PHP解密支付宝小程序的加密数据、手机号的示例代码
吾爱主题
阅读:134
2021-11-05 16:34:00
评论:0
1.小程序端代码示例
?1 2 3 4 5 6 7 8 9 10 11 12 13 | my.getPhoneNumber({ success: (res) => { let encryptedData = res.response; my.httpRequest({ url: '你的后端服务端' , data: encryptedData, }); }, fail: (res) => { console.log(res); console.log( 'getPhoneNumber_fail' ); }, }); |
2.PHP后端解密示例
?1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | public static function decryptData( $encryptedData , $key = '开发设置-接口内容加密方式-查看-字符串' ) { $encrys = json_decode( $encryptedData , true); $encryptedData = $encrys [ 'response' ]; $str = base64_decode ( $encryptedData ); $screct_key = base64_decode ( $key ); //设置全0的IV $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC); $iv = str_repeat ( "\0" , $iv_size ); $decrypt_str = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $screct_key , $str , MCRYPT_MODE_CBC, $iv ); $decrypt_str = self::stripPKSC7Padding( $decrypt_str ); return $decrypt_str ; } public static function stripPKSC7Padding( $source ) { $char = substr ( $source , -1); $num = ord( $char ); if ( $num == 62) return $source ; $source = substr ( $source , 0, - $num ); return $source ; } |
3.解密返回
?1 | { "code" : "10000" , "msg" : "Success" , "mobile" : "185xxxxx111" } |
知识点扩展:
php函数摘要-加密和解密类
1支付宝小程序手机号解密
加密数据
?1 2 3 4 | { "response" : "EaieI1W9gPK0zClNbA7P0T6svaSYq/1xejihTXNVSH0WyCjBIcP2xOwaAevaYgb4aeQ5NNRQaqbZgVvfJKfaLQ==" , "sign" : "iSHQH/r3rZiBx7N49SwQNHx2Y0B6OP2ePvhS+T2XKw9+dzt3T1W9T0cHSldFlkczcdPQ05Pi/bEygsZxip6StCNEqse7ou/nXx9QOAVNoBgZfb4bmFJxOl8DYeuF8VKQy+NdxuvRGJFpmVynZtSNy31BfD4663IowMj80/pfnmLJCEKqoS2oHWtGRRM7oIFEdCH5IJKCsq79qxFEPwmQVid2uN0XuL/Rg+lKN9eAbTGcBttVZGaI11vGDEBUq9sNksVJXWUHofszCeD9jGz8pGoNvApRt8Swe2RnVtWcnQ+Zh+G105fPpp3RYNZBSBV9EJJ5la5IEv8KfAwjW7jGFg==" } |
解密函数
?1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | /** * 解密 * * return mix */ function decryptData(string $encrypted_data ) { $key = env( 'EAS' ); $aesKey = base64_decode ( $key ); $iv = 0; $aesIV = base64_decode ( $iv ); $aesCipher = base64_decode ( $encrypted_data ); $result =openssl_decrypt( $aesCipher , "AES-128-CBC" , $aesKey , 1, $aesIV ); return $result ; } |
解密过程
?1 2 3 | echo decryptData( 'EaieI1W9gPK0zClNbA7P0T6svaSYq/1xejihTXNVSH0WyCjBIcP2xOwaAevaYgb4aeQ5NNRQaqbZgVvfJKfaLQ==' ); // {"code":"10000","msg":"Success","mobile":"1342XXXXXXX"} |
到此这篇关于PHP解密支付宝小程序的加密数据,手机号的文章就介绍到这了,更多相关PHP解密支付宝小程序加密数据内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!
原文链接:https://www.cnblogs.com/xiager/p/14450931.html
声明
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。