Skip to content

Commit

Permalink
Refactor payments
Browse files Browse the repository at this point in the history
  • Loading branch information
v2board committed Dec 22, 2023
1 parent 4f04eab commit 05075f3
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 44 deletions.
3 changes: 0 additions & 3 deletions app/Payments/AlipayF2F.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<?php

/**
* 自己写别抄,抄NMB抄
*/
namespace App\Payments;

class AlipayF2F {
Expand Down
59 changes: 29 additions & 30 deletions app/Payments/MGate.php → app/Payments/Smogate.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

/**
* 自己写别抄,抄NMB抄
* Telegram@smogate_bot
*/
namespace App\Payments;

use \Curl\Curl;

class MGate {
class Smogate {
private $config;

public function __construct($config)
Expand All @@ -18,25 +18,19 @@ public function __construct($config)
public function form()
{
return [
'mgate_url' => [
'label' => 'API地址',
'description' => '',
'type' => 'input',
],
'mgate_app_id' => [
'label' => 'APPID',
'description' => '',
'type' => 'input',
],
'mgate_app_secret' => [
'label' => 'AppSecret',
'description' => '',
'type' => 'input',
],
'mgate_source_currency' => [
'smogate_source_currency' => [
'label' => '源货币',
'description' => '默认CNY',
'type' => 'input'
],
'smogate_method' => [
'label' => '支付方式',
'description' => '支持参数:alipay',
'type' => 'input',
],
'alert1' => [
'type' => 'alert',
'content' => '开户请联系:@smogate'
]
];
}
Expand All @@ -47,19 +41,19 @@ public function pay($order)
'out_trade_no' => $order['trade_no'],
'total_amount' => $order['total_amount'],
'notify_url' => $order['notify_url'],
'return_url' => $order['return_url']
'method' => $this->config['smogate_method']
];
if (isset($this->config['mgate_source_currency'])) {
$params['source_currency'] = $this->config['mgate_source_currency'];
if (isset($this->config['smogate_source_currency'])) {
$params['source_currency'] = strtolower($this->config['smogate_source_currency']);
}
$params['app_id'] = $this->config['mgate_app_id'];
$params['app_id'] = "__APPID__";
ksort($params);
$str = http_build_query($params) . $this->config['mgate_app_secret'];
$str = http_build_query($params) . "__APPSECRET__";
$params['sign'] = md5($str);
$curl = new Curl();
$curl->setUserAgent('MGate');
$curl->setUserAgent("Smogate __APPID__");
$curl->setOpt(CURLOPT_SSL_VERIFYPEER, 0);
$curl->post($this->config['mgate_url'] . '/v1/gateway/fetch', http_build_query($params));
$curl->post("https://__APPID__.vless.org/v1/gateway/pay", http_build_query($params));
$result = $curl->response;
if (!$result) {
abort(500, '网络异常');
Expand All @@ -75,12 +69,12 @@ public function pay($order)
abort(500, '未知错误');
}
$curl->close();
if (!isset($result->data->trade_no)) {
abort(500, '接口请求失败');
if (!isset($result->data)) {
abort(500, '请求失败');
}
return [
'type' => 1, // 0:qrcode 1:url
'data' => $result->data->pay_url
'type' => $this->isMobile() ? 1 : 0, // 0:qrcode 1:url
'data' => $result->data
];
}

Expand All @@ -90,7 +84,7 @@ public function notify($params)
unset($params['sign']);
ksort($params);
reset($params);
$str = http_build_query($params) . $this->config['mgate_app_secret'];
$str = http_build_query($params) . "__APPSECRET__";
if ($sign !== md5($str)) {
return false;
}
Expand All @@ -99,4 +93,9 @@ public function notify($params)
'callback_no' => $params['trade_no']
];
}

private function isMobile()
{
return strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'mobile') !== false;
}
}
3 changes: 0 additions & 3 deletions app/Payments/StripeAlipay.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<?php

/**
* 自己写别抄,抄NMB抄
*/
namespace App\Payments;

use Stripe\Source;
Expand Down
3 changes: 0 additions & 3 deletions app/Payments/StripeCredit.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<?php

/**
* 自己写别抄,抄NMB抄
*/
namespace App\Payments;

use Stripe\Source;
Expand Down
3 changes: 0 additions & 3 deletions app/Payments/StripeWepay.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<?php

/**
* 自己写别抄,抄NMB抄
*/
namespace App\Payments;

use Stripe\Source;
Expand Down
4 changes: 2 additions & 2 deletions app/Utils/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public static function generateOrderNo(): string

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

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

0 comments on commit 05075f3

Please sign in to comment.