123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <?php
- namespace App\Payments;
- use Omnipay\Omnipay;
- 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',
- ]
- ];
- }
- public function pay($order)
- {
- $gateway = Omnipay::create('Alipay_AopF2F');
- $gateway->setSignType('RSA2');
- $gateway->setAppId($this->config['app_id']);
- $gateway->setPrivateKey($this->config['private_key']);
- $gateway->setAlipayPublicKey($this->config['public_key']);
- $gateway->setNotifyUrl($order['notify_url']);
- $request = $gateway->purchase();
- $request->setBizContent([
- 'subject' => config('v2board.app_name', 'V2Board') . ' - 订阅',
- 'out_trade_no' => $order['trade_no'],
- 'total_amount' => $order['total_amount'] / 100
- ]);
-
- $response = $request->send();
- $result = $response->getAlipayResponse();
- if ($result['code'] !== '10000') {
- abort(500, $result['sub_msg']);
- }
- return [
- 'type' => 0,
- 'data' => $response->getQrCode()
- ];
- }
- public function notify($params)
- {
- $gateway = Omnipay::create('Alipay_AopF2F');
- $gateway->setSignType('RSA2');
- $gateway->setAppId($this->config['app_id']);
- $gateway->setPrivateKey($this->config['private_key']);
- $gateway->setAlipayPublicKey($this->config['public_key']);
- $request = $gateway->completePurchase();
- $request->setParams($_POST);
- try {
-
- $response = $request->send();
- if ($response->isPaid()) {
-
- return [
- 'trade_no' => $params['out_trade_no'],
- 'callback_no' => $params['trade_no']
- ];
- } else {
-
- return false;
- }
- } catch (\Exception $e) {
-
- return false;
- }
- }
- }
|