1
1
<?php
2
2
3
3
/**
4
- * 自己写别抄,抄NMB抄
4
+ * Telegram@smogate_bot
5
5
*/
6
6
namespace App \Payments ;
7
7
8
8
use \Curl \Curl ;
9
9
10
- class MGate {
10
+ class Smogate {
11
11
private $ config ;
12
12
13
13
public function __construct ($ config )
@@ -18,25 +18,19 @@ public function __construct($config)
18
18
public function form ()
19
19
{
20
20
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 ' => [
37
22
'label ' => '源货币 ' ,
38
23
'description ' => '默认CNY ' ,
39
24
'type ' => 'input '
25
+ ],
26
+ 'smogate_method ' => [
27
+ 'label ' => '支付方式 ' ,
28
+ 'description ' => '支持参数:alipay ' ,
29
+ 'type ' => 'input ' ,
30
+ ],
31
+ 'alert1 ' => [
32
+ 'type ' => 'alert ' ,
33
+ 'content ' => '开户请联系:@smogate '
40
34
]
41
35
];
42
36
}
@@ -47,19 +41,19 @@ public function pay($order)
47
41
'out_trade_no ' => $ order ['trade_no ' ],
48
42
'total_amount ' => $ order ['total_amount ' ],
49
43
'notify_url ' => $ order ['notify_url ' ],
50
- 'return_url ' => $ order [ ' return_url ' ]
44
+ 'method ' => $ this -> config [ ' smogate_method ' ]
51
45
];
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 ' ]) ;
54
48
}
55
- $ params ['app_id ' ] = $ this -> config [ ' mgate_app_id ' ] ;
49
+ $ params ['app_id ' ] = " __APPID__ " ;
56
50
ksort ($ params );
57
- $ str = http_build_query ($ params ) . $ this -> config [ ' mgate_app_secret ' ] ;
51
+ $ str = http_build_query ($ params ) . " __APPSECRET__ " ;
58
52
$ params ['sign ' ] = md5 ($ str );
59
53
$ curl = new Curl ();
60
- $ curl ->setUserAgent (' MGate ' );
54
+ $ curl ->setUserAgent (" Smogate __APPID__ " );
61
55
$ 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 ));
63
57
$ result = $ curl ->response ;
64
58
if (!$ result ) {
65
59
abort (500 , '网络异常 ' );
@@ -75,12 +69,12 @@ public function pay($order)
75
69
abort (500 , '未知错误 ' );
76
70
}
77
71
$ curl ->close ();
78
- if (!isset ($ result ->data -> trade_no )) {
79
- abort (500 , '接口请求失败 ' );
72
+ if (!isset ($ result ->data )) {
73
+ abort (500 , '请求失败 ' );
80
74
}
81
75
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
84
78
];
85
79
}
86
80
@@ -90,7 +84,7 @@ public function notify($params)
90
84
unset($ params ['sign ' ]);
91
85
ksort ($ params );
92
86
reset ($ params );
93
- $ str = http_build_query ($ params ) . $ this -> config [ ' mgate_app_secret ' ] ;
87
+ $ str = http_build_query ($ params ) . " __APPSECRET__ " ;
94
88
if ($ sign !== md5 ($ str )) {
95
89
return false ;
96
90
}
@@ -99,4 +93,9 @@ public function notify($params)
99
93
'callback_no ' => $ params ['trade_no ' ]
100
94
];
101
95
}
96
+
97
+ private function isMobile ()
98
+ {
99
+ return strpos (strtolower ($ _SERVER ['HTTP_USER_AGENT ' ]), 'mobile ' ) !== false ;
100
+ }
102
101
}
0 commit comments