Browse Source

修复 Trojan Webapi & GuzzleHttp 替换 Curl

兔姬桑 4 years ago
parent
commit
2cb4e4f9d6

+ 0 - 30
app/Components/Curl.php

@@ -1,30 +0,0 @@
-<?php
-
-namespace App\Components;
-
-class Curl {
-	/**
-	 * @param  string  $url   请求地址
-	 * @param  array   $data  数据,如果有数据则用POST请求
-	 *
-	 * @return mixed
-	 */
-	public static function send($url, $data = []) {
-		$ch = curl_init();
-		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-		curl_setopt($ch, CURLOPT_TIMEOUT, 60);
-		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
-		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
-		curl_setopt($ch, CURLOPT_URL, $url);
-
-		if($data){
-			curl_setopt($ch, CURLOPT_POST, 1);
-			curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
-		}
-
-		$result = curl_exec($ch);
-		curl_close($ch);
-
-		return $result;
-	}
-}

+ 1 - 1
app/Components/IPIP.php

@@ -13,7 +13,7 @@ class IPIP {
 	 * @return array|null
 	 * @return array|null
 	 */
 	 */
 	public static function ip($ip): ?array {
 	public static function ip($ip): ?array {
-		$filePath = public_path('ipip.ipdb');
+		$filePath = database_path('ipip.ipdb');
 		$loc = new City($filePath);
 		$loc = new City($filePath);
 
 
 		return $loc->findMap($ip, 'CN');
 		return $loc->findMap($ip, 'CN');

+ 20 - 18
app/Components/Namesilo.php

@@ -2,7 +2,7 @@
 
 
 namespace App\Components;
 namespace App\Components;
 
 
-use Exception;
+use GuzzleHttp\Client;
 use Log;
 use Log;
 use LSS\XML2Array;
 use LSS\XML2Array;
 
 
@@ -10,6 +10,7 @@ class Namesilo {
 	protected static $host;
 	protected static $host;
 	protected static $systemConfig;
 	protected static $systemConfig;
 
 
+	// Todo Debug测试
 	public function __construct() {
 	public function __construct() {
 		self::$host = 'https://www.namesilo.com/api/';
 		self::$host = 'https://www.namesilo.com/api/';
 		self::$systemConfig = Helpers::systemConfig();
 		self::$systemConfig = Helpers::systemConfig();
@@ -31,27 +32,28 @@ class Namesilo {
 
 
 		$content = '请求操作:['.$operation.'] --- 请求数据:['.http_build_query($query).']';
 		$content = '请求操作:['.$operation.'] --- 请求数据:['.http_build_query($query).']';
 
 
-		try{
-			$result = Curl::send(self::$host.$operation.'?'.http_build_query($query));
-			$result = XML2Array::createArray($result);
-
-			// 出错
-			if(empty($result['namesilo']) || $result['namesilo']['reply']['code'] != 300 || $result['namesilo']['reply']['detail'] !== 'success'){
-				Helpers::addNotificationLog('[Namesilo API] - ['.$operation.']', $content, 1,
-					self::$systemConfig['webmaster_email'], 0, $result['namesilo']['reply']['detail']);
-			}else{
-				Helpers::addNotificationLog('[Namesilo API] - ['.$operation.']', $content, 1,
-					self::$systemConfig['webmaster_email'], 1, $result['namesilo']['reply']['detail']);
-			}
-
-			return $result['namesilo']['reply'];
-		}catch(Exception $e){
-			Log::error('CURL请求失败:'.$e->getMessage().' --- '.$e->getLine());
+		$client = new Client(['timeout' => 10]);
+		$request = $client->get(self::$host.$operation.'?'.http_build_query($query));
+		$result = XML2Array::createArray(json_decode($request->getBody(), true));
+
+		if($request->getStatusCode() != 200){
+			Log::error('请求失败:'.var_export($request, true));
 			Helpers::addNotificationLog('[Namesilo API] - ['.$operation.']', $content, 1,
 			Helpers::addNotificationLog('[Namesilo API] - ['.$operation.']', $content, 1,
-				self::$systemConfig['webmaster_email'], 0, $e->getMessage());
+				self::$systemConfig['webmaster_email'], 0, var_export($request, true));
 
 
 			return false;
 			return false;
 		}
 		}
+
+		// 出错
+		if(empty($result['namesilo']) || $result['namesilo']['reply']['code'] != 300 || $result['namesilo']['reply']['detail'] !== 'success'){
+			Helpers::addNotificationLog('[Namesilo API] - ['.$operation.']', $content, 1,
+				self::$systemConfig['webmaster_email'], 0, $result['namesilo']['reply']['detail']);
+		}else{
+			Helpers::addNotificationLog('[Namesilo API] - ['.$operation.']', $content, 1,
+				self::$systemConfig['webmaster_email'], 1, $result['namesilo']['reply']['detail']);
+		}
+
+		return $result['namesilo']['reply'];
 	}
 	}
 
 
 	// 列出指定域名的所有DNS记录
 	// 列出指定域名的所有DNS记录

+ 35 - 41
app/Components/NetworkDetection.php

@@ -2,7 +2,7 @@
 
 
 namespace App\Components;
 namespace App\Components;
 
 
-use Exception;
+use GuzzleHttp\Client;
 use Log;
 use Log;
 
 
 class NetworkDetection {
 class NetworkDetection {
@@ -18,75 +18,69 @@ class NetworkDetection {
 	public static function networkCheck($ip, $type, $port = null) {
 	public static function networkCheck($ip, $type, $port = null) {
 		$url = 'https://api.50network.com/china-firewall/check/ip/'.($type? 'icmp/' : ($port? 'tcp_port/' : 'tcp_ack/')).$ip.($port? '/'.$port : '');
 		$url = 'https://api.50network.com/china-firewall/check/ip/'.($type? 'icmp/' : ($port? 'tcp_port/' : 'tcp_ack/')).$ip.($port? '/'.$port : '');
 		$checkName = $type? 'ICMP' : 'TCP';
 		$checkName = $type? 'ICMP' : 'TCP';
+		$client = new Client(['timeout' => 10]);
+		$request = $client->get($url);
+		$result = json_decode($request->getBody(), true);
 
 
-		try{
-			$ret = json_decode(Curl::send($url), true);
-			if(!$ret){
+		if($request->getStatusCode() == 200){
+			if(!$result){
 				Log::warning("【".$checkName."阻断检测】检测".$ip."时,接口返回异常访问链接:".$url);
 				Log::warning("【".$checkName."阻断检测】检测".$ip."时,接口返回异常访问链接:".$url);
 
 
 				return false;
 				return false;
 			}
 			}
 
 
-			if(!$ret['success']){
-				if($ret['error'] === "execute timeout (3s)"){
+			if(!$result['success']){
+				if($result['error'] === "execute timeout (3s)"){
 					sleep(10);
 					sleep(10);
 
 
 					return self::networkCheck($ip, $type, $port);
 					return self::networkCheck($ip, $type, $port);
 				}
 				}
 
 
-				Log::warning("【".$checkName."阻断检测】检测".$ip.($port?: '')."时,返回".json_encode($ret));
+				Log::warning("【".$checkName."阻断检测】检测".$ip.($port?: '')."时,返回".var_export($result, true));
 				return false;
 				return false;
 			}
 			}
-		}catch(Exception $e){
-			Log::warning("【".$checkName."阻断检测】检测".$ip."时,接口请求超时".$e);
 
 
-			return false;
-		}
+			if($result['firewall-enable'] && $result['firewall-disable']){
+				return "通讯正常"; // 正常
+			}
 
 
-		if($ret['firewall-enable'] && $ret['firewall-disable']){
-			return "通讯正常"; // 正
-		}
+			if($result['firewall-enable'] && !$result['firewall-disable']){
+				return "海外阻断"; // 国外访问异
+			}
 
 
-		if($ret['firewall-enable'] && !$ret['firewall-disable']){
-			return "海外阻断"; // 国外访问异常
-		}
+			if(!$result['firewall-enable'] && $result['firewall-disable']){
+				return "国内阻断"; // 被墙
+			}
 
 
-		if(!$ret['firewall-enable'] && $ret['firewall-disable']){
-			return "国内阻断"; // 被墙
+			return "机器宕机"; // 服务器宕机
 		}
 		}
-
-		return "机器宕机"; // 服务器宕机
+		return false;
 	}
 	}
 
 
 	/**
 	/**
-	 * 用api.iiwl.cc进行Ping检测
+	 * 用外部API进行Ping检测
 	 *
 	 *
 	 * @param  string  $ip  被检测的IP或者域名
 	 * @param  string  $ip  被检测的IP或者域名
 	 *
 	 *
 	 * @return bool|array
 	 * @return bool|array
 	 */
 	 */
 	public static function ping($ip) {
 	public static function ping($ip) {
-		$url = 'https://api.iiwl.cc/api/ping.php?host='.$ip;
-
-		try{
-			$ret = json_decode(Curl::send($url), true);
-			if(!$ret){
-				Log::warning("【PING】检测".$ip."时,接口返回异常访问链接:".$url);
-
-				return false;
-			}
-
-			if($ret['code'] != 1 || $ret['msg'] !== "检测成功!"){
-				Log::warning("【PING】检测".$ip."时,返回".json_encode($ret));
-
-				return false;
+		$url = 'https://api.oioweb.cn/api/hostping.php?host='.$ip;//https://api.iiwl.cc/api/ping.php?host=
+		$client = new Client(['timeout' => 20]);
+		$request = $client->get($url);
+		$message = json_decode($client->get($url)->getBody(), true);
+
+		// 发送成功
+		if($request->getStatusCode() == 200){
+			if($message && $message['code']){
+				return $message['data'];
 			}
 			}
-		}catch(Exception $e){
-			Log::warning("【Ping】检测".$ip."时,接口请求超时".$e);
-
+			// 发送失败
+			Log::warning("【PING】检测".$ip."时,返回".var_export($message, true));
 			return false;
 			return false;
 		}
 		}
-
-		return $ret['data']; // 服务器宕机
+		Log::warning("【PING】检测".$ip."时,接口返回异常访问链接:".$url);
+		// 发送错误
+		return false;
 	}
 	}
 }
 }

+ 31 - 35
app/Components/PushNotification.php

@@ -3,9 +3,8 @@
 
 
 namespace App\Components;
 namespace App\Components;
 
 
-use Exception;
+use GuzzleHttp\Client;
 use Log;
 use Log;
-use stdClass;
 
 
 class PushNotification {
 class PushNotification {
 	public static function send($title, $content) {
 	public static function send($title, $content) {
@@ -30,27 +29,24 @@ class PushNotification {
 	 * @return mixed
 	 * @return mixed
 	 */
 	 */
 	private static function ServerChan($title, $content) {
 	private static function ServerChan($title, $content) {
-		$ret = false;
-		try{
-			// TODO:一天仅可发送不超过500条
-			$url = 'https://sc.ftqq.com/'.Helpers::systemConfig()['server_chan_key'].'.send?text='.$title.'&desp='.urlencode($content);
-			$result = json_decode(Curl::send($url), true);
-			if(empty(Helpers::systemConfig()['server_chan_key'])){
-				$result = new stdClass();
-				$result->errno = true;
-				$result->errmsg = "未正确配置ServerChan";
-			}
-			if($result != null && !$result->errno){
+		// TODO:一天仅可发送不超过500条
+		$client = new Client(['timeout' => 5]);
+		$request = $client->get('https://sc.ftqq.com/'.Helpers::systemConfig()['server_chan_key'].'.send?text='.$title.'&desp='.urlencode($content));
+		$message = json_decode($request->getBody(), true);
+		Log::debug($message);
+		// 发送成功
+		if($request->getStatusCode() == 200){
+			if(!$message['errno']){
 				Helpers::addNotificationLog($title, $content, 2);
 				Helpers::addNotificationLog($title, $content, 2);
-				$ret = true;
-			}else{
-				Helpers::addNotificationLog($title, $content, 2, 'admin', 1, $result? $result->errmsg : '未知');
+				return $message;
 			}
 			}
-		}catch(Exception $e){
-			Log::error('ServerChan消息推送异常:'.$e);
+			// 发送失败
+			Helpers::addNotificationLog($title, $content, 2, 'admin', -1, $message? $message['errmsg'] : '未知');
+			return false;
 		}
 		}
-
-		return $ret;
+		// 发送错误
+		Log::debug('ServerChan消息推送异常:'.var_export($request, true));
+		return false;
 	}
 	}
 
 
 	/**
 	/**
@@ -62,22 +58,22 @@ class PushNotification {
 	 * @return mixed
 	 * @return mixed
 	 */
 	 */
 	private static function Bark($title, $content) {
 	private static function Bark($title, $content) {
-		$ret = false;
-		try{
-			$url = 'https://api.day.app/'.Helpers::systemConfig()['bark_key'].'/'.$title.'/'.$content;
-			$result = json_decode(Curl::send($url), true);
-			if($result){
-				if($result->code == 200){
-					Helpers::addNotificationLog($title, $content, 3);
-					$ret = true;
-				}else{
-					Helpers::addNotificationLog($title, $content, 3, 'admin', $result->message);
-				}
+		$client = new Client(['timeout' => 5]);
+		$request = $client->get('https://api.day.app/'.Helpers::systemConfig()['bark_key'].'/'.$title.'/'.$content);
+		$message = json_decode($request->getBody(), true);
+
+		if($request->getStatusCode() == 200){
+			// 发送成功
+			if($message['code'] == 200){
+				Helpers::addNotificationLog($title, $content, 3);
+				return $message;
 			}
 			}
-		}catch(Exception $e){
-			Log::error('Bark消息推送异常:'.$e);
+			// 发送失败
+			Helpers::addNotificationLog($title, $content, 3, 'admin', -1, $message);
+			return false;
 		}
 		}
-
-		return $ret;
+		// 发送错误
+		Log::debug('Bark消息推送异常:'.var_export($request, true));
+		return false;
 	}
 	}
 }
 }

+ 30 - 33
app/Components/QQInfo.php

@@ -2,59 +2,56 @@
 
 
 namespace App\Components;
 namespace App\Components;
 
 
-class QQInfo {
-	/**
-	 * 通过QQ号查询头像与昵称信息
-	 *
-	 * @param  string  $qq  QQ号
-	 *
-	 * @return string
-	 */
-	public static function getName($qq) {
+use GuzzleHttp\Client;
 
 
+class QQInfo {
+	public static function getName(string $qq): string {
 		//向接口发起请求获取json数据
 		//向接口发起请求获取json数据
 		$url = 'https://r.qzone.qq.com/fcg-bin/cgi_get_portrait.fcg?get_nick=1&uins='.$qq;
 		$url = 'https://r.qzone.qq.com/fcg-bin/cgi_get_portrait.fcg?get_nick=1&uins='.$qq;
-		$ret = mb_convert_encoding(Curl::send($url), "UTF-8", "GBK");
+		$client = new Client(['timeout' => 10]);
+		$request = $client->get($url);
+		$message = mb_convert_encoding($request->getBody(), "UTF-8", "GBK");
+
 		// 接口是否异常
 		// 接口是否异常
-		//echo $ret;
-		if(strpos($ret, $qq) !== false){
-			//对获取的json数据进行截取并解析成数组
-			$ret = json_decode(substr($ret, 17, -1), true);
+		if($request->getStatusCode() == 200){
+			if(strpos($message, $qq) !== false){
+				//对获取的json数据进行截取并解析成数组
+				$message = json_decode(substr($message, 17, -1), true);
 
 
-			return stripslashes($ret[$qq][6]);
+				return stripslashes($message[$qq][6]);
+			}
 		}
 		}
 
 
-		echo $qq.PHP_EOL;
-
-		return false;
+		return $qq;
 	}
 	}
 
 
-	public static function getName2($qq) {
-
+	public static function getName2(string $qq): string {
 		//向接口发起请求获取json数据
 		//向接口发起请求获取json数据
 		$url = 'https://api.toubiec.cn/qq?qq='.$qq.'&size=100';
 		$url = 'https://api.toubiec.cn/qq?qq='.$qq.'&size=100';
-		$ret = json_decode(Curl::send($url), true);
+		$client = new Client(['timeout' => 10]);
+		$request = $client->get($url);
+		$message = json_decode($request->getBody(), true);
+
 		// 接口是否异常
 		// 接口是否异常
-		if($ret && $ret['code'] == 200){
-			return $ret['name'];
+		if($request->getStatusCode() == 200 && $message && $message['code'] == 200){
+			return $message['name'];
 		}
 		}
 
 
-		echo $qq.PHP_EOL;
-
-		return false;
+		return $qq;
 	}
 	}
 
 
-	public static function getName3($qq) {
+	public static function getName3(string $qq): string {
 		//向接口发起请求获取json数据
 		//向接口发起请求获取json数据
 		$url = 'https://api.unipay.qq.com/v1/r/1450000186/wechat_query?cmd=1&pf=mds_storeopen_qb-__mds_qqclub_tab_-html5&pfkey=pfkey&from_h5=1&from_https=1&openid=openid&openkey=openkey&session_id=hy_gameid&session_type=st_dummy&qq_appid=&offerId=1450000186&sandbox=&provide_uin='.$qq;
 		$url = 'https://api.unipay.qq.com/v1/r/1450000186/wechat_query?cmd=1&pf=mds_storeopen_qb-__mds_qqclub_tab_-html5&pfkey=pfkey&from_h5=1&from_https=1&openid=openid&openkey=openkey&session_id=hy_gameid&session_type=st_dummy&qq_appid=&offerId=1450000186&sandbox=&provide_uin='.$qq;
-		$ret = json_decode(Curl::send($url), true);
+		$client = new Client(['timeout' => 10]);
+		$request = $client->get($url);
+		$message = json_decode($request->getBody(), true);
+
 		// 接口是否异常
 		// 接口是否异常
-		if($ret && $ret['ret'] == 0){
-			return urldecode($ret['nick']);
+		if($request->getStatusCode() == 200 && $message && $message['ret'] == 0){
+			return urldecode($message['nick']);
 		}
 		}
 
 
-		echo $qq.PHP_EOL;
-
-		return false;
+		return $qq;
 	}
 	}
 }
 }

+ 1 - 1
app/Components/QQWry.php

@@ -13,7 +13,7 @@ class QQWry {
 	 * @return array
 	 * @return array
 	 */
 	 */
 	public static function ip($ip): array {
 	public static function ip($ip): array {
-		$filePath = public_path('qqwry.dat');
+		$filePath = database_path('qqwry.dat');
 
 
 		return IpLocation::getLocation($ip, $filePath);
 		return IpLocation::getLocation($ip, $filePath);
 	}
 	}

+ 4 - 4
app/Console/Commands/AutoPingNode.php

@@ -33,10 +33,10 @@ class AutoPingNode extends Command {
 		if($result){
 		if($result){
 			$obj = new SsNodePing();
 			$obj = new SsNodePing();
 			$obj->node_id = $nodeId;
 			$obj->node_id = $nodeId;
-			$obj->ct = intval($result['China Telecom']['time']);
-			$obj->cu = intval($result['China Unicom']['time']);
-			$obj->cm = intval($result['China Mobile']['time']);
-			$obj->hk = intval($result['Hong Kong']['time']);
+			$obj->ct = intval($result['telecom']['time']);//电信
+			$obj->cu = intval($result['Unicom']['time']);// 联通
+			$obj->cm = intval($result['move']['time']);// 移动
+			$obj->hk = intval($result['HongKong']['time']);// 香港
 			$obj->save();
 			$obj->save();
 		}else{
 		}else{
 			Log::info("【".$ip."】Ping测速获取失败");
 			Log::info("【".$ip."】Ping测速获取失败");

+ 2 - 6
app/Http/Controllers/Api/WebApi/TrojanController.php

@@ -34,16 +34,12 @@ class TrojanController extends BaseController {
 		foreach($users as $user){
 		foreach($users as $user){
 			$new = [
 			$new = [
 				'uid'         => $user->id,
 				'uid'         => $user->id,
-				'password'    => str_replace('-', '', $user->vmess_id),
+				'password'    => $user->passwd,
 				'speed_limit' => $user->speed_limit
 				'speed_limit' => $user->speed_limit
 			];
 			];
 			$data[] = $new;
 			$data[] = $new;
 		}
 		}
 
 
-		if($data){
-			return $this->returnData('获取用户列表成功', 'success', 200, $data, ['updateTime' => time()]);
-		}
-
-		return $this->returnData('获取用户列表失败');
+		return $this->returnData('获取用户列表成功', 'success', 200, $data, ['updateTime' => time()]);
 	}
 	}
 }
 }

+ 1 - 1
app/Http/Controllers/Gateway/AbstractPayment.php

@@ -160,7 +160,7 @@ abstract class AbstractPayment {
 
 
 	protected function creatNewPayment($uid, $oid, $amount): Payment {
 	protected function creatNewPayment($uid, $oid, $amount): Payment {
 		$payment = new Payment();
 		$payment = new Payment();
-		$payment->trade_no = substr(str_replace('-', '', Str::uuid()), 0, 8);
+		$payment->trade_no = makeRandStr(8);
 		$payment->user_id = $uid;
 		$payment->user_id = $uid;
 		$payment->oid = $oid;
 		$payment->oid = $oid;
 		$payment->amount = $amount;
 		$payment->amount = $amount;

+ 3 - 5
app/Http/Controllers/Gateway/BitpayX.php

@@ -10,8 +10,6 @@ use Log;
 use Response;
 use Response;
 
 
 class BitpayX extends AbstractPayment {
 class BitpayX extends AbstractPayment {
-	private $bitpayGatewayUrl = 'https://api.mugglepay.com/v1/';
-
 	public function purchase($request): JsonResponse {
 	public function purchase($request): JsonResponse {
 		$payment = $this->creatNewPayment(Auth::id(), $request->input('oid'), $request->input('amount'));
 		$payment = $this->creatNewPayment(Auth::id(), $request->input('oid'), $request->input('amount'));
 
 
@@ -26,7 +24,6 @@ class BitpayX extends AbstractPayment {
 			'success_url'       => parent::$systemConfig['website_url'].'/invoices',
 			'success_url'       => parent::$systemConfig['website_url'].'/invoices',
 			'cancel_url'        => parent::$systemConfig['website_url'],
 			'cancel_url'        => parent::$systemConfig['website_url'],
 			'token'             => $this->sign($this->prepareSignId($payment->trade_no)),
 			'token'             => $this->sign($this->prepareSignId($payment->trade_no)),
-
 		];
 		];
 
 
 		$result = json_decode($this->mprequest($data), true);
 		$result = json_decode($this->mprequest($data), true);
@@ -55,12 +52,13 @@ class BitpayX extends AbstractPayment {
 			'secret'            => parent::$systemConfig['bitpay_secret'],
 			'secret'            => parent::$systemConfig['bitpay_secret'],
 			'type'              => 'FIAT'
 			'type'              => 'FIAT'
 		];
 		];
+		ksort($data_sign);
 
 
-		return http_build_query(ksort($data_sign));
+		return http_build_query($data_sign);
 	}
 	}
 
 
 	private function mprequest($data, $type = 'pay') {
 	private function mprequest($data, $type = 'pay') {
-		$client = new Client(['base_uri' => $this->bitpayGatewayUrl, 'timeout' => 10]);
+		$client = new Client(['base_uri' => 'https://api.mugglepay.com/v1/', 'timeout' => 10]);
 
 
 		if($type === 'query'){
 		if($type === 'query'){
 			$request = $client->get('orders/merchant_order_id/status?id='.$data['merchant_order_id'],
 			$request = $client->get('orders/merchant_order_id/status?id='.$data['merchant_order_id'],

+ 27 - 14
app/Http/Controllers/Gateway/EPay.php

@@ -27,7 +27,6 @@ class EPay extends AbstractPayment {
 				break;
 				break;
 		}
 		}
 
 
-
 		$data = [
 		$data = [
 			'pid'          => self::$systemConfig['epay_mch_id'],
 			'pid'          => self::$systemConfig['epay_mch_id'],
 			'type'         => $type,
 			'type'         => $type,
@@ -36,7 +35,7 @@ class EPay extends AbstractPayment {
 			'return_url'   => self::$systemConfig['website_url'].'/invoices',
 			'return_url'   => self::$systemConfig['website_url'].'/invoices',
 			'name'         => self::$systemConfig['subject_name']?: self::$systemConfig['website_name'],
 			'name'         => self::$systemConfig['subject_name']?: self::$systemConfig['website_name'],
 			'money'        => $payment->amount,
 			'money'        => $payment->amount,
-
+			'sign_type'    => 'MD5'
 		];
 		];
 		$data['sign'] = $this->sign($this->prepareSign($data));
 		$data['sign'] = $this->sign($this->prepareSign($data));
 
 
@@ -59,26 +58,40 @@ class EPay extends AbstractPayment {
 
 
 	// 签名字符串
 	// 签名字符串
 	private function sign($data): string {
 	private function sign($data): string {
-		return strtolower(md5($data.self::$systemConfig['epay_key']));
-	}
-
-	private function prepareSign($data): string {
+		unset($data['sign'], $data['sign_type']);
+		array_filter($data);
 		ksort($data);
 		ksort($data);
-		return http_build_query($data);
+		reset($data);
+
+		return md5(urldecode(http_build_query($data).self::$systemConfig['epay_key']));
 	}
 	}
 
 
 	public function notify(Request $request): void {
 	public function notify(Request $request): void {
-
-		if(!$this->verify($request->all(), $request->input('sign'))){
-			die('FAIL');
+		if($this->verify($request->except('method'), $request->input('sign'))
+		   && $request->input('trade_status') == 'TRADE_SUCCESS'){
+			$this->postPayment($request->input('out_trade_no'), 'EPay');
+			die('SUCCESS');
 		}
 		}
-		$this->postPayment($request->input('out_trade_no'), 'EPay');
-		die('SUCCESS');
+		die('FAIL');
 	}
 	}
 
 
 	// 验证签名
 	// 验证签名
 	private function verify($data, $signature): bool {
 	private function verify($data, $signature): bool {
-		unset($data['sign']);
-		return $this->sign($this->prepareSign($data)) === $signature;
+		return $this->sign($data) === $signature;
+	}
+
+	public function queryInfo(): JsonResponse {
+		$request = self::$client->get('api.php', [
+			'query' => [
+				'act' => 'query',
+				'pid' => self::$systemConfig['epay_mch_id'],
+				'key' => self::$systemConfig['epay_key']
+			]
+		]);
+		if($request->getStatusCode() == 200){
+			return Response::json(['status' => 'success', 'data' => json_decode($request->getBody(), true)]);
+		}
+
+		return Response::json(['status' => 'fail', 'message' => '获取失败!请检查配置信息']);
 	}
 	}
 }
 }

+ 1 - 1
app/helpers.php

@@ -19,7 +19,7 @@ if(!function_exists('makeRandStr')){
 	function makeRandStr($length = 6, $isNumbers = false) {
 	function makeRandStr($length = 6, $isNumbers = false) {
 		// 密码字符集,可任意添加你需要的字符
 		// 密码字符集,可任意添加你需要的字符
 		if(!$isNumbers){
 		if(!$isNumbers){
-			$chars = 'abcdefghijkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789';
+			$chars = 'abcdefghijkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ0123456789';
 		}else{
 		}else{
 			$chars = '0123456789';
 			$chars = '0123456789';
 		}
 		}

+ 17 - 2
resources/views/admin/config/system.blade.php

@@ -1282,13 +1282,14 @@
 										<div class="row">
 										<div class="row">
 											<label class="col-md-3 col-form-label">易支付</label>
 											<label class="col-md-3 col-form-label">易支付</label>
 											<div class="col-md-7">
 											<div class="col-md-7">
+												<button class="btn btn-primary" type="button" onclick="epayInfo()">咨询查询</button>
 												{{--												请到 <a href="https://codepay.fateqq.com/i/377289" target="_blank">码支付</a>申请账号,然后下载登录其挂机软件--}}
 												{{--												请到 <a href="https://codepay.fateqq.com/i/377289" target="_blank">码支付</a>申请账号,然后下载登录其挂机软件--}}
 											</div>
 											</div>
 										</div>
 										</div>
 									</div>
 									</div>
 									<div class="form-group col-lg-6">
 									<div class="form-group col-lg-6">
 										<div class="row">
 										<div class="row">
-											<label class="col-md-3 col-form-label" for="epay_url">请求URL</label>
+											<label class="col-md-3 col-form-label" for="epay_url">接口对接地址</label>
 											<div class="col-md-7">
 											<div class="col-md-7">
 												<div class="input-group">
 												<div class="input-group">
 													<input type="text" class="form-control" id="epay_url" value="{{$epay_url}}" placeholder="https://www.example.com"/>
 													<input type="text" class="form-control" id="epay_url" value="{{$epay_url}}" placeholder="https://www.example.com"/>
@@ -1314,7 +1315,7 @@
 									</div>
 									</div>
 									<div class="form-group col-lg-6">
 									<div class="form-group col-lg-6">
 										<div class="row">
 										<div class="row">
-											<label class="col-md-3 col-form-label" for="epay_key">商户签名</label>
+											<label class="col-md-3 col-form-label" for="epay_key">商户密钥</label>
 											<div class="col-md-7">
 											<div class="col-md-7">
 												<div class="input-group">
 												<div class="input-group">
 													<input type="text" class="form-control" id="epay_key" value="{{$epay_key}}"/>
 													<input type="text" class="form-control" id="epay_key" value="{{$epay_key}}"/>
@@ -1563,5 +1564,19 @@
 				$("#website_security_code").val(ret);
 				$("#website_security_code").val(ret);
 			});
 			});
 		}
 		}
+
+		function epayInfo() {
+			$.get("/admin/epayInfo", function (ret) {
+				if (ret.status === 'success') {
+					swal.fire({
+						title: '易支付信息(仅供参考)',
+						html: '商户状态: ' + ret.data["active"] + ' | 账号余额: ' + ret.data["money"] + ' | 结算账号:' + ret.data["account"]+'<br\><br\>渠道手续费:【支付宝 - ' + (100 - ret.data["alirate"]) + '% | 微信 - ' + (100 - ret.data["wxrate"]) + '% | QQ钱包 - ' + (100 - ret.data["qqrate"]) + '%】<br\><br\> 请按照支付平台的介绍为准,本信息纯粹为Api获取信息',
+						type: 'info'
+					});
+				} else {
+					swal.fire({title: ret.message, type: 'error'});
+				}
+			});
+		}
 	</script>
 	</script>
 @endsection
 @endsection

+ 1 - 1
resources/views/admin/node/authList.blade.php

@@ -144,7 +144,7 @@
 									<div class="text-center red-700 mb-5">Trojan-Poseidon</div>
 									<div class="text-center red-700 mb-5">Trojan-Poseidon</div>
 									(yum install curl 2> /dev/null || apt install curl 2> /dev/null) \<br>
 									(yum install curl 2> /dev/null || apt install curl 2> /dev/null) \<br>
 									&& curl -L -s https://bit.ly/33UdELu \<br>
 									&& curl -L -s https://bit.ly/33UdELu \<br>
-									| WEB_API="{{\App\Components\Helpers::systemConfig()['v2ray_license'] ?: \App\Components\Helpers::systemConfig()['website_url']}}" \<br>
+									| WEB_API="{{\App\Components\Helpers::systemConfig()['web_api_url'] ?: \App\Components\Helpers::systemConfig()['website_url']}}" \<br>
 									NODE_ID={{$vl->node->id}} \<br>
 									NODE_ID={{$vl->node->id}} \<br>
 									NODE_KEY={{$vl->key}} \<br>
 									NODE_KEY={{$vl->key}} \<br>
 									NODE_HOST={{$vl->node->server}} \<br>
 									NODE_HOST={{$vl->node->server}} \<br>

+ 2 - 1
routes/web.php

@@ -67,6 +67,7 @@ Route::group(['middleware' => ['isForbidden', 'isAdminLogin', 'isAdmin']], funct
 		Route::post('sendTestNotification', 'AdminController@sendTestNotification'); //推送通知测试
 		Route::post('sendTestNotification', 'AdminController@sendTestNotification'); //推送通知测试
 		Route::any('profile', 'AdminController@profile'); // 修改个人信息
 		Route::any('profile', 'AdminController@profile'); // 修改个人信息
 		Route::get('makePort', 'AdminController@makePort'); // 生成端口
 		Route::get('makePort', 'AdminController@makePort'); // 生成端口
+		Route::get('epayInfo', 'Gateway\EPay@queryInfo');// 易支付信息
 
 
 		//返利相关
 		//返利相关
 		Route::group(['namespace' => 'Admin'], function() {
 		Route::group(['namespace' => 'Admin'], function() {
@@ -212,5 +213,5 @@ Route::group(['middleware' => ['isForbidden', 'isMaintenance', 'isLogin']], func
 
 
 Route::group(['prefix' => 'callback'], function() {
 Route::group(['prefix' => 'callback'], function() {
 	Route::get('checkout', 'Gateway\PayPal@getCheckout');
 	Route::get('checkout', 'Gateway\PayPal@getCheckout');
-	Route::post('notify', 'PaymentController@notify'); //支付回调
+	Route::any('notify', 'PaymentController@notify'); //支付回调
 });
 });