您好,欢迎访问一九零五行业门户网

谈谈php对接芝麻信用踩的坑_php实例

由于项目需要,接入芝麻信用对用户进行认证,打开芝麻信用官方网站( https://b.zmxy.com.cn/index.htm)查看官方demo,在文档中看到如图
瞬间觉得这个官方demo的垃圾了。
在其中有需要注意如下:
1.本地生成密钥,可以按照提示进行生成
2.在“商家管理”中创建应用,通过第一步生成的密钥得到芝麻信用给的公钥,这就得到了加密用的密钥
注意:芝麻信用给的公钥只能复制,但是复制出来的格式是不对的,需要咱们手工处理每行64,和咱们生成的密钥格式一致,不然加密和解密将不能进行;
3.需要传递的参数根据文档可以得出,上图只是生成了一个参数,需要处理生成对应文档的数据返回;
直接上代码:
gatewayurl, $this->appid, $this->charset, $this->privatekeyfile,$this->zmpublickeyfile); $request = new zhimaauthinfoauthorizerequest(); $request->setscene(test); // 授权来源渠道设置为appsdk $request->setchannel(appsdk); // 授权类型设置为2标识为证件号授权见“章节4中的业务入参说明identity_type” $request->setidentitytype(2); // 构造授权业务入参证件号,姓名,证件类型;“章节4中的业务入参说明identity_param” $request->setidentityparam({\certno\:\$certno\,\certtype\:\identity_card\, \name\:\$name\}); // 构造业务入参扩展参数“章节4中的业务入参说明biz_params” $request->setbizparams({\auth_code\:\m_appsdk\}); $params = $client->generateencryptedparamwithurlencode($request); $sign = $client->generatesignwithurlencode($request); $data['gatewayurl'] = $this->gatewayurl; $data['appid'] = $this->appid; $data['charset'] = $this->charset; $data['params']=$params; $data['sign'] = $sign; return $data; } // 解密 public function zhimacallback($params){ $this->privatekeyfile= path/rsa_private_keypem; $client = new zmopclient($this->gatewayurl, $this->appid, $this->charset, $this->privatekeyfile,$this->zmpublickeyfile); $result=$client->generatesigncallback($params,$this->privatekeyfile); return $result; } } ?>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
其它类似信息

推荐信息