Home > Backend Development > PHP Tutorial > Talk about the pitfalls of PHP docking with Sesame Credit_php examples

Talk about the pitfalls of PHP docking with Sesame Credit_php examples

WBOY
Release: 2023-03-03 06:30:02
Original
986 people have browsed it

Due to project needs, connect to Sesame Credit to authenticate users, open the official website of Sesame Credit (https://b.zmxy.com.cn/index.htm) to view the official demo, as shown in the document

I instantly felt that this official demo was rubbish.

There are things you need to pay attention to:

1. Generate the key locally and follow the prompts

2. Create an application in "Merchant Management" and use the key generated in the first step to get the public key given by Zhima Credit. This will get the encryption key

Note: The public key provided by Zhima Credit can only be copied, but the copied format is wrong. We need to manually process each line of 64, which is consistent with the key format we generated, otherwise encryption and decryption will not be possible;

3. The parameters that need to be passed can be obtained from the document. The above figure only generates a parameter, which needs to be processed to generate the data return of the corresponding document;

Go directly to the code:

<&#63;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; 
  } 
}  
&#63;> 
Copy after login

The above is the entire content of this article. I hope it will be helpful to everyone’s study. I also hope that everyone will support Script Home.

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template