小程序
小游戏
企业微信
微信支付
扫描小程序码分享
不想建立服务器,但又需要获取到用户的手机和openid,有没办法直接在小程序端解密encryptedData
2 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
获取客户 openId 和 unionId 需要以下步骤(都为必须步骤)
1.从验证从客户端传上来code, 获取sessionKey (需要配合小程序appid ,secret 发送到微信服务器)
$params = [ 'appid' => $this->appid, 'secret' => $this->secret, 'js_code' => $this->code, 'grant_type' => $this->grant_type ];
2.获取到微信服务器 返回信息
(通过客户端传来的 原始数据 + 获取的sessionKey 与客户端传来的 签名对比)
$signature = sha1($this->rawData . $this->sessionKey); if ($signature !== $this->signature){ return $this->ret_message("signNotMatch"."sessionKey 签名不匹配"); }
3.重要环节:
通过 服务器返回的 session_key 解密 客户端上传的加密数据
/* 3.通过 服务器返回的 session_key 解密 客户端上传的加密数据 * 需要参数 * [ "appid"=>$this->appid, "sessionKey"=>$sessionKey, "encryptedData"=>$this->encryptedData, "iv"=>$this->iv, ]; */
客户端上传的 encryptedData 需要用encodeURIComponent方法进行URL编码,对应服务端需要URL解码
小程序:
encodeURIComponent(data.encryptedData);//一定要把加密串转成URL编码
对应服务端需要进行URL解码 否则出现解密结果 为NULL的错误
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
试试云开发
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
获取客户 openId 和 unionId 需要以下步骤(都为必须步骤)
1.从验证从客户端传上来code, 获取sessionKey (需要配合小程序appid ,secret 发送到微信服务器)
$params = [ 'appid' => $this->appid, 'secret' => $this->secret, 'js_code' => $this->code, 'grant_type' => $this->grant_type ];
2.获取到微信服务器 返回信息
(通过客户端传来的 原始数据 + 获取的sessionKey 与客户端传来的 签名对比)
$signature = sha1($this->rawData . $this->sessionKey); if ($signature !== $this->signature){ return $this->ret_message("signNotMatch"."sessionKey 签名不匹配"); }
3.重要环节:
通过 服务器返回的 session_key 解密 客户端上传的加密数据
/* 3.通过 服务器返回的 session_key 解密 客户端上传的加密数据 * 需要参数 * [ "appid"=>$this->appid, "sessionKey"=>$sessionKey, "encryptedData"=>$this->encryptedData, "iv"=>$this->iv, ]; */
客户端上传的 encryptedData 需要用encodeURIComponent方法进行URL编码,对应服务端需要URL解码
小程序:
encodeURIComponent(data.encryptedData);//一定要把加密串转成URL编码
对应服务端需要进行URL解码 否则出现解密结果 为NULL的错误
试试云开发