|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
require_once "aop/AopCertClient.php";
|
|
|
|
|
require_once "aop/request/AlipayFundTransUniTransferRequest.php";
|
|
|
|
|
require_once "aop/request/AlipayFundTransOrderQueryRequest.php";
|
|
|
|
|
require_once "aop/request/AlipayFundAccountQueryRequest.php";
|
|
|
|
|
|
|
|
|
|
class Fund {
|
|
|
|
|
private $appCertPath = __DIR__ . "/cert/appCertPublicKey_2021001150621489.crt";
|
|
|
|
|
private $alipayCertPath = __DIR__ . "/cert/alipayCertPublicKey_RSA2.crt";
|
|
|
|
|
private $rootCertPath = __DIR__ . "/cert/alipayRootCert.crt";
|
|
|
|
|
private $gatewayUrl = "https://openapi.alipay.com/gateway.do";
|
|
|
|
|
private $appId = "2021001150621489";
|
|
|
|
|
private $alipayUserId = '2088731986604211'; // pid
|
|
|
|
|
private $rsaPrivateKey = 'MIIEogIBAAKCAQEAokaztliXge4pDoNWVVdYNSq6N+Be7xNU2LBKANhhdPfSny1VdCBgn7bbuSXA38ubkVZ8xZ/oFcPHa0LMZ5Ki9hRntU+Ry7vJN5kKwqP1CX8rCVWj2Jx2IuTUNdFA1TzCSLV1UMNvIIkFTFnkJUR++YWoQ2EBDYuQsccSbveZ4U5bHf4xopNhQ42a3lwVyuJaBC3q/m4pLVkBIxupP7HSgc3M/ZP0EBHRoq65wHrRsW70A3JPYCmKaw+9W0qeM2fmSXjhU0U7TS1QyyWLwaYgkFZySFscGYVgG6L1dzdVkSbQxlcp/3kEBQXnwTgdODBCdoNrDBZyIteMOlzfZ2MK/QIDAQABAoIBACkqSFJ8fMqgENg2pwL1KlIqaZzdFRgOzlo9tjgqq+ZRK6PniyLvR7OcXnbERf4/l1IyH2q+mtBSntbt1g58G0zTdk9/RNvq4itxblJb50Ame1Nd3zeG0U0ewVp5n7m4NQzew0jemuUk/SwWLZLqok9IAZw+EldOTUFb36g4tVd68Z6uJ5fpUhzMI/HZrFq2wYnH4SwhFJQbHVGadPzB4yWD4jvT4zaAZI1MeXugDjnpRYLIqd5r+fJv2mRbRgDBb2fWW7R+5xaMsZATARkFoXhy0CbZu3fOEELiKPfgxMy4MgqEmJwE7hSg8hD8z63wC03nY2JY5IOY3DdzFZRQo6ECgYEA6sQUO933kW8hHVy0VcI0aLp5LUykl05BEb5MSvKB61ghxZzQDREQNsMlkIggL1ENSW2cNS12yqxeEPdEx89ekJ2gLocOtho5Ufg49rj0wK/fp55Xu412SF06NSSLk636C0j1dK3CP+T3JSH2cBLpqJK9n9moLo2kODDibm2JhEkCgYEAsPQmElDYFMhNIKNmNgLfXimUDPswKLpHyYCfiBMHaArAV+LB6lDynxTsBdFEqbTpXeZiGG0HtlR+YjaCj0ujdKoMaeNY+SCZ+VxsioBAP+SWIj2UKg8Xi6YqW9zQnGZis17CeHCAq27OHz69m8udVk55OlzhTuyI9lEnVc6PqRUCgYAELxptNreC0Ag3Db/pB10HwMsIE6WbTLm8JzgU3d2S5C815mWO1g8D6tZwjPyF21vxQxLVn8nOMuQ6SS3gocF9slF4gs+wTydWXqYlP4adKIVD536IySyifYbcC5qxNxiNuu8k9TPRD7OX5dMOjEe9yV+3yZlFuyCCH9zpOuqIgQKBgHu8/rJoHfHKb0SXfm3ebFvoL0M0k2SnfnOFogkBZXh3rDDIvFkh6cccVj9rKtyRSW8EHyx9cZsqUoZTH9EcT1zRXITfGeR7y6/31V60eDk1m1auQOF4VDqvI4fBTY9QeUx8wvh9kzxN640lzmkXZRppHZSWRmduOAgmj58NJqBRAoGAY0qXaL0nDAehVpoxVUDmFdPuallq9oEz5z5Q29A0IXm/dHkbbHEtEdE/MU9WPn3yOIwwGkF21q3cormt4oyi2ro4OlFSKmpQzMtg/I5Tj5XbOz13FYA60IhjYwqZ2pW/l8oEg6ZAIo2vNSjqJudQS/16Q8xu8Gxzl9E9e3LZBeE=';
|
|
|
|
|
|
|
|
|
|
public function transfer($aliAccount, $realName, $orderId, $amount, $title='') {
|
|
|
|
|
|
|
|
|
|
$aop = new AopCertClient ();
|
|
|
|
|
//1、execute 使用
|
|
|
|
|
$appCertPath = $this->appCertPath;
|
|
|
|
|
$alipayCertPath = $this->alipayCertPath;
|
|
|
|
|
$rootCertPath = $this->rootCertPath;
|
|
|
|
|
|
|
|
|
|
$aop->gatewayUrl = $this->gatewayUrl;
|
|
|
|
|
$aop->appId = $this->appId;
|
|
|
|
|
$aop->rsaPrivateKey = $this->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 AlipayFundTransUniTransferRequest();
|
|
|
|
|
$arrData = [
|
|
|
|
|
'out_biz_no' => $orderId, // 商户端的唯一订单号,对于同一笔转账请求,商户需保证该订单号唯一。
|
|
|
|
|
// 单笔无密转账到支付宝账户固定
|
|
|
|
|
// TRANS_ACCOUNT_NO_PWD 产品取值范围[0.1,100000000]
|
|
|
|
|
// STD_RED_PACKET [0.01,100000000]
|
|
|
|
|
'trans_amount' => $amount, // 订单总金额,单位为元,精确到小数点后两位,
|
|
|
|
|
'product_code' => 'TRANS_ACCOUNT_NO_PWD',
|
|
|
|
|
|
|
|
|
|
'biz_scene' => 'DIRECT_TRANSFER', // B2C现金红包、单笔无密转账到支付宝/银行卡
|
|
|
|
|
'order_title' => $title, // 转账业务的标题,用于在支付宝用户的账单里显示
|
|
|
|
|
'payee_info' => [
|
|
|
|
|
'identity' => $aliAccount,// 参与方的唯一标识
|
|
|
|
|
'identity_type' => 'ALIPAY_LOGON_ID', // 支付宝登录号,支持邮箱和手机号格式
|
|
|
|
|
'name' => $realName, // 参与方真实姓名,如果非空,将校验收款支付宝账号姓名一致性。当identity_type=ALIPAY_LOGON_ID时,本字段必填。
|
|
|
|
|
],
|
|
|
|
|
'remark' => $title
|
|
|
|
|
];
|
|
|
|
|
$request->setBizContent(json_encode($arrData,JSON_UNESCAPED_UNICODE));
|
|
|
|
|
$result = $aop->execute($request);
|
|
|
|
|
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
|
|
|
|
|
return $result->$responseNode;
|
|
|
|
|
// $resultCode = $result->$responseNode->code;
|
|
|
|
|
// if(!empty($resultCode)&&$resultCode == 10000){
|
|
|
|
|
// return 0;
|
|
|
|
|
// } else {
|
|
|
|
|
// return -1;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 失败返回-1
|
|
|
|
|
* 成功返回 order_id order_fee pay_date status ali_order_id
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public function order($orderId) {
|
|
|
|
|
$aop = new AopCertClient ();
|
|
|
|
|
//1、execute 使用
|
|
|
|
|
$appCertPath = $this->appCertPath;
|
|
|
|
|
$alipayCertPath = $this->alipayCertPath;
|
|
|
|
|
$rootCertPath = $this->rootCertPath;
|
|
|
|
|
|
|
|
|
|
$aop->gatewayUrl = $this->gatewayUrl;
|
|
|
|
|
$aop->appId = $this->appId;
|
|
|
|
|
$aop->rsaPrivateKey = $this->rsaPrivateKey;
|
|
|
|
|
$aop->alipayrsaPublicKey = $aop->getPublicKey($alipayCertPath);//调用getPublicKey从支付宝公钥证书中提取公钥
|
|
|
|
|
// echo ($aop->alipayrsaPublicKey);die;
|
|
|
|
|
$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获取支付宝根证书序列号
|
|
|
|
|
// alipay.fund.trans.order.query
|
|
|
|
|
Vendor('Alipay2020.Aop.Request.AlipayFundTransOrderQueryRequest');
|
|
|
|
|
$request = new AlipayFundTransOrderQueryRequest();
|
|
|
|
|
$arrData = [
|
|
|
|
|
'out_biz_no' => $orderId, // 商户端的唯一订单号,对于同一笔转账请求,商户需保证该订单号唯一。
|
|
|
|
|
'order_id' => ''
|
|
|
|
|
];
|
|
|
|
|
$request->setBizContent(json_encode($arrData,JSON_UNESCAPED_UNICODE));
|
|
|
|
|
$result = $aop->execute($request);
|
|
|
|
|
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
|
|
|
|
|
$resultCode = $result->$responseNode->code;
|
|
|
|
|
if(!empty($resultCode)&&$resultCode == 10000){
|
|
|
|
|
$ret['order_id'] = $result->alipay_fund_trans_order_query_response->out_biz_no;
|
|
|
|
|
$ret['order_fee'] = $result->alipay_fund_trans_order_query_response->order_fee;
|
|
|
|
|
$ret['pay_date'] = $result->alipay_fund_trans_order_query_response->pay_date;
|
|
|
|
|
$ret['status'] = $result->alipay_fund_trans_order_query_response->status;
|
|
|
|
|
$ret['ali_order_id'] = $result->alipay_fund_trans_order_query_response->order_id;
|
|
|
|
|
|
|
|
|
|
return $ret;
|
|
|
|
|
} else {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function account() {
|
|
|
|
|
|
|
|
|
|
$aop = new AopCertClient();
|
|
|
|
|
//1、execute 使用
|
|
|
|
|
$appCertPath = $this->appCertPath;
|
|
|
|
|
$alipayCertPath = $this->alipayCertPath;
|
|
|
|
|
$rootCertPath = $this->rootCertPath;
|
|
|
|
|
|
|
|
|
|
$aop->gatewayUrl = $this->gatewayUrl;
|
|
|
|
|
$aop->appId = $this->appId;
|
|
|
|
|
$aop->rsaPrivateKey = $this->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 AlipayFundAccountQueryRequest();
|
|
|
|
|
$arrData = [
|
|
|
|
|
'alipay_user_id' => $this->alipayUserId, // 商户端的唯一订单号,对于同一笔转账请求,商户需保证该订单号唯一。
|
|
|
|
|
// 'account_product_code' => 'DING_ACCOUNT',
|
|
|
|
|
// 'account_scene_code' => 'SCENE_000_000_000',
|
|
|
|
|
'account_type' => 'ACCTRANS_ACCOUNT'
|
|
|
|
|
];
|
|
|
|
|
$request->setBizContent(json_encode($arrData,JSON_UNESCAPED_UNICODE));
|
|
|
|
|
$result = $aop->execute($request);
|
|
|
|
|
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
|
|
|
|
|
$resultCode = $result->$responseNode->code;
|
|
|
|
|
if(!empty($resultCode)&&$resultCode == 10000){
|
|
|
|
|
$ret['amount'] = $result->alipay_fund_account_query_response->available_amount;
|
|
|
|
|
|
|
|
|
|
return $ret;
|
|
|
|
|
} else {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
?>
|