当前位置:首页 > PHP教程 > PHP常见问题

谈谈php对接芝麻信用踩的坑

由于项目需要,接入芝麻信用对用户进行认证,打开芝麻信用官方网站( https://b.zmxy.com.cn/index.htm)查看官方demo,在文档中看到如图

瞬间觉得这个官方demo的垃圾了。

在其中有需要注意如下:

1.本地生成密钥,可以按照提示进行生成

2.在“商家管理”中创建应用,通过第一步生成的密钥得到芝麻信用给的公钥,这就得到了加密用的密钥

注意:芝麻信用给的公钥只能复制,但是复制出来的格式是不对的,需要咱们手工处理每行64,和咱们生成的密钥格式一致,不然加密和解密将不能进行;

3.需要传递的参数根据文档可以得出,上图只是生成了一个参数,需要处理生成对应文档的数据返回;

直接上代码:

<?php include('/zmopclientphp'); include('/zhimaauthinfoauthorizerequestphp'); class testauthfreeze { //芝麻信用网关地址 public $gatewayurl = "https://zmopenapizmxycomcn/openapido"; //商户公钥文件 //芝麻公钥文件 public $privatekeyfile = "path/rsa_private_keypem"; public $zmpublickeyfile = "path/zima_public_keypem"; //数据编码格式 public $charset = "utf-8"; //芝麻分配给商户的appid public $appid = "1000003"; //生成移动端sdk 集成需要的sign 参数 ,并进行urlencode public function generatesign($certno,$name,$certtype='identity_card'){ $client = new zmopclient($this->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; } } ?>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持硕编程。



【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐