Skip to content

Commit

Permalink
增加支付宝APP支付
Browse files Browse the repository at this point in the history
  • Loading branch information
lgdzz committed Aug 22, 2019
1 parent 44f5b50 commit 90d2384
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 50 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
composer require lgdz/payment

#### 版本说明
2019-08-22 ------ v1.3
- [支付宝]APP支付

2019-06-06 ------ v1.2
- [支付宝]扫码支付
Expand Down
25 changes: 15 additions & 10 deletions src/driver/alipay/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
class Config
{
private $config = [
'app_id' => '',
'format' => 'JSON',
'charset' => 'UTF-8',
'sign_type' => 'RSA2',
'version' => '1.0',
'ali_public_key' => '',
'rsa_private_key' => ''
'app_id' => '',
'format' => 'JSON',
'charset' => 'UTF-8',
'sign_type' => 'RSA2',
'version' => '1.0',
'ali_public_key' => '',
'rsa_private_key' => ''
];

private $gateway = 'https://openapi.alipay.com/gateway.do';
Expand Down Expand Up @@ -75,7 +75,7 @@ protected function sign(array $data)
ksort($data);
$rsa2 = new Rsa2Encrypt;
return $rsa2->setKey($rsa2->getRsaKeyValue($this->_getConfig('rsa_private_key'), 'private'))
->encrypt(urldecode(http_build_query($data)));
->encrypt(urldecode(http_build_query($data)));
}

protected function send()
Expand All @@ -88,6 +88,11 @@ protected function getUrl()
return $this->gateway . '?' . $this->_splicingString($this->body);
}

protected function getString()
{
return $this->_splicingString($this->body);
}

//获取支付宝推送数据
protected function getMsgFromAli()
{
Expand All @@ -101,7 +106,7 @@ protected function succSyncVerifySign(array $data, $sign)
{
$rsa2 = new Rsa2Encrypt;
return $rsa2->setKey($rsa2->getRsaKeyValue($this->_getConfig('ali_public_key'), 'public'))
->rsaVerify(json_encode($data, JSON_UNESCAPED_UNICODE), $sign);
->rsaVerify(json_encode($data, JSON_UNESCAPED_UNICODE), $sign);
}

//成功验证签名(异步) @return bool
Expand All @@ -113,7 +118,7 @@ protected function succVerifySign(array $data)
ksort($data);
$rsa2 = new Rsa2Encrypt;
return $rsa2->setKey($rsa2->getRsaKeyValue($this->_getConfig('ali_public_key'), 'public'))
->rsaVerify(urldecode(http_build_query($data)), $sign);
->rsaVerify(urldecode(http_build_query($data)), $sign);
} else {
return false;
}
Expand Down
94 changes: 54 additions & 40 deletions src/driver/alipay/Pay.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ private function wap(Charge $charge)
{
$this->method = 'alipay.trade.wap.pay';
return $this->body([
'other' => function (&$data) use ($charge) {
$data['return_url'] = $charge->getPayDataByName('return_url', '');
$data['notify_url'] = $charge->getPayDataByName('notify_url', '');
},
'content' => function (&$data) use ($charge) {
$data['subject'] = $charge->getPayDataByName('title');
$data['body'] = $charge->getPayDataByName('detail', '');
$data['out_trade_no'] = $charge->getPayDataByName('order_no');
$data['total_amount'] = $charge->getPayDataByName('pay_amount');
$data['passback_params'] = urlencode($charge->getPayDataByName('passback_params', ''));
$data['product_code'] = 'QUICK_WAP_WAY';
}
'other' => function (&$data) use ($charge) {
$data['return_url'] = $charge->getPayDataByName('return_url', '');
$data['notify_url'] = $charge->getPayDataByName('notify_url', '');
},
'content' => function (&$data) use ($charge) {
$data['subject'] = $charge->getPayDataByName('title');
$data['body'] = $charge->getPayDataByName('detail', '');
$data['out_trade_no'] = $charge->getPayDataByName('order_no');
$data['total_amount'] = $charge->getPayDataByName('pay_amount');
$data['passback_params'] = urlencode($charge->getPayDataByName('passback_params', ''));
$data['product_code'] = 'QUICK_WAP_WAY';
}
])->getUrl();
}

Expand All @@ -49,40 +49,40 @@ private function pc(Charge $charge)
{
$this->method = 'alipay.trade.page.pay';
return $this->body([
'other' => function (&$data) use ($charge) {
$data['return_url'] = $charge->getPayDataByName('return_url', '');
$data['notify_url'] = $charge->getPayDataByName('notify_url', '');
},
'content' => function (&$data) use ($charge) {
$data['subject'] = $charge->getPayDataByName('title');
$data['body'] = $charge->getPayDataByName('detail', '');
$data['out_trade_no'] = $charge->getPayDataByName('order_no');
$data['total_amount'] = $charge->getPayDataByName('pay_amount');
$data['goods_type'] = $charge->getPayDataByName('goods_type', '1');
$data['qr_pay_mode'] = $charge->getPayDataByName('qr_pay_mode', '2');
$data['qrcode_width'] = $charge->getPayDataByName('qrcode_width', '100');
$data['passback_params'] = urlencode($charge->getPayDataByName('passback_params', ''));
$data['product_code'] = 'FAST_INSTANT_TRADE_PAY';
}
'other' => function (&$data) use ($charge) {
$data['return_url'] = $charge->getPayDataByName('return_url', '');
$data['notify_url'] = $charge->getPayDataByName('notify_url', '');
},
'content' => function (&$data) use ($charge) {
$data['subject'] = $charge->getPayDataByName('title');
$data['body'] = $charge->getPayDataByName('detail', '');
$data['out_trade_no'] = $charge->getPayDataByName('order_no');
$data['total_amount'] = $charge->getPayDataByName('pay_amount');
$data['goods_type'] = $charge->getPayDataByName('goods_type', '1');
$data['qr_pay_mode'] = $charge->getPayDataByName('qr_pay_mode', '2');
$data['qrcode_width'] = $charge->getPayDataByName('qrcode_width', '100');
$data['passback_params'] = urlencode($charge->getPayDataByName('passback_params', ''));
$data['product_code'] = 'FAST_INSTANT_TRADE_PAY';
}
])->getUrl();
}

private function precreate(Charge $charge)
{
$this->method = 'alipay.trade.precreate';
$result = $this->body([
'other' => function (&$data) use ($charge) {
$data['return_url'] = $charge->getPayDataByName('return_url', '');
$data['notify_url'] = $charge->getPayDataByName('notify_url', '');
},
'content' => function (&$data) use ($charge) {
$data['subject'] = $charge->getPayDataByName('title');
$data['body'] = $charge->getPayDataByName('detail', '');
$data['out_trade_no'] = $charge->getPayDataByName('order_no');
$data['total_amount'] = $charge->getPayDataByName('pay_amount');
$data['passback_params'] = urlencode($charge->getPayDataByName('passback_params', ''));
$data['product_code'] = $charge->getPayDataByName('goods_type', 'FACE_TO_FACE_PAYMENT');
}
'other' => function (&$data) use ($charge) {
$data['return_url'] = $charge->getPayDataByName('return_url', '');
$data['notify_url'] = $charge->getPayDataByName('notify_url', '');
},
'content' => function (&$data) use ($charge) {
$data['subject'] = $charge->getPayDataByName('title');
$data['body'] = $charge->getPayDataByName('detail', '');
$data['out_trade_no'] = $charge->getPayDataByName('order_no');
$data['total_amount'] = $charge->getPayDataByName('pay_amount');
$data['passback_params'] = urlencode($charge->getPayDataByName('passback_params', ''));
$data['product_code'] = $charge->getPayDataByName('goods_type', 'FACE_TO_FACE_PAYMENT');
}
])->send();

$data = $result['alipay_trade_precreate_response'] ?? null;
Expand All @@ -98,7 +98,21 @@ private function precreate(Charge $charge)
//APP支付
private function app(Charge $charge)
{

$this->method = 'alipay.trade.app.pay';
return $this->body([
'other' => function (&$data) use ($charge) {
$data['return_url'] = $charge->getPayDataByName('return_url', '');
$data['notify_url'] = $charge->getPayDataByName('notify_url', '');
},
'content' => function (&$data) use ($charge) {
$data['subject'] = $charge->getPayDataByName('title');
$data['body'] = $charge->getPayDataByName('detail', '');
$data['out_trade_no'] = $charge->getPayDataByName('order_no');
$data['total_amount'] = $charge->getPayDataByName('pay_amount');
$data['passback_params'] = urlencode($charge->getPayDataByName('passback_params', ''));
$data['product_code'] = $charge->getPayDataByName('goods_type', 'QUICK_MSECURITY_PAY');
},
])->getString();
}

}

0 comments on commit 90d2384

Please sign in to comment.