Skip to content

Commit 05075f3

Browse files
author
v2board
committed
Refactor payments
1 parent 4f04eab commit 05075f3

File tree

6 files changed

+31
-44
lines changed

6 files changed

+31
-44
lines changed

app/Payments/AlipayF2F.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
<?php
22

3-
/**
4-
* 自己写别抄,抄NMB抄
5-
*/
63
namespace App\Payments;
74

85
class AlipayF2F {
Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22

33
/**
4-
* 自己写别抄,抄NMB抄
4+
* Telegram@smogate_bot
55
*/
66
namespace App\Payments;
77

88
use \Curl\Curl;
99

10-
class MGate {
10+
class Smogate {
1111
private $config;
1212

1313
public function __construct($config)
@@ -18,25 +18,19 @@ public function __construct($config)
1818
public function form()
1919
{
2020
return [
21-
'mgate_url' => [
22-
'label' => 'API地址',
23-
'description' => '',
24-
'type' => 'input',
25-
],
26-
'mgate_app_id' => [
27-
'label' => 'APPID',
28-
'description' => '',
29-
'type' => 'input',
30-
],
31-
'mgate_app_secret' => [
32-
'label' => 'AppSecret',
33-
'description' => '',
34-
'type' => 'input',
35-
],
36-
'mgate_source_currency' => [
21+
'smogate_source_currency' => [
3722
'label' => '源货币',
3823
'description' => '默认CNY',
3924
'type' => 'input'
25+
],
26+
'smogate_method' => [
27+
'label' => '支付方式',
28+
'description' => '支持参数:alipay',
29+
'type' => 'input',
30+
],
31+
'alert1' => [
32+
'type' => 'alert',
33+
'content' => '开户请联系:@smogate'
4034
]
4135
];
4236
}
@@ -47,19 +41,19 @@ public function pay($order)
4741
'out_trade_no' => $order['trade_no'],
4842
'total_amount' => $order['total_amount'],
4943
'notify_url' => $order['notify_url'],
50-
'return_url' => $order['return_url']
44+
'method' => $this->config['smogate_method']
5145
];
52-
if (isset($this->config['mgate_source_currency'])) {
53-
$params['source_currency'] = $this->config['mgate_source_currency'];
46+
if (isset($this->config['smogate_source_currency'])) {
47+
$params['source_currency'] = strtolower($this->config['smogate_source_currency']);
5448
}
55-
$params['app_id'] = $this->config['mgate_app_id'];
49+
$params['app_id'] = "__APPID__";
5650
ksort($params);
57-
$str = http_build_query($params) . $this->config['mgate_app_secret'];
51+
$str = http_build_query($params) . "__APPSECRET__";
5852
$params['sign'] = md5($str);
5953
$curl = new Curl();
60-
$curl->setUserAgent('MGate');
54+
$curl->setUserAgent("Smogate __APPID__");
6155
$curl->setOpt(CURLOPT_SSL_VERIFYPEER, 0);
62-
$curl->post($this->config['mgate_url'] . '/v1/gateway/fetch', http_build_query($params));
56+
$curl->post("https://__APPID__.vless.org/v1/gateway/pay", http_build_query($params));
6357
$result = $curl->response;
6458
if (!$result) {
6559
abort(500, '网络异常');
@@ -75,12 +69,12 @@ public function pay($order)
7569
abort(500, '未知错误');
7670
}
7771
$curl->close();
78-
if (!isset($result->data->trade_no)) {
79-
abort(500, '接口请求失败');
72+
if (!isset($result->data)) {
73+
abort(500, '请求失败');
8074
}
8175
return [
82-
'type' => 1, // 0:qrcode 1:url
83-
'data' => $result->data->pay_url
76+
'type' => $this->isMobile() ? 1 : 0, // 0:qrcode 1:url
77+
'data' => $result->data
8478
];
8579
}
8680

@@ -90,7 +84,7 @@ public function notify($params)
9084
unset($params['sign']);
9185
ksort($params);
9286
reset($params);
93-
$str = http_build_query($params) . $this->config['mgate_app_secret'];
87+
$str = http_build_query($params) . "__APPSECRET__";
9488
if ($sign !== md5($str)) {
9589
return false;
9690
}
@@ -99,4 +93,9 @@ public function notify($params)
9993
'callback_no' => $params['trade_no']
10094
];
10195
}
96+
97+
private function isMobile()
98+
{
99+
return strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'mobile') !== false;
100+
}
102101
}

app/Payments/StripeAlipay.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
<?php
22

3-
/**
4-
* 自己写别抄,抄NMB抄
5-
*/
63
namespace App\Payments;
74

85
use Stripe\Source;

app/Payments/StripeCredit.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
<?php
22

3-
/**
4-
* 自己写别抄,抄NMB抄
5-
*/
63
namespace App\Payments;
74

85
use Stripe\Source;

app/Payments/StripeWepay.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
<?php
22

3-
/**
4-
* 自己写别抄,抄NMB抄
5-
*/
63
namespace App\Payments;
74

85
use Stripe\Source;

app/Utils/Helper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ public static function generateOrderNo(): string
3636

3737
public static function exchange($from, $to)
3838
{
39-
$result = file_get_contents('https://api.exchangerate.host/latest?symbols=' . $to . '&base=' . $from);
39+
$result = file_get_contents("https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies/" . $from . "/" . $to . ".json");
4040
$result = json_decode($result, true);
41-
return $result['rates'][$to];
41+
return $result[$to];
4242
}
4343

4444
public static function randomChar($len, $special = false)

0 commit comments

Comments
 (0)