<?php
require '../AopCertClient.php';

require '../request/AlipayFundAccountQueryRequest.php';
require '../request/AlipayFundTransUniTransferRequest.php';

/** 初始化 **/

$aop = new AopCertClient;

/** 支付宝网关 **/

$aop->gatewayUrl = "https://openapi.alipay.com/gateway.do";

/** 应用id,如何获取请参考：https://opensupport.alipay.com/support/helpcenter/190/201602493024 **/

$aop->appId = "2021003192638805";

/** 密钥格式为pkcs1，如何获取私钥请参考：https://opensupport.alipay.com/support/helpcenter/207/201602469554 **/

$aop->rsaPrivateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCN6hnKouUoNLvbHmzt4kPlLvxINERaVQ+Fk3COh4lW5ESpIczjLT1fHGEbab60+8Io0XeFkKhOWHVYXV4nzIoBw0d/Yeu/kLI79JeatP4uOZLxdi/LfgAozHajzvzwNBXn9vBPEBiW3+Uq2VsooWdMR6y7qseZXMcXKE3L3fEwGvdmraXlfdYM4bQKjw0S1I1ADQs3ltuzXYM+vK1+n7fI6BHqb6LEN6Uojdc1Vy2Iq74frDpEjRBdhxwB7VZC6cHlIxI6Eed3Nql04/oBtQqdm0b1ORLIr3xU6XS3ZI3E2hIJseIhSOuoAbzQ7LeQcpMraBi4GrG7sr6EH5Qd9RPPAgMBAAECggEAOly0Dqm/JDHLr+lrUslisrYH+onEMoIYyA5Ck9sZmCp4MjY8VJEeVCcPqH5sd3Gx/6dlSACdttqaJ6T+O8/aUa9FkBVtJnMTWaTVVEJq5ge3bqX0MfO3jQ/JGsTdMMu61pKvcVRlSGb7kAujeaonGS/A0c0CGQgWuGdS1yyHLAjL3eT/bRbgTHMwb3X9WBAvo7vgJMUTS/BpTqqpE/66c+Hub9RSFgYU+JtkoG2mXWTn50ExlztOW0NTzDZmghSvQEKv0uE5C4KpDESCBgNzkE+K5N4/DPt4Vg+VXhc4Vj1n05rQTx8hm8kA1IDWQlRjGINzh3mIfmSw4a9NlUlJAQKBgQDi2qakqgBdUUm5HpFmRea9txIXQEAXUfIJ+Um/fapU2b5nFuat9o8XOpGCXI/x9UPIx19qy8x4md1Lu6k2RiQibT2VNF1HO1x0OMt7FJcTqbwlUflo/UrKnfeDYNj/VdFcFxFLXRHs64dUNwrJ+CLLO62YZWQwJc/mFqNYc0gPvwKBgQCgJb2gey7tCYXsw1pPW6fn0ExzPPgpqVgfihp7u26tJg9HHV47wL0xxRnqqB//NphPzkweV5NT2He/Qf1uZr5Qxl9e4Or+yuaM7xFx/AjTR22AH6DjqneQfmlck+Yl0ub9q3p7eAFXYqMEjMwEg1Bp0WxsnVwodBlCSvxHLFH/8QKBgQDbgH/gMpJZuQ7hrX84+4gRp7M8hjG9ns/Y8Lp4LCsFIQ+IBnO8fibkbgpfnhq2HwCwpKFh38KAKzkiT3mih2ntWdBNr7ZV9001M8NH25t3LjRb1B7FhNi6hvD40VwGbE5Akh1s06hFm3x9cyjgVlWsWplVLT4tDFlGpD73lcxzVwKBgBIgc3hIuSUHYOtNqVk2LKkmgKDCk+xTSLA5N4otyvc6SZxpDJOC22dYwfg3k3eVvGO8HA2LKBfjdpplY8QtSPlnmr/ogXDZkoL9RGI8fts7SH+qFNHwJ5xpUo+yBejeGFs6H6D+EljLx1vqe+U+38k6dSVOInJJwdopFqkPsTBhAoGAOlioohZjaugeOz3ovdNCs2r2DwE7Ven5Y7aDPn1M0ca7HxAnbeTCyNotJbfkZe2aSrjysoD1HrLg8p8SEreoaNzNjum4LiL8zvZkhyBU+7NqbHRZP0UV6Dp9uiIxWQjRA9hh3MONnc3QgDpz0g7k0j+BcDemqqDKo86R2C9b96c=";
/** 应用公钥证书路径，下载后保存位置的绝对路径 **/

$appCertPath = "appCertPublicKey_2021003192638805.crt";

$alipayrsaPublicKey_test = $aop->getPublicKey($appCertPath);
echo '支付宝应用公钥证书值'.$alipayrsaPublicKey_test;


/** 支付宝公钥证书路径，下载后保存位置的绝对路径 **/

$alipayCertPath = "alipayCertPublicKey_RSA2.crt";

$alipayrsaPublicKey_test = $aop->getPublicKey($alipayCertPath);
echo '支付宝公钥证书值'.$alipayrsaPublicKey_test;

/** 支付宝公钥证书路径，下载后保存位置的绝对路径 **/

$rootCertPath = "alipayRootCert.crt";


/** 设置签名类型 **/

$aop->signType= "RSA2";

/** 设置请求格式，固定值json **/

$aop->format = "json";

/** 设置编码格式 **/

$aop->charset= "utf-8";

/** 调用getPublicKey从支付宝公钥证书中提取公钥 **/

$aop->alipayrsaPublicKey = $aop->getPublicKey($alipayCertPath);

/** 是否校验自动下载的支付宝公钥证书，如果开启校验要保证支付宝根证书在有效期内 **/

$aop->isCheckAlipayPublicCert = true;

/** 调用getCertSN获取证书序列号 **/

$aop->appCertSN = $aop->getCertSN($appCertPath);

/** 调用getRootCertSN获取支付宝根证书序列号 **/

$aop->alipayRootCertSN = $aop->getRootCertSN($rootCertPath);

if(false){
    /** 设置业务参数，具体接口参数传值以文档说明为准：https://opendocs.alipay.com/apis/api_28/alipay.fund.account.query **/
    $request = new AlipayFundAccountQueryRequest ();
    
    $request->setBizContent("{" .
        "\"alipay_user_id\":\"2088641232029876\"," .
        "\"account_type\":\"ACCTRANS_ACCOUNT\"" .
        "}");
    
    $result= $aop->execute($request);
    
    /** 获取接口调用结果，如果调用失败，可根据返回错误信息到该文档寻找排查方案：https://opensupport.alipay.com/support/helpcenter/107 **/
    
    echo json_encode($result,JSON_UNESCAPED_UNICODE);
}else {
    $request = new AlipayFundTransUniTransferRequest();
    $request->setBizContent("{".
        "\"out_biz_no\":\"hmxs201806300001\",".
        "\"remark\":\"201905代发\",".
        "\"business_params\":\"{\\\"payer_show_name_use_alias\\\":\\\"true\\\"}\",".
        "\"biz_scene\":\"DIRECT_TRANSFER\",".
        "\"payee_info\":{".
        "\"identity\":\"18668420256\",".
        "\"identity_type\":\"ALIPAY_LOGON_ID\",".
        "\"name\":\"周灵杰\"".
        "},".
        "\"trans_amount\":\"0.1\",".
        "\"product_code\":\"TRANS_ACCOUNT_NO_PWD\",".
        "\"order_title\":\"201905代发\"".
        "}");
    $result = $aop->execute($request);
    echo json_encode($result,JSON_UNESCAPED_UNICODE);
    
//     $responseApiName = str_replace(".","_",$request->getApiMethodName())."_response";
//     $response = $responseResult->$responseApiName;
//     if(!empty($response->code)&&$response->code==10000){
//         echo("调用成功");
//     }
//     else{
//         echo("调用失败");
//     }
}

