更新支付资金接口

This commit is contained in:
Anyon 2020-03-11 09:47:17 +08:00
parent a94f30edff
commit 9dbabfe89e
5 changed files with 100 additions and 1 deletions

View File

@ -15,6 +15,7 @@
namespace AliPay;
use WeChat\Contracts\BasicAliPay;
use WeChat\Exceptions\InvalidArgumentException;
/**
* 支付宝转账到账户
@ -46,6 +47,7 @@ class Transfer extends BasicAliPay
*/
public function create($options = [])
{
$this->setAppCertSnAndRootCertSn();
$this->options->set('method', 'alipay.fund.trans.uni.transfer');
return $this->getResult($options);
}
@ -59,6 +61,7 @@ class Transfer extends BasicAliPay
*/
public function queryResult($options = [])
{
$this->setAppCertSnAndRootCertSn();
$this->options->set('method', 'alipay.fund.trans.common.query');
return $this->getResult($options);
@ -73,7 +76,29 @@ class Transfer extends BasicAliPay
*/
public function queryAccount($options = [])
{
$this->setAppCertSnAndRootCertSn();
$this->options->set('method', 'alipay.fund.account.query');
return $this->getResult($options);
}
/**
* 新版 设置网关应用公钥证书SN、支付宝根证书SN
*/
protected function setAppCertSnAndRootCertSn()
{
if (!$this->config->get('app_cert')) {
throw new InvalidArgumentException("Missing Config -- [app_cert]");
}
if (!$this->config->get('root_cert')) {
throw new InvalidArgumentException("Missing Config -- [root_cert]");
}
$this->options->set('app_cert_sn', $this->getCertSN($this->config->get('app_cert')));
$this->options->set('alipay_root_cert_sn', $this->getRootCertSN($this->config->get('root_cert')));
if (!$this->options->get('app_cert_sn')) {
throw new InvalidArgumentException("Missing options -- [app_cert_sn]");
}
if (!$this->options->get('alipay_root_cert_sn')) {
throw new InvalidArgumentException("Missing options -- [alipay_root_cert_sn]");
}
}
}

2
We.php
View File

@ -85,7 +85,7 @@ class We
* 定义当前版本
* @var string
*/
const VERSION = '1.2.18';
const VERSION = '1.2.19';
/**
* 静态配置

View File

@ -276,6 +276,75 @@ abstract class BasicAliPay
return "{$html}<script>document.forms['alipaysubmit'].submit();</script>";
}
/**
* 新版 从证书中提取序列号
* @param string $sign
* @return string
*/
public function getCertSN($sign)
{
if (file_exists($sign)) $sign = file_get_contents($sign);
$ssl = openssl_x509_parse($sign);
return md5($this->_arr2str(array_reverse($ssl['issuer'])) . $ssl['serialNumber']);
}
/**
* 新版 提取根证书序列号
* @param string $sign
* @return string|null
*/
public function getRootCertSN($sign)
{
$sn = null;
if (file_exists($sign)) $sign = file_get_contents($sign);
$array = explode("-----END CERTIFICATE-----", $sign);
for ($i = 0; $i < count($array) - 1; $i++) {
$ssl[$i] = openssl_x509_parse($array[$i] . "-----END CERTIFICATE-----");
if (strpos($ssl[$i]['serialNumber'], '0x') === 0) {
$ssl[$i]['serialNumber'] = $this->_hex2dec($ssl[$i]['serialNumber']);
}
if ($ssl[$i]['signatureTypeLN'] == "sha1WithRSAEncryption" || $ssl[$i]['signatureTypeLN'] == "sha256WithRSAEncryption") {
if ($sn == null) {
$sn = md5($this->_arr2str(array_reverse($ssl[$i]['issuer'])) . $ssl[$i]['serialNumber']);
} else {
$sn = $sn . "_" . md5($this->_arr2str(array_reverse($ssl[$i]['issuer'])) . $ssl[$i]['serialNumber']);
}
}
}
return $sn;
}
/**
* 新版 数组转字符串
* @param array $array
* @return string
*/
private function _arr2str($array)
{
$string = [];
if ($array && is_array($array)) {
foreach ($array as $key => $value) {
$string[] = $key . '=' . $value;
}
}
return implode(',', $string);
}
/**
* 新版 0x转高精度数字
* @param string $hex
* @return int|string
*/
private function _hex2dec($hex)
{
list($dec, $len) = [0, strlen($hex)];
for ($i = 1; $i <= $len; $i++) {
$dec = bcadd($dec, bcmul(strval(hexdec($hex[$i - 1])), bcpow('16', strval($len - $i))));
}
return $dec;
}
/**
* 应用数据操作
* @param array $options

View File

@ -23,6 +23,10 @@ return [
'public_key' => 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtU71NY53UDGY7JNvLYAhsNa+taTF6KthIHJmGgdio9bkqeJGhHk6ttkTKkLqFgwIfgAkHpdKiOv1uZw6gVGZ7TCu5LfHTqKrCd6Uz+N7hxhY+4IwicLgpr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O/fcz7+RXZKgPDeoTeNo717tZFZGBEyUdH9M9Inqvht7+hjVDIMCYBDomYebdk3Xqo4mDBjLRdVNGrhGmVQKBgQDKS/MgTMK8Ktfnu1KzwCbn/FfHTOrp1a1t1wWPv9AW0rJPYeaP6lOkgIoO/1odG9qDDhdB6njqM+mKY5Yr3N94PHamHbwJUCmbkqEunCWpGzgcQZ1Q254xk9D7UKq/XUqW2WDqDq80GQeNial+fBc46yelQzokwdA+JdIFKoyinQKBgQCBems9V/rTAtkk1nFdt6EGXZEbLS3PiXXhGXo4gqV+OEzf6H/i/YMwJb2hsK+5GQrcps0XQihA7PctEb9GOMa/tu5fva0ZmaDtc94SLR1p5d4okyQFGPgtIp594HpPSEN0Qb9BrUJFeRz0VP6U3dzDPGHo7V4yyqRLgIN6EIcy1QKBgAqdh6mHPaTAHspDMyjJiYEc5cJIj/8rPkmIQft0FkhMUB0IRyAALNlyAUyeK61hW8sKvz+vPR8VEEk5xpSQp41YpuU6pDZc5YILZLfca8F+8yfQbZ/jll6Foi694efezl4yE/rUQG9cbOAJfEJt4o4TEOaEK5XoMbRBKc8pl22lAoGARTq0qOr9SStihRAy9a+8wi2WEwL4QHcmOjH7iAuJxy5b5TRDSjlk6h+0dnTItiFlTXdfpO8KhWA8EoSJVBZ1kcACQDFgMIA+VM+yXydtzMotOn21W4stfZ4I6dHFiujMsnKpNYVpQh3oCrJf4SeXiQDdiSCodqb1HlKkEc6naHQ=',
// 应用公钥证书新版资金类接口转app_cert_sn
'app_cert' => '',
// 支付宝根证书新版资金类接口转alipay_root_cert_sn
'root_cert' => '',
// 支付成功通知地址
'notify_url' => '',
// 网页支付回跳地址

View File

@ -23,6 +23,7 @@
"php": ">=5.4",
"ext-json": "*",
"ext-curl": "*",
"ext-bcmath": "*",
"ext-libxml": "*",
"ext-openssl": "*",
"ext-mbstring": "*",