支付宝证书模式(转账给其他支付宝)

支付宝证书模式(转账给其他支付宝)

因为支付宝的加密方式要求资金类必须用证书方式加密,所以。。。
1.去生成crt证书
2.开始开发

初始化

//证书模式
        vendor("Alipay.aop.AopCertClient"); //引入sdk
        $aop = new \AopCertClient();
        $appCertPath = "./Application/Pay/Conf/Cert/appCertPublicKey.crt";//"应用证书路径(要确保证书文件可读),例如:/home/admin/cert/appCertPublicKey.crt";
        $alipayCertPath = "./Application/Pay/Conf/Cert/alipayCertPublicKey_RSA2.crt";//"支付宝公钥证书路径(要确保证书文件可读),例如:/home/admin/cert/alipayCertPublicKey_RSA2.crt";
        $rootCertPath = "./Application/Pay/Conf/Cert/alipayRootCert.crt";//"支付宝根证书路径(要确保证书文件可读),例如:/home/admin/cert/alipayRootCert.crt";

        $aop->gatewayUrl = $config['gatewayUrl'];
        $aop->appId = $config['app_id'];
        $aop->rsaPrivateKey = $config['merchant_private_key'];
        $aop->alipayrsaPublicKey = $aop->getPublicKey($alipayCertPath);
        $aop->apiVersion = '1.0';
        $aop->signType=$config['sign_type'];
        $aop->postCharset=$config['charset'];
        $aop->format='json';
        $aop->isCheckAlipayPublicCert = true;//是否校验自动下载的支付宝公钥证书,如果开启校验要保证支付宝根证书在有效期内
        $aop->appCertSN = $aop->getCertSN($appCertPath);//调用getCertSN获取证书序列号
        $aop->alipayRootCertSN = $aop->getRootCertSN($rootCertPath);//调用getRootCertSN获取支付宝根证书序列号

注意

一定要确保你的openssl的版本不能太低,建议是1.1.1,不然 getRootCertSN($rootCertPath) 解析出来的根证书序列号,不完整,或者是不正确。

3.alipay.fund.trans.uni.transfer(统一转账接口)

//统一转账接口
    public function transfer($money = null,$openid = null){
        vendor("Alipay.aop.request.AlipayFundTransUniTransferRequest");
        $request = new \AlipayFundTransUniTransferRequest();
        $date = date("Y-m-d");
        $data['out_biz_no'] = build_order_no();
        $data['trans_amount'] = $money;
        $data['product_code'] = 'TRANS_ACCOUNT_NO_PWD';
        $data['biz_scene'] = 'DIRECT_TRANSFER';
        $data['order_title'] = '营销红包';
        $payee_info['identity'] = $openid;
        $payee_info['identity_type'] = 'ALIPAY_USER_ID';
        $data['payee_info'] = $payee_info;
        Log::write(json_encode($data,JSON_UNESCAPED_UNICODE),'info','','Logs/Pay/Alipay/SendHongBao/fa/'.$date.'.txt');
        $request->setBizContent(json_encode($data));
        $result = $this->aop->execute($request);
        $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
        $res =  $result->$responseNode;
        $ress = json_encode($res,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
        Log::write($ress,'info','','Logs/Pay/Alipay/SendHongBao/fa/'.$date.'.txt');
        $rest = json_decode($ress,true);
        return $rest;
    }

4.alipay.fund.trans.common.query(转账业务单据查询接口)

 //转账业务单据查询接口
    public function transfer_query($info){
        vendor("Alipay.aop.request.AlipayFundTransCommonQueryRequest");
        $request = new \AlipayFundTransCommonQueryRequest();
        $date = date("Y-m-d");
        $data['product_code'] = 'TRANS_ACCOUNT_NO_PWD';
        $data['biz_scene'] = 'DIRECT_TRANSFER';
        //商户转账唯一订单号
        $data['out_biz_no'] = $info['out_biz_no'];
        //支付宝转账单据号
        $data['order_id'] = $info['order_id'];
        //支付宝支付资金流水号
        $data['pay_fund_order_id'] = $info['pay_fund_order_id'];
        Log::write(json_encode($data,JSON_UNESCAPED_UNICODE),'info','','Logs/Pay/Alipay/SendHongBao/cha/'.$date.'.txt');
        $request->setBizContent(json_encode($data));
        $result = $this->aop->execute($request);
        $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
        $res =  $result->$responseNode;
        $ress = json_encode($res,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
        Log::write($ress,'info','','Logs/Pay/Alipay/SendHongBao/cha/'.$date.'.txt');
        $rest = json_decode($ress,true);
        return $rest;
    }

差不多了

发布了5 篇原创文章 · 获赞 4 · 访问量 536

猜你喜欢

转载自blog.csdn.net/wozhongmingyue/article/details/103610242