小程序解密用户手机号

1.官网下载解密类文件:https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/signature.html

2.解密手机号必须用到的参数:session_key,encryptedData,iv
3.我用get请求

public function userDecrypt(Request $request)
    {
        //包含解密类
        include("../vendor/wechatdecrypt/wxBizDataCrypt.php");
        //接收参数
        $sessionKey = $request->get('session_key');
        $encryptedData = $request->get('encryptedData');
        $iv = $request->get('iv');
        //调用微信类
        $pc = new \WXBizDataCrypt(Env::get('APPID'), $sessionKey);
        $errCode = $pc->decryptData($encryptedData, $iv, $data);

        if ($errCode == 0) {
            $data = json_decode($data)->phoneNumber;
            // print($data . "\n");
            return sendResponse($data);
        } else {
            return sendResponse('', -1);
        }

    }

你可能感兴趣的:(小程序解密用户手机号)