From 343c93ad8e85f4c80ff0b107d485f2b45bc21c13 Mon Sep 17 00:00:00 2001 From: tokumeikoi Date: Mon, 14 Jun 2021 22:27:29 +0900 Subject: [PATCH] add: wechatpay native --- app/Console/Commands/Test.php | 2 - app/Payments/WechatPayNative.php | 84 ++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 app/Payments/WechatPayNative.php diff --git a/app/Console/Commands/Test.php b/app/Console/Commands/Test.php index 0d7079ba..667e616c 100644 --- a/app/Console/Commands/Test.php +++ b/app/Console/Commands/Test.php @@ -2,8 +2,6 @@ namespace App\Console\Commands; -use App\Payments\AlipayF2F; -use App\Services\PaymentService; use Illuminate\Console\Command; class Test extends Command diff --git a/app/Payments/WechatPayNative.php b/app/Payments/WechatPayNative.php new file mode 100644 index 00000000..37caf21c --- /dev/null +++ b/app/Payments/WechatPayNative.php @@ -0,0 +1,84 @@ +config = $config; + $this->customResult = ''; + } + + public function form() + { + return [ + 'currency' => [ + 'label' => 'APPID', + 'description' => '绑定微信支付商户的APPID', + 'type' => 'input', + ], + 'stripe_sk_live' => [ + 'label' => '商户号', + 'description' => '微信支付商户号', + 'type' => 'input', + ], + 'stripe_webhook_key' => [ + 'label' => 'APIKEY(v1)', + 'description' => '', + 'type' => 'input', + ] + ]; + } + + public function pay($order) + { + $gateway = Omnipay::create('WechatPay_Native'); + $gateway->setAppId($this->config['app_id']); + $gateway->setMchId($this->config['mch_id']); + $gateway->setApiKey($this->config['api_key']); + $gateway->setNotifyUrl($order['notify_url']); + + $params = [ + 'body' => $order['trade_no'], + 'out_trade_no' => $order['trade_no'], + 'total_fee' => $order['total_amount'], + 'spbill_create_ip' => '0.0.0.0', + 'fee_type' => 'CNY' + ]; + + $request = $gateway->purchase($params); + $response = $request->send(); + $response = $response->getData(); + if ($response['return_code'] !== 'SUCCESS') { + abort(500, $response['return_msg']); + } + return [ + 'type' => 0, + 'data' => $response['code_url'] + ]; + } + + public function notify($params) + { + $data = Helper::xml2array(file_get_contents('php://input')); + $gateway = Omnipay::create('WechatPay'); + $gateway->setAppId($this->config['app_id']); + $gateway->setMchId($this->config['mch_id']); + $gateway->setApiKey($this->config['api_key']); + $response = $gateway->completePurchase([ + 'request_params' => file_get_contents('php://input') + ])->send(); + + if (!$response->isPaid()) { + die('FAIL'); + } + + return [ + 'trade_no' => $data['out_trade_no'], + 'callback_no' => $data['transaction_id'] + ]; + } +}