mirror of
https://github.com/ProxyPanel/ProxyPanel.git
synced 2026-04-06 20:50:01 +00:00
Update 添加麻瓜宝支付宝+微信支付方式,修复麻瓜宝请求支付和回调接口
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
namespace App\Http\Controllers\Gateway;
|
||||
|
||||
use Auth;
|
||||
use Http;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Log;
|
||||
use Response;
|
||||
@@ -13,69 +12,91 @@ class BitpayX extends AbstractPayment
|
||||
public function purchase($request): JsonResponse
|
||||
{
|
||||
$payment = $this->creatNewPayment(Auth::id(), $request->input('id'), $request->input('amount'));
|
||||
|
||||
$data = [
|
||||
'merchant_order_id' => $payment->trade_no,
|
||||
'price_amount' => $payment->amount,
|
||||
'price_currency' => 'CNY',
|
||||
'title' => '支付单号:'.$payment->trade_no,
|
||||
'description' => sysConfig('subject_name') ?: sysConfig('website_name'),
|
||||
'callback_url' => route('payment.notify', ['method' => 'bitpayx']),
|
||||
'success_url' => route('invoice'),
|
||||
'cancel_url' => route('invoice'),
|
||||
'token' => $this->sign($payment->trade_no),
|
||||
'merchant_order_id' => $payment->trade_no,
|
||||
'price_amount' => (float) $payment->amount,
|
||||
'price_currency' => 'CNY',
|
||||
'title' => '支付单号:'.$payment->trade_no,
|
||||
'description' => sysConfig('subject_name') ?: sysConfig('website_name'),
|
||||
'callback_url' => route('payment.notify', ['method' => 'bitpayx']),
|
||||
'success_url' => route('invoice'),
|
||||
'cancel_url' => route('invoice'),
|
||||
'token' => $this->sign($this->prepareSignId($payment->trade_no)),
|
||||
];
|
||||
if ($request->input('type') == 1) {
|
||||
$data['pay_currency'] = 'ALIPAY';
|
||||
} elseif ($request->input('type') == 3) {
|
||||
$data['pay_currency'] = 'WECHAT';
|
||||
}
|
||||
$result = $this->sendRequest($data);
|
||||
|
||||
if ($result['status'] === 200 || $result['status'] === 201) {
|
||||
$result['payment_url'] .= '&lang=zh';
|
||||
$payment->update(['url' => $result['payment_url']]);
|
||||
|
||||
return Response::json(['status' => 'success', 'url' => $result['payment_url'], 'message' => '创建订单成功!']);
|
||||
}
|
||||
|
||||
Log::warning('创建订单错误:'.var_export($result, true));
|
||||
|
||||
return Response::json(['status' => 'fail', 'message' => '创建订单失败!'.$result['error']]);
|
||||
}
|
||||
|
||||
private function sign($tradeNo): string
|
||||
private function prepareSignId($tradeNo): string
|
||||
{
|
||||
$data = [
|
||||
'merchant_order_id' => $tradeNo,
|
||||
'secret' => sysConfig('bitpay_secret'),
|
||||
'type' => 'FIAT',
|
||||
'secret' => sysConfig('bitpay_secret'),
|
||||
'type' => 'FIAT',
|
||||
];
|
||||
ksort($data);
|
||||
|
||||
return $this->aliStyleSign($data, sysConfig('bitpay_secret'));
|
||||
return http_build_query($data);
|
||||
}
|
||||
|
||||
private function sign($data)
|
||||
{
|
||||
return strtolower(md5(md5($data).sysConfig('bitpay_secret')));
|
||||
}
|
||||
|
||||
private function sendRequest($data, $type = 'createOrder')
|
||||
{
|
||||
$client = Http::baseUrl('https://api.mugglepay.com/v1/')
|
||||
->timeout(15)
|
||||
->withHeaders([
|
||||
'token' => sysConfig('bitpay_secret'),
|
||||
'content-type' => 'application/json',
|
||||
]);
|
||||
|
||||
if ($type === 'query') {
|
||||
$response = $client->get('orders/merchant_order_id/status?id='.$data['merchant_order_id']);
|
||||
} else {// Create Order
|
||||
$response = $client->post('orders', ['body' => json_encode($data)]);
|
||||
}
|
||||
if ($response->failed()) {
|
||||
Log::error('BitPayX请求支付错误:'.var_export($response, true));
|
||||
$bitpayGatewayUri = 'https://api.mugglepay.com/v1/';
|
||||
$headers = ['content-type: application/json', 'token: '.sysConfig('bitpay_secret')];
|
||||
$curl = curl_init();
|
||||
if ($type === 'createOrder') {
|
||||
$bitpayGatewayUri .= 'orders';
|
||||
curl_setopt($curl, CURLOPT_URL, $bitpayGatewayUri);
|
||||
curl_setopt($curl, CURLOPT_POST, 1);
|
||||
$data_string = json_encode($data);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
|
||||
} elseif ($type === 'query') {
|
||||
$bitpayGatewayUri .= 'orders/merchant_order_id/status?id='.$data['merchant_order_id'];
|
||||
curl_setopt($curl, CURLOPT_URL, $bitpayGatewayUri);
|
||||
curl_setopt($curl, CURLOPT_HTTPGET, 1);
|
||||
}
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
||||
$result = curl_exec($curl);
|
||||
curl_close($curl);
|
||||
|
||||
return $response->json();
|
||||
return json_decode($result, true);
|
||||
}
|
||||
|
||||
private function verify_bit($data, $signature)
|
||||
{
|
||||
$mySign = $this->sign($data);
|
||||
|
||||
return $mySign === $signature;
|
||||
}
|
||||
|
||||
//Todo: Postman虚拟测试通过,需要真实数据参考验证
|
||||
public function notify($request): void
|
||||
{
|
||||
$tradeNo = $request->input(['merchant_order_id']);
|
||||
if ($request->input(['status']) === 'PAID' && hash_equals($this->sign($tradeNo), $request->input(['token']))) {
|
||||
// 准备待签名数据
|
||||
$str_to_sign = $this->prepareSignId($tradeNo);
|
||||
if ($request->input(['status']) === 'PAID' && $this->verify_bit($str_to_sign, $request->input(['token']))) {
|
||||
if ($this->paymentReceived($tradeNo)) {
|
||||
exit(json_encode(['status' => 200]));
|
||||
}
|
||||
|
||||
@@ -217,10 +217,10 @@
|
||||
<div class="tab-content pb-100">
|
||||
<x-system.tab-pane id="paymentSetting" :active="true">
|
||||
<x-system.select title="支付宝支付" code="is_AliPay"
|
||||
:list="['关闭' => '', 'F2F' => 'f2fpay', '码支付' => 'codepay', '易支付' => 'epay', '海狸支付' => 'paybeaver', '平头哥支付' => 'theadpay']"/>
|
||||
:list="['关闭' => '', 'F2F' => 'f2fpay', '码支付' => 'codepay', '易支付' => 'epay', '海狸支付' => 'paybeaver', '平头哥支付' => 'theadpay', '麻瓜宝' => 'bitpayx']"/>
|
||||
<x-system.select title="QQ钱包" code="is_QQPay" :list="['关闭' => '', '码支付' => 'codepay', '易支付' => 'epay']"/>
|
||||
<x-system.select title="微信支付" code="is_WeChatPay"
|
||||
:list="['关闭' => '', '码支付' => 'codepay', 'PayJS' => 'payjs', '易支付' => 'epay', '海狸支付' => 'paybeaver']"/>
|
||||
:list="['关闭' => '', '码支付' => 'codepay', 'PayJS' => 'payjs', '易支付' => 'epay', '海狸支付' => 'paybeaver', '麻瓜宝' => 'bitpayx']"/>
|
||||
<x-system.select title="特殊支付" code="is_otherPay" :list="['关闭' => '', '麻瓜宝' => 'bitpayx', 'PayPal' => 'paypal', 'Stripe' => 'stripe']"/>
|
||||
<x-system.input title="自定义商品名称" :value="$subject_name" code="subject_name" help="用于在支付渠道的商品标题显示"/>
|
||||
<x-system.input title="通用支付回调地址" :value="$website_callback_url" code="website_callback_url"
|
||||
|
||||
Reference in New Issue
Block a user