当前位置:网站首页>封装微信支付宝脱敏
封装微信支付宝脱敏
2022-07-21 14:36:00 【dj1540225203】
/**
* 脱敏 https://opendocs.alipay.com/common/02kg63 https://developers.weixin.qq.com/miniprogram/dev/framework/security.html#%E4%BF%A1%E6%81%AF%E6%B3%84%E9%9C%B2
* @param $platform int 平台:0微信、1支付宝
* @param $type int 类型:0身份证ID、1手机号、2银行卡号、3个人姓名
* @param $string string 待脱敏字符串
* user Mr.DJ
* des:脱敏封装方法
*/
function getDesensitize($platform,$type,$string){
$arr = ['identity_card'=>0,'phone_number'=>1,'bank_card_number'=>2,'personal_name'=>3];
switch ($arr[$type]){
case 0: //只显示第一位和最后一位,如:3****************1
$strlen = mb_strlen($string, 'utf-8');
$firstStr = mb_substr($string, 0, 1, 'utf-8');
$lastStr = mb_substr($string, 0, 1, 'utf-8');
$string = $firstStr.str_repeat("*", $strlen - mb_strlen($firstStr, 'utf-8') -1) .$lastStr;
break;
case 1: //支付宝只显示前三位和最后两位,如:156******77。
if($platform){
$firstStr = mb_substr($string, 0, 3, 'utf-8');
$string = $firstStr.str_repeat("*", mb_strlen($string, 'utf-8') - 5) . mb_substr($string, -2, 4, 'utf-8');
}else{ //微信只显示前三位和最后两位,如:156******77。手机号位数少于10位时,只显示前两位和后两位,如:12*****89
$strlen = mb_strlen($string, 'utf-8');
$firstStr = mb_substr($string, 0, 3, 'utf-8');
if($strlen < 11){
$firstStr = mb_substr($string, 0, 2, 'utf-8');
$string = $firstStr.str_repeat("*", $strlen - 4) .mb_substr($string, -2, 2, 'utf-8');
}else{
$string = $firstStr.str_repeat("*", mb_strlen($string, 'utf-8') - 5) . mb_substr($string, -2, 2, 'utf-8');
}
}
break;
case 2: //只显示最后4位,如:************1234
$string = str_repeat("*", mb_strlen($string, 'utf-8') - 4) . mb_substr($string, -4, 4, 'utf-8');
break;
case 3: //微信:名字只有两个字,对第一个字打码,如:*三。 多于两个字,只保留第一个和最后一个,其余都打码,如:王*四、欧**五 支付宝:中文姓名只展示最后一个字,前面补充 *
if($platform){
$string = str_repeat("*", mb_strlen($string, 'utf-8') - 1) . mb_substr($string, -1, 1, 'utf-8');
}else{
$strlen = mb_strlen($string, 'utf-8');
$firstStr = mb_substr($string, 0, 1, 'utf-8');
$lastStr = mb_substr($string, -1, 1, 'utf-8');
$string = ($strlen == 2) ? str_repeat('*', mb_strlen($string, 'utf-8') - 1).$lastStr : $firstStr . str_repeat("*", $strlen - 2) . $lastStr;
}
break;
}
return $string;
}
边栏推荐
- LeetCode刷题:链表中倒数第k个节点
- DOM event proxy (2)
- β- Preparation of cyclodextrin derivative grafted hydroxypropyl chitosan hydrogel / carboxyl modified chitosan supported cyclodextrin hydrogel microspheres
- Exploration of running applet of domestic Tongxin UOS system
- LeetCode刷题:二叉树的中序遍历
- Preparation of chitosan / dextran / nano hydroxyapatite composite hydrogel / fish gelatin galactose chitosan hydrogel liver scaffold
- leetcode1588. Sum of all odd length subarrays
- 列表标签和超链接
- Typora beta expired solution
- Dom4j parsing XML (detailed)
猜你喜欢
详细教你用NPS搭建内网穿透服务,外出时轻薄本轻松连接家里的游戏主机远程玩耍
Animation, and basic use of animation
Leetcode skimming: balanced binary tree and flipped binary tree
YOLOPose实战:手把手实现单阶段的人体姿态估计+代码解读
运营商AI机遇:以大模型拓展全新赛道
LeetCode刷题:链表中倒数第k个节点
Leetcode skimming: reverse the linked list and the intermediate nodes in the linked list
Dom4j parsing XML (detailed)
leetcode 1380. Lucky number in matrix
.net 温故知新:【6】Linq是什么
随机推荐
Leetcode skimming: middle order traversal of binary trees
The company that opens an account for futures has low handling charges and is safe
创建私有CA,我就用openSSL
leetcode 1306. Jumping game III
Leetcode 539. 最小时间差
西农大 C plus
IDEA快捷键(第十六天)
Using LINGO to solve simple linear programming problems
The role of visual management of communication infrastructure in ISO 2.0
Preparation method of polyether / polyacrylamide monomethyl / Polyacrylamide / granular poly (N-isopropylacrylamide) chitosan hydrogel
高度塌陷和清除浮动
关于面试的一些问题
网页的结构
LeetCode刷题:链表中倒数第k个节点
vector容器成员函数——reserve()及迭代器失效问题
Software testing: equivalence testing, decision table based testing and comprehensive problem analysis
streamlit TypeError: Plain typing. NoReturn is not valid as type argument
Set the background color, background range, Sprite chart, gradient, radial gradient, etc
IDEA 搭建和环境变量
leetcode 310. Minimum height tree