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.

155 lines
9.2 KiB
PHP

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?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_2021001159678209.crt";
private $alipayCertPath = __DIR__ . "/cert/alipayCertPublicKey_RSA2.crt";
private $rootCertPath = __DIR__ . "/cert/alipayRootCert.crt";
private $gatewayUrl = "https://openapi.alipay.com/gateway.do";
private $appId = "2021001159678209";
private $alipayUserId = '2088631242187552';
private $rsaPrivateKey = 'MIIEogIBAAKCAQEApuiUWwiE9apUAWLaX8SDYgt2oQnGCtT60dZvpMMHCuGR71HKCoLuCbgoZ3GUGhS9PByQZp/hNygEu6GzQwNTj5PiWMVrlfL7Xjkcpg+JbSiR3TUSJfYO2uLa+atJCQDNhsE6cfdcE4VHiSU5TK4ezBaIcYBPmzM6xKdQ6BblCM7fakTlVct+gvrE69M6XoyoM5VT6/lRwTIscWfwkyd/lps4jBwhuVMDboulk1BXQ2+daIQGqK4QQfQtC0bvREC+gwwmFaIfrw3dF/nOVEUEyhx4SFb7RzQv9mZx9HL4P4qCRvGl+jE5NE9hUWNz2pajR2cg7DxHDEMB0dSz8LRW9QIDAQABAoIBAADqDz38avYJi9JCH14c7ndQBsNVEV+n0QPrP8tQQi6eE7WS5h9uni0xdA81ARGvgWXd5jCZuZsavgPlG91HHGMR9VB1LGSy4wueFnkWZrNRYJMsoj/Q/D3Ytkhd1tWUyottbYuIRlnZBg5LROgVoBeQHAk7IbSA8FZ5cCkFTxXgQfOHd2yWJGkI1bz9MCTawT96fEBAowq2g28LsT44/EiJIGXY4hv7SOpZIIp9JZfmEDO9vOf5nkkZbsli0KPQPkTvly3p0YfMATqsxMLue1lwfHmueRMdk8p31aaz3c2aOVyvtyNae/UP3/O47HgAI9LXoAbzChlMi15o5YTyaxUCgYEA56ThYW4+9CB1Q+qFkz4KyarI4//AHyha/LELXpeRICidxDw6PQdfBi/75udbQDI0tISJjio+S8sKUlCWcHi/1/A8k0aZBN1rs9mTVQrN1zMbSgoYOHOIGE4147ig5vU6gjvpI/SPbeg3BLg3rd/3IOsDmh4HoVhSUINUwJ9dK2MCgYEAuHU5eeInSKeEPWMMqql+OxHnA7g/Z9RYJsuuXrNm8qsGDxJbJmVfBsa7Uo466hwr3OhMuk2ShensEzFYxDrURgADjAgVn7puzMUtHYMNcK06Se8g/Crq6UYM0OGaFfKVMgX8gq+eAdDZmX+WmdJBgakVLfjxlQ94ar5EGe+w/8cCgYB4TjyzsmNFvRnKJSIsn7tQk790Ep7AT+A5fuXNweAgmJeflDwW+B4VA5TLjnro82pGGtOqHyxths0chTgsv7m7N8zuHGtaiHjoVmbbcxoG20cgA/AiWXZkUTJRy9DdQp2Zh+4Eu35GcaUpcVeRmVErKoObZl9GH63YnOzGgb4MywKBgGebWHRQhfY2OX3tg7DcUQ3GyXZ6aAre58CqyT9iD2Igk9+lVNNlPxHkUFVXlFnpBu4nAOnoJnPXZ4WEQzK9RHwpB9UAuXylUBTub5/S+5qdgk8C5Qke5iGu+gXdohnPzuNxH1scX2jvsTmZw7KUubylh0LyQGeUb/Os+T2EN2wDAoGASbDD8hLDI64DpDp73XHbKbrdHaz7c9NkUsLD3FB6nmGQtAD8Gvuvd3PvhhBGz5O/ndUU0KSdZb4Yg3/3Qx4TWIJhobkXsNLkv+aPNxyjQBkFfJmXjsx2phsvjPNRICBeWlLKbB30SbZ6uCs6uypebSzIxdjT2riFmuuaJtsZJVM=';
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";
$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;
}
}
}
?>