zoukankan      html  css  js  c++  java
  • PHP解密支付宝小程序的加密数据,手机号等。

    1.小程序端代码示例

    my.getPhoneNumber({
        success: (res) => {
            let encryptedData = res.response;
            my.httpRequest({
                url: '你的后端服务端',
                data: encryptedData,
            });
        },
        fail: (res) => {
            console.log(res);
            console.log('getPhoneNumber_fail');
        },
    });

    2.PHP后端解密示例

     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("", $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.解密返回

    {"code":"10000","msg":"Success","mobile":"185xxxxx111"}
  • 相关阅读:
    Pika的设计及实现
    高性能网络编程
    C语言的结构体
    消息队列库——ZeroMQ
    Diffie-Hellman密钥交换算法
    mysql-proxy 读写分离
    位运算
    分布式学习之一:事务
    Redis Cluster
    SpringBoot整合ActiveMQ,看这篇就够了
  • 原文地址:https://www.cnblogs.com/xiager/p/14450931.html
Copyright © 2011-2022 走看看