Alipay certificate signature PHP SDK

PHP access Alipay signature and a certificate signed inspection

Alipay around 2019.10.25 updated on the new PHP SDK (v4.1.0). Before the PHP SDK (v3.4.2) only supports Public Key endorsement. After this update PHP SDK can also be used to sign certificates and inspection signed.

Alipay official SDK Download

Download and unzip the file aop folder in the folder copied directly into the project you want into folders, for example, extend
the folder (To test the crt certificate file has also been put under the same directory cert directory)
Here Insert Picture Description
to amend SDK 1 small error: AopCertClient.php in
about a 478 checks whether the line has null methods
Here Insert Picture Description
modified to

    if (method_exists($request, 'getApiVersion')){
        $iv = $request->getApiVersion();
    }else{
        $iv = $this->apiVersion;
    }

   
   

Import documents

    require_once EXTEND_PATH.'aop/AopCertClient.php';
    require_once EXTEND_PATH.'aop/AopCertification.php';
    require_once EXTEND_PATH.'aop/request/AlipayTradeQueryRequest.php';
    require_once EXTEND_PATH.'aop/request/AlipayTradeWapPayRequest.php';
    require_once EXTEND_PATH.'aop/request/AlipayOpenOperationOpenbizmockBizQueryRequest.php';

   
   

From the aop / test / directory to find the next AopCertClientTest.php (as is the use of the certificate is signed, if the use of public key signature, you should refer to AopClientTest.php file, not repeat them) directly copy the relevant code changes such as my copy It is

    //1、execute 使用
    $aop = new AopCertClient ();
    $appCertPath = "应用证书路径(要确保证书文件可读),例如:/home/admin/cert/appCertPublicKey.crt";
    $alipayCertPath = "支付宝公钥证书路径(要确保证书文件可读),例如:/home/admin/cert/alipayCertPublicKey_RSA2.crt";
    $rootCertPath = "支付宝根证书路径(要确保证书文件可读),例如:/home/admin/cert/alipayRootCert.crt";
    
    $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
    $aop->appId = '你的appid';
    $aop->rsaPrivateKey = '你的应用私钥';
    $aop->alipayrsaPublicKey = $aop->getPublicKey($alipayCertPath);//调用getPublicKey从支付宝公钥证书中提取公钥
    $aop->apiVersion = '1.0';
    $aop->signType = 'RSA2';
    $aop->postCharset='utf-8';
    $aop->format='json';
    $aop->isCheckAlipayPublicCert = true;//是否校验自动下载的支付宝公钥证书,如果开启校验要保证支付宝根证书在有效期内
    $aop->appCertSN = $aop->getCertSN($appCertPath);//调用getCertSN获取证书序列号
    $aop->alipayRootCertSN = $aop->getRootCertSN($rootCertPath);//调用getRootCertSN获取支付宝根证书序列号
    
    $request = new AlipayTradeQueryRequest ();
    $request->setBizContent("{" .
        "\"out_trade_no\":\"20150320010101001\"," .
        "\"trade_no\":\"2014112611001004680 073956707\"," .
        "\"org_pid\":\"2088101117952222\"," .
        "      \"query_options\":[" .
        "        \"TRADE_SETTE_INFO\"" .
        "      ]" .
        "  }");
    $result = $aop->execute ( $request);
    var_dump($result);


   
   

Because I want to use a single interface to transfer Alipay account.
So the above code to be modified in two places.

    $request = new AlipayFundTransToaccountTransferRequest ();
    // 官方示例  切记要自己修改
    $request->setBizContent("{" .
    "\"out_biz_no\":\"3142321423432\"," .
    "\"payee_type\":\"ALIPAY_LOGONID\"," .
    "\"payee_account\":\"[email protected]\"," .
    "\"amount\":\"12.23\"," .
    "\"payer_show_name\":\"上海交通卡退款\"," .
    "\"payee_real_name\":\"张三\"," .
    "\"remark\":\"转账备注\"" .
    "  }");

   
   

After modifications are complete, you can run the code for testing.

Original: https: //blog.csdn.net/csd465038717/article/details/102748277

Guess you like

Origin www.cnblogs.com/showcase/p/12091141.html