mirror of
https://github.com/v2board/v2board.git
synced 2024-11-10 09:39:10 +08:00
add: wechatpay native
This commit is contained in:
parent
f80af8efdc
commit
343c93ad8e
@ -2,8 +2,6 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Payments\AlipayF2F;
|
||||
use App\Services\PaymentService;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class Test extends Command
|
||||
|
84
app/Payments/WechatPayNative.php
Normal file
84
app/Payments/WechatPayNative.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace App\Payments;
|
||||
|
||||
use Omnipay\Omnipay;
|
||||
use Omnipay\WechatPay\Helper;
|
||||
|
||||
class WechatPayNative {
|
||||
public function __construct($config)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->customResult = '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
|
||||
}
|
||||
|
||||
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']
|
||||
];
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user