欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

支付宝身份认证初始化服务40004未知的错误码

程序员文章站 2022-07-14 08:16:40
...

 

 

下面是支付宝官方给出的示例:

支付宝身份认证初始化服务40004未知的错误码

 

$aop = new AopClient ();
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$aop->appId = 'your app_id';
$aop->rsaPrivateKey = '请填写开发者私钥去头去尾去回车,一行字符串';
$aop->alipayrsaPublicKey='请填写支付宝公钥,一行字符串';
$aop->apiVersion = '1.0';
$aop->signType = 'RSA2';
$aop->postCharset='GBK';
$aop->format='json';
$request = new AlipayUserCertifyOpenInitializeRequest ();
$request->setBizContent("{" .
"\"outer_order_no\":\"ZGYD201809132323000001234\"," .
"\"biz_code\":\"FACE\"," .
"\"identity_param\":\"{\\\"identity_type\\\":\\\"CERT_INFO\\\",\\\"cert_type\\\":\\\"IDENTITY_CARD\\\",\\\"cert_name\\\":\\\"收委\\\",\\\"cert_no\\\":\\\"260104197909275964\\\"}\"," .
"\"merchant_config\":\"{\\\"return_url\\\":\\\"xxx\\\"}\"," .
"\"face_contrast_picture\":\"xydasf==\"" .
"  }");
$result = $aop->execute ( $request); 

$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code;
if(!empty($resultCode)&&$resultCode == 10000){
echo "成功";
} else {
echo "失败";
}

会出现报错:

支付宝身份认证初始化服务40004未知的错误码

 

这个是因为如果直接抄写了官方的案列,会在$request->setBizContent()添加参数时,字符串拼接有误,要对进行修改

        $data['cert_name']="收委";
        $data['cert_no']="260104197909275964";
        $data['outer_order_no']="ZGYD201809132323000001234";
        $aop = new AopClient ();
        $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
        $aop->appId =C('appId');
        $aop->rsaPrivateKey = C('rsaPrivateKey');
        $aop->alipayrsaPublicKey=C('alipayrsaPublicKey');
        $aop->apiVersion = '1.0';
        $aop->signType = 'RSA2';
        $aop->postCharset='UTF-8';
        $aop->format='json';
        $request = new AlipayUserCertifyOpenInitializeRequest ();
        $request->setBizContent("{" .
        "\"outer_order_no\":\"".$data['outer_order_no']."\"," .
        "\"biz_code\":\"FACE\"," .
        "\"identity_param\":"."{\"identity_type\":\"CERT_INFO\",\"cert_type\":\"IDENTITY_CARD\",\"cert_name\":\"".$data['cert_name']."\",\"cert_no\":\"".$data['cert_no']."\"}"."," .
        "\"merchant_config\":"."{\"return_url\":\"www.baidu.com\"}".
        "  }");
        $result = $aop->execute ( $request); 
        echo "<pre>";
        var_dump($result);
        $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
        $resultCode = $result->$responseNode->code;
        if(!empty($resultCode)&&$resultCode == 10000){
        echo "成功";
        } else {
        echo "失败";
        }

因为identity_param 与 merchant_config 参数是字符串  但里面也是json,要删除官方的一些”\“,并自己拼接。如此就能成功的完成初始化。

结果如下:

支付宝身份认证初始化服务40004未知的错误码

 

相关标签: php 字符串