1.支付宝小程序获取电话号码,先要签约(获取会员手机号)签约成功
2.设置支付宝(接口内容加密方式)
3.后端代码解密报文获取电话号码
// 支付宝解密获取敏感信息
public function alipayAes()
{
$encryptedData = $this->request->param('encryptedData'); // 小程序获取的报文,内有加密信息和签名
if(empty($encryptedData)){
return $this->errorReturn('号码获取失败');
}
$encryptedArr = json_decode($encryptedData); // 小程序拿到的报文 json格式
$encrypted = $encryptedArr['response']; // 加密字符串
//获取手机号解密
$aesKey="SCMZbJTVVrs------"; // 小程序 - 接口内容加密方式:设置的秘钥
$result=openssl_decrypt(base64_decode($encrypted), 'AES-128-CBC', base64_decode($aesKey),OPENSSL_RAW_DATA);
$mobile = \json_decode(\html_entity_decode($result, ENT_QUOTES), true); // 解密
if($mobile['code'] != '10000'){
return $this->error($mobile['msg']);
}
$userData = [
'user_id' => $this->userId,
'mobile' => $mobile['mobile'],
'mobile_validated' => 1
];
$this->success($userData);
}