2021-04-30 23:27:02 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 自己写别抄,抄NMB抄
|
|
|
|
|
*/
|
|
|
|
|
namespace App\Payments;
|
|
|
|
|
|
|
|
|
|
class AlipayF2F {
|
|
|
|
|
public function __construct($config)
|
|
|
|
|
{
|
|
|
|
|
$this->config = $config;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function form()
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'app_id' => [
|
|
|
|
|
'label' => '支付宝APPID',
|
|
|
|
|
'description' => '',
|
|
|
|
|
'type' => 'input',
|
|
|
|
|
],
|
|
|
|
|
'private_key' => [
|
|
|
|
|
'label' => '支付宝私钥',
|
|
|
|
|
'description' => '',
|
|
|
|
|
'type' => 'input',
|
|
|
|
|
],
|
|
|
|
|
'public_key' => [
|
|
|
|
|
'label' => '支付宝公钥',
|
|
|
|
|
'description' => '',
|
|
|
|
|
'type' => 'input',
|
2022-12-20 01:57:35 +08:00
|
|
|
|
],
|
|
|
|
|
'product_name' => [
|
|
|
|
|
'label' => '自定义商品名称',
|
|
|
|
|
'description' => '将会体现在支付宝账单中',
|
|
|
|
|
'type' => 'input'
|
2021-04-30 23:27:02 +08:00
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function pay($order)
|
|
|
|
|
{
|
2022-01-22 01:46:34 +08:00
|
|
|
|
try {
|
|
|
|
|
$gateway = new \Library\AlipayF2F();
|
2022-02-24 23:09:04 +08:00
|
|
|
|
$gateway->setMethod('alipay.trade.precreate');
|
2022-01-22 01:46:34 +08:00
|
|
|
|
$gateway->setAppId($this->config['app_id']);
|
|
|
|
|
$gateway->setPrivateKey($this->config['private_key']); // 可以是路径,也可以是密钥内容
|
|
|
|
|
$gateway->setAlipayPublicKey($this->config['public_key']); // 可以是路径,也可以是密钥内容
|
|
|
|
|
$gateway->setNotifyUrl($order['notify_url']);
|
|
|
|
|
$gateway->setBizContent([
|
2022-12-20 01:58:02 +08:00
|
|
|
|
'subject' => $this->config['product_name'] ?? (config('v2board.app_name', 'V2Board') . ' - 订阅'),
|
2022-01-22 01:46:34 +08:00
|
|
|
|
'out_trade_no' => $order['trade_no'],
|
|
|
|
|
'total_amount' => $order['total_amount'] / 100
|
|
|
|
|
]);
|
|
|
|
|
$gateway->send();
|
|
|
|
|
return [
|
|
|
|
|
'type' => 0, // 0:qrcode 1:url
|
|
|
|
|
'data' => $gateway->getQrCodeUrl()
|
|
|
|
|
];
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
abort(500, $e->getMessage());
|
2021-04-30 23:27:02 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function notify($params)
|
|
|
|
|
{
|
2022-03-09 02:40:29 +08:00
|
|
|
|
if ($params['trade_status'] !== 'TRADE_SUCCESS') return false;
|
2022-02-24 21:11:32 +08:00
|
|
|
|
$gateway = new \Library\AlipayF2F();
|
2021-04-30 23:27:02 +08:00
|
|
|
|
$gateway->setAppId($this->config['app_id']);
|
|
|
|
|
$gateway->setPrivateKey($this->config['private_key']); // 可以是路径,也可以是密钥内容
|
|
|
|
|
$gateway->setAlipayPublicKey($this->config['public_key']); // 可以是路径,也可以是密钥内容
|
|
|
|
|
try {
|
2022-02-24 21:11:32 +08:00
|
|
|
|
if ($gateway->verify($params)) {
|
2021-04-30 23:27:02 +08:00
|
|
|
|
/**
|
|
|
|
|
* Payment is successful
|
|
|
|
|
*/
|
|
|
|
|
return [
|
|
|
|
|
'trade_no' => $params['out_trade_no'],
|
|
|
|
|
'callback_no' => $params['trade_no']
|
|
|
|
|
];
|
|
|
|
|
} else {
|
|
|
|
|
/**
|
|
|
|
|
* Payment is not successful
|
|
|
|
|
*/
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
/**
|
|
|
|
|
* Payment is not successful
|
|
|
|
|
*/
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|