You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

156 lines
9.2 KiB
PHTML

5 years ago
<?php
5 years ago
require_once "aop/AopCertClient.php";
5 years ago
require_once "aop/request/AlipayFundTransUniTransferRequest.php";
require_once "aop/request/AlipayFundTransOrderQueryRequest.php";
5 years ago
require_once "aop/request/AlipayFundAccountQueryRequest.php";
5 years ago
5 years ago
class Fund {
private $appCertPath = __DIR__ . "/cert/appCertPublicKey_2021001165628090.crt";
5 years ago
private $alipayCertPath = __DIR__ . "/cert/alipayCertPublicKey_RSA2.crt";
private $rootCertPath = __DIR__ . "/cert/alipayRootCert.crt";
private $gatewayUrl = "https://openapi.alipay.com/gateway.do";
private $appId = "2021001165628090";
private $alipayUserId = '2088331082835421'; // pid
private $rsaPrivateKey = 'MIIEowIBAAKCAQEAmDggf4zno5KmKKEv0gbKctXyceEylTbWgZhannFGDXBkVkUqKC1btcKOFRWteVcQDFFCAgMobiTxH4rpIopyoC3x66mAynTVQnEWYFCyc628ZMAJ6aXQMvYNmzJgDczX8YI9taXbOf2YtV3uLdSs6t3Qm/rCBfrn/wj30QNsUm1f8yqCiHVwZ3jTM3ygKCr4SU3XjTKa1IqlYvGgIHrNHmTwATxvNRXa9pDTvSFz/zdvFxveWBn9PDhiNVebgEDFq0Xtv//z78UzRC3T8vV7HfCvcuR/gH0bVhvTzK55VlXlANM8o06tGsOj1jpJUGjUeMe2yiH9bDO810zNuri9LwIDAQABAoIBADoZQh4s88S1FoJvc0cgnGjUTCM3Jw1YzurL8dqDtY8vlLxwzbRkC5sGVSCrE3k6x79LzHvkJKxVoUq+xFkQqsuEfc/K9INRsIwZicbdRh9s8nkp6x6o0RyCWZMg2RSrWMivQ0pvsYsixgSDg4Mup4lFfHfsb93EdIQdMikuu0uCKFcXLO8UTma7mBRLdOis11vaZv7ROVftEUww9MZHCh/AJl7S73RvwZwZHQ9H5Y7fJ8EFqARJmTDEwDaOUQUGVTVho85KIlvpQ9gYbwy9R+xbftBSra+/THTiYjcMPR06wbf0dQwSunsz/NK4guVIpjKD23hQI1XcTcvxl6qRvjECgYEA12oro1NV9U4wVdwbbGzonW3hyNIE8pNbs3AE4q8pJF8aTVVnQuicunrgfK1W88urrngMMx+byg4ZnxUmahcyU+fId+z6FZbfypij+lMRpF85oQ0bhcXn04dcJimMlNrV4i62GeVcKtaAvoVXNYOXeS7SHtZ2nI0f7ArHbdgpbgMCgYEAtOXtfm3+CmNrlbhyPXPjUbNY3q3Uo09X6R01zYSvIobl3hoVVsw+7zJIAAaCTLcRxiVhvK5QVdRi/ohUphu2YugJx8fzNw6zl0iR/B9dWpDplMFDn3VOuS5UBeIHDn1C/A8RO7VKmYpCSAyHZxaxg0sAsAqjn9pk0ClvFpshcmUCgYEAwxXL32Yher8M1zU3QMKBB9HzoMNS57y8V40jX4fyYpYeY9rsYZP4HIobs83n6XKSULc3lTUTCbIrUf79gybu1T4cNz/OXK7+jaQfHR0N5Sa4MjqEqmnIwbDcq1MFlel5uhVDpcAp8EHC5sgrarN6Aq18baEcWjsUpdg9NCWHn7ECgYAVcyodErfLzYwlPbC2Hra2qliAVwZesvrOlnsZuoD1zB8Xneon16IixMiK0DrFE/QUlbwoHldCRiPS4KGA7MpMogz+1nO9dI3RA3bj+WgdZA9+Zwg4sTU7egXWiL2jdzDpKHQ3q0CEQkOnvWyUybkUw2D6fth2DPRlRnR4rr5hjQKBgHxl/E/sWi8iTN1thUbWzs2Q/8Qt+CHiXnWEU1rraV/0OlE4wbYVyFxURuZHCNdpTyuj0LS28WanbjJsmceL//+hy5qcjSBFJ8UO4Mw8pwDM8SEfWbo/MHNV48ElovOXxLrKTuvQUR6duWkv73qZYOpPYr+Rl0ylHGvNsqsLY7LZ';
5 years ago
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;
// }
5 years ago
}
/*
* 失败返回-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;
}
}
}
?>