diff --git a/app/Components/Helpers.php b/app/Components/Helpers.php index 2ea74d3ad..72c5915d8 100644 --- a/app/Components/Helpers.php +++ b/app/Components/Helpers.php @@ -10,6 +10,7 @@ use App\Models\UserCreditLog; use App\Models\UserSubscribe; use App\Models\UserTrafficModifyLog; +use Str; class Helpers { // 不生成的端口 @@ -82,7 +83,7 @@ public static function addUser($email, $password, $transfer_enable, $data, $refe // 生成一个可用端口 $user->port = self::systemConfig()['is_rand_port']? self::getRandPort() : self::getOnlyPort(); $user->passwd = makeRandStr(); - $user->vmess_id = createGuid(); + $user->vmess_id = Str::uuid(); $user->enable = 1; $user->method = self::getDefaultMethod(); $user->protocol = self::getDefaultProtocol(); diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index 406472b99..c0277130a 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -43,6 +43,7 @@ use Redirect; use Response; use Session; +use Str; use Symfony\Component\HttpFoundation\BinaryFileResponse; use Validator; @@ -246,7 +247,7 @@ public function addUser(Request $request) { $user->password = Hash::make($request->input('password')?: makeRandStr()); $user->port = $request->input('port')?: $this->makePort(); $user->passwd = $request->input('passwd')?: makeRandStr(); - $user->vmess_id = $request->input('uuid')?: createGuid(); + $user->vmess_id = $request->input('uuid')?: Str::uuid(); $user->transfer_enable = toGB($request->input('transfer_enable')?: 0); $user->enable = $request->input('enable')?: 0; $user->method = $request->input('method'); @@ -367,7 +368,7 @@ public function editUser(Request $request, $id) { 'email' => $email, 'port' => $port, 'passwd' => $request->input('passwd')?: makeRandStr(), - 'vmess_id' => $request->input('uuid')?: createGuid(), + 'vmess_id' => $request->input('uuid')?: Str::uuid(), 'transfer_enable' => toGB($transfer_enable?: 0), 'enable' => $status < 0? 0 : $request->input('enable'), 'method' => $request->input('method'), @@ -1152,6 +1153,11 @@ public function setConfig(Request $request): JsonResponse { return Response::json(['status' => 'fail', 'message' => '请先设置【码支付】必要参数']); } break; + case 'epay': + if(!self::$systemConfig['epay_url'] || !self::$systemConfig['epay_mch_id'] || !self::$systemConfig['epay_key']){ + return Response::json(['status' => 'fail', 'message' => '请先设置【易支付】必要参数']); + } + break; case 'payjs': if(!self::$systemConfig['payjs_mch_id'] || !self::$systemConfig['payjs_key']){ return Response::json(['status' => 'fail', 'message' => '请先设置【PayJs】必要参数']); diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 561e00fcb..39a658043 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -12,22 +12,13 @@ use Illuminate\Http\UploadedFile; use Illuminate\Routing\Controller as BaseController; use RuntimeException; +use Str; class Controller extends BaseController { use AuthorizesRequests, DispatchesJobs, ValidatesRequests; - // 生成随机密码 - public function makePasswd() { - return makeRandStr(); - } - - // 生成UUID - public function makeUUID() { - return createGuid(); - } - // 生成网站安全码 - public function makeSecurityCode() { + public function makeSecurityCode(): string { return strtolower(makeRandStr(8)); } diff --git a/app/Http/Controllers/Gateway/AbstractPayment.php b/app/Http/Controllers/Gateway/AbstractPayment.php index da0cc587c..4ace86e00 100644 --- a/app/Http/Controllers/Gateway/AbstractPayment.php +++ b/app/Http/Controllers/Gateway/AbstractPayment.php @@ -12,6 +12,7 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Log; +use Str; abstract class AbstractPayment { protected static $systemConfig; @@ -26,7 +27,7 @@ abstract public function notify(Request $request): void; protected function postPayment($data, $method): int { // 获取需要的信息 - $payment = Payment::whereTradeNo($data)->first(); + $payment = Payment::whereTradeNo($data)->latest()->first(); // 是否为余额购买套餐 if($payment){ Payment::whereTradeNo($data)->update(['status' => 1]); @@ -120,9 +121,7 @@ protected function postPayment($data, $method): int { User::query()->whereId($order->user->referral_uid)->increment('invite_num', 1); } //按照返利模式进行返利判断 - if(self::$systemConfig['referral_type'] == 2 - || (self::$systemConfig['referral_type'] == 1 - && !$referral)){ + if(self::$systemConfig['referral_type'] == 2 || (self::$systemConfig['referral_type'] == 1 && !$referral)){ $this->addReferralLog($order->user_id, $order->user->referral_uid, $order->oid, $order->amount, $order->amount * self::$systemConfig['referral_percent']); } @@ -155,14 +154,13 @@ private function addReferralLog($userId, $refUserId, $oid, $amount, $refAmount): $log->amount = $amount; $log->ref_amount = $refAmount; $log->status = 0; - $log->save(); - return 0; + return $log->save(); } protected function creatNewPayment($uid, $oid, $amount): Payment { $payment = new Payment(); - $payment->trade_no = self::generateGuid(); + $payment->trade_no = substr(str_replace('-', '', Str::uuid()), 0, 8); $payment->user_id = $uid; $payment->oid = $oid; $payment->amount = $amount; @@ -171,19 +169,6 @@ protected function creatNewPayment($uid, $oid, $amount): Payment { return $payment; } - public static function generateGuid(): string { - mt_srand((double) microtime() * 10000); - $charId = strtoupper(md5(uniqid(mt_rand() + time(), true))); - $hyphen = chr(45); - $uuid = chr(123).substr($charId, 0, 8).$hyphen.substr($charId, 8, 4).$hyphen.substr($charId, 12, - 4).$hyphen.substr($charId, 16, 4).$hyphen.substr($charId, 20, 12).chr(125); - - $uuid = str_replace(['}', '{', '-'], '', $uuid); - $uuid = substr($uuid, 0, 8); - - return $uuid; - } - /** * @param string $trade_no 本地订单号 * @param string $out_trade_no 外部订单号 diff --git a/app/Http/Controllers/Gateway/EPay.php b/app/Http/Controllers/Gateway/EPay.php new file mode 100644 index 000000000..13259c4f3 --- /dev/null +++ b/app/Http/Controllers/Gateway/EPay.php @@ -0,0 +1,76 @@ +creatNewPayment(Auth::id(), $request->input('oid'), $request->input('amount')); + + switch($request->input('type')){ + case 2: + $type = 'qqpay'; + break; + case 3: + $type = 'wxpay'; + break; + case 1: + default: + $type = 'alipay'; + break; + } + + + $data = [ + 'pid' => self::$systemConfig['epay_mch_id'], + 'type' => $type, + 'out_trade_no' => $payment->trade_no, + 'notify_url' => (self::$systemConfig['website_callback_url']?: self::$systemConfig['website_url']).'/callback/notify?method=epay', + 'return_url' => self::$systemConfig['website_url'].'/invoices', + 'name' => self::$systemConfig['subject_name']?: self::$systemConfig['website_name'], + 'money' => $payment->amount, + + ]; + $data['sign'] = $this->sign($this->prepareSign($data)); + + $result = json_decode(Curl::send(self::$systemConfig['epay_url'].'/submit.php', $data), true); + if(!$result){ + return Response::json(['status' => 'fail', 'message' => '支付处理失败!']); + } + + Payment::whereId($payment->id)->update(['qr_code' => 1, 'url' => $result['pay_url']]); + + return Response::json(['status' => 'success', 'data' => $payment->trade_no, 'message' => '创建订单成功!']); + } + + // 签名字符串 + private function sign($data): string { + return strtolower(md5($data.self::$systemConfig['epay_key'])); + } + + private function prepareSign($data): string { + ksort($data); + return http_build_query($data); + } + + public function notify(Request $request): void { + + if(!$this->verify($request->all(), $request->input('sign'))){ + die('FAIL'); + } + $this->postPayment($request->input('out_trade_no'), 'EPay'); + die('SUCCESS'); + } + + // 验证签名 + private function verify($data, $signature): bool { + unset($data['sign']); + return $this->sign($this->prepareSign($data)) === $signature; + } +} diff --git a/app/Http/Controllers/PaymentController.php b/app/Http/Controllers/PaymentController.php index bfeee053f..3bc3d6349 100644 --- a/app/Http/Controllers/PaymentController.php +++ b/app/Http/Controllers/PaymentController.php @@ -5,6 +5,7 @@ use App\Components\Helpers; use App\Http\Controllers\Gateway\BitpayX; use App\Http\Controllers\Gateway\CodePay; +use App\Http\Controllers\Gateway\EPay; use App\Http\Controllers\Gateway\F2Fpay; use App\Http\Controllers\Gateway\Local; use App\Http\Controllers\Gateway\PayJs; @@ -53,6 +54,8 @@ public static function getClient() { return new BitpayX(); case 'paypal': return new PayPal(); + case 'epay': + return new EPay(); default: Log::error("未知支付:".self::$method); @@ -189,7 +192,7 @@ public function purchase(Request $request) { Helpers::addCouponLog($coupon->id, $goods_id, $order->oid, '订单支付使用'); } - $request->merge(['oid' => $order->oid, 'amount' => $amount, 'type' => $request->input('pay_type')]); + $request->merge(['oid' => $order->oid, 'amount' => $amount, 'type' => $pay_type]); // 生成支付单 return self::getClient()->purchase($request); diff --git a/app/helpers.php b/app/helpers.php index 3029b8e22..b37bf9691 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -208,19 +208,6 @@ function getIPv6($ip) { } } -// 随机UUID -if(!function_exists('createGuid')){ - function createGuid() { - mt_srand((double) microtime() * 10000); - $charid = strtoupper(md5(uniqid(mt_rand(), true))); - $hyphen = chr(45); - $uuid = substr($charid, 0, 8).$hyphen.substr($charid, 8, 4).$hyphen.substr($charid, 12, - 4).$hyphen.substr($charid, 16, 4).$hyphen.substr($charid, 20, 12); - - return strtolower($uuid); - } -} - // 过滤emoji表情 if(!function_exists('filterEmoji')){ function filterEmoji($str) { diff --git a/resources/views/admin/config/system.blade.php b/resources/views/admin/config/system.blade.php index 2855404c0..7bf29874f 100644 --- a/resources/views/admin/config/system.blade.php +++ b/resources/views/admin/config/system.blade.php @@ -1112,6 +1112,7 @@ class="col-md-3 col-form-label">流量警告阈值 + @@ -1121,6 +1122,7 @@ class="col-md-3 col-form-label">流量警告阈值 @@ -1131,6 +1133,7 @@ class="col-md-3 col-form-label">流量警告阈值 + @@ -1274,6 +1277,55 @@ class="col-md-3 col-form-label">流量警告阈值 +
+
+
+ +
+ {{-- 请到 码支付申请账号,然后下载登录其挂机软件--}} +
+
+
+
+
+ +
+
+ + + + +
+
+
+
+
+
+ +
+
+ + + + +
+
+
+
+
+
+ +
+
+ + + + +
+
+
+
+
diff --git a/resources/views/admin/node/nodeInfo.blade.php b/resources/views/admin/node/nodeInfo.blade.php index e02fcaeda..bb41a29c5 100644 --- a/resources/views/admin/node/nodeInfo.blade.php +++ b/resources/views/admin/node/nodeInfo.blade.php @@ -432,7 +432,7 @@ class="col-md-5 form-control" name="country_code" id="country_code"> $('#passwd').val('{{$node->passwd}}'); $("input[name='type'][value='{{$node->type}}']").click(); - @if($node->type==1) + @if($node->type == 1 || $node->type == 4) // ShadowsocksR $('#method').selectpicker('val', '{{$node->method}}'); $('#protocol').selectpicker('val', '{{$node->protocol}}'); @@ -444,7 +444,7 @@ class="col-md-5 form-control" name="country_code" id="country_code"> @endif @endif - @if($node->type==2) + @if($node->type == 2) //V2Ray $('#v2_alter_id').val('{{$node->v2_alter_id}}'); $('#v2_port').val('{{$node->v2_port}}'); diff --git a/resources/views/admin/node/nodeList.blade.php b/resources/views/admin/node/nodeList.blade.php index 20498c922..8710a0432 100644 --- a/resources/views/admin/node/nodeList.blade.php +++ b/resources/views/admin/node/nodeList.blade.php @@ -44,7 +44,7 @@ @if($node->is_relay) 中转 @else - {{$node->type == 2 ? 'V2' : 'SSR'}} + {{$node->type_label}} @endif {{$node->name}} diff --git a/routes/web.php b/routes/web.php index a0989480a..091aff101 100644 --- a/routes/web.php +++ b/routes/web.php @@ -13,8 +13,8 @@ Route::get('active/{token}', 'AuthController@active'); // 激活账号 Route::post('sendCode', 'AuthController@sendCode'); // 发送注册验证码 Route::get('free', 'AuthController@free'); // 免费邀请码 - Route::get('makePasswd', 'Controller@makePasswd'); // 生成密码 - Route::get('makeUUID', 'Controller@makeUUID'); // 生成UUID + Route::get('makePasswd', makeRandStr()); // 生成随机密码 + Route::get('makeUUID', Str::uuid()); // 生成UUID Route::get('makeSecurityCode', 'Controller@makeSecurityCode'); // 生成网站安全码 }); Route::any('admin/login', 'AuthController@login')->middleware('isForbidden', 'isSecurity'); // 登录 diff --git a/sql/db.sql b/sql/db.sql index 67bc99160..bfde0e305 100644 --- a/sql/db.sql +++ b/sql/db.sql @@ -416,7 +416,10 @@ VALUES ('1', 'is_rand_port', 0), ('109', 'paypal_secret', ''), ('110', 'paypal_certificate', ''), ('111', 'paypal_app_id', ''), - ('112', 'redirect_url', ''); + ('112', 'redirect_url', ''), + ('113', 'epay_url', ''), + ('114', 'epay_mch_id', ''), + ('115', 'epay_key', ''); -- ---------------------------- -- Table structure for article diff --git a/sql/mod/20200720.sql b/sql/mod/20200720.sql new file mode 100644 index 000000000..1365ff2e7 --- /dev/null +++ b/sql/mod/20200720.sql @@ -0,0 +1,3 @@ +INSERT INTO `config` VALUES ('113', 'epay_url', ''); +INSERT INTO `config` VALUES ('114', 'epay_mch_id', ''); +INSERT INTO `config` VALUES ('115', 'epay_key', ''); \ No newline at end of file