Compare commits
No commits in common. 'dev' and 'Anankke_dev' have entirely different histories.
dev
...
Anankke_de
@ -0,0 +1,22 @@
|
||||
# https://editorconfig.org/
|
||||
|
||||
root = true
|
||||
|
||||
[*]
|
||||
tab_width = 4
|
||||
|
||||
[*.php]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_size = 4
|
||||
indent_style = space
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_style = space
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
max_line_length = 80
|
||||
@ -0,0 +1,2 @@
|
||||
# Auto detect text files and perform LF normalization
|
||||
* text=auto
|
||||
@ -1,19 +0,0 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an new idea for this project
|
||||
title: "[Feature Request]"
|
||||
labels: enhancement
|
||||
|
||||
---
|
||||
|
||||
- [ ] I acknowledge if I don't follow the format below or I don't check these box, my issue could be closed without any notice.
|
||||
- [ ] I certify that I have read project Wiki and other issue may related to this one.
|
||||
|
||||
**Feature**
|
||||
The feature you want.
|
||||
|
||||
**Solution**
|
||||
If you have some solution about this issue, type it here.
|
||||
|
||||
**Addition**
|
||||
Additional context here.
|
||||
@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>ss-panel-v3-mod_UIChanges</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>com.aptana.ide.core.unifiedBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>com.aptana.projects.webnature</nature>
|
||||
</natures>
|
||||
<filteredResources>
|
||||
<filter>
|
||||
<id>1522297588605</id>
|
||||
<name></name>
|
||||
<type>26</type>
|
||||
<matcher>
|
||||
<id>org.eclipse.ui.ide.multiFilter</id>
|
||||
<arguments>1.0-name-matches-false-false-node_modules</arguments>
|
||||
</matcher>
|
||||
</filter>
|
||||
</filteredResources>
|
||||
</projectDescription>
|
||||
@ -1,19 +0,0 @@
|
||||
根据时间从 2018 年 12 月始...
|
||||
|
||||
- 支持 Quantumult 格式的 V2Ray 订阅以及策略组配置导出
|
||||
- 支持 Surge 2 & 3 的托管配置以及 policy group
|
||||
- 支持 SurfBoard 的托管配置
|
||||
- 支持 Shadowrocket 支持的 Shadowsocks(R) & VMess 合并订阅
|
||||
- 提供用户使用文档
|
||||
- 完全合并普通端口和单端口的订阅及托管
|
||||
- ShadowsocksR 订阅中的账户及流量信息改为可选
|
||||
- ~~一键切换 SS/SSR 加密、协议、混淆~~ (已废弃)
|
||||
- 订阅链接兼容 Anankke
|
||||
- ~~支持 ss-v2ray-plugin 类型节点~~ (已合并到 Anankke)
|
||||
- V2Ray 订阅可选支持显示账户及流量信息
|
||||
- 可选使用预定义的加密、协议、混淆配置方案
|
||||
- 支持用户自定义 Surge 托管配置
|
||||
- 支持用户自定义 Clash 托管配置
|
||||
|
||||
……
|
||||
|
||||
@ -1,43 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use App\Controllers\AdminController;
|
||||
use Ozdemir\Datatables\Datatables;
|
||||
use App\Utils\DatatablesHelper;
|
||||
|
||||
class DetectBanLogController extends AdminController
|
||||
{
|
||||
public function index($request, $response, $args)
|
||||
{
|
||||
$table_config['total_column'] = array("id" => "ID", "user_id" => "用户ID",
|
||||
"user_name" => "用户名", "email" => "用户邮箱",
|
||||
"detect_number" => "违规次数", "ban_time" => "封禁时长(分钟)",
|
||||
"start_time" => "统计开始时间", "end_time" => "统计结束以及封禁开始时间",
|
||||
"ban_end_time" => "封禁结束时间", "all_detect_number" => "累计违规次数");
|
||||
$table_config['default_show_column'] = array();
|
||||
foreach ($table_config['total_column'] as $column => $value) {
|
||||
array_push($table_config['default_show_column'], $column);
|
||||
}
|
||||
$table_config['ajax_url'] = 'ban/ajax';
|
||||
return $this->view()->assign('table_config', $table_config)->display('admin/detect/ban.tpl');
|
||||
}
|
||||
|
||||
public function ajax_log($request, $response, $args)
|
||||
{
|
||||
$datatables = new Datatables(new DatatablesHelper());
|
||||
$datatables->query('Select detect_ban_log.id,detect_ban_log.user_id,detect_ban_log.user_name,detect_ban_log.email,detect_ban_log.detect_number,detect_ban_log.ban_time,detect_ban_log.start_time,detect_ban_log.end_time,detect_ban_log.all_detect_number,detect_ban_log.end_time as ban_end_time from detect_ban_log');
|
||||
$datatables->edit('start_time', function ($data) {
|
||||
return date('Y-m-d H:i:s', $data['start_time']);
|
||||
});
|
||||
$datatables->edit('end_time', function ($data) {
|
||||
return date('Y-m-d H:i:s', $data['end_time']);
|
||||
});
|
||||
$datatables->edit('ban_end_time', function ($data) {
|
||||
return date('Y-m-d H:i:s', $data['ban_end_time']+$data['ban_time']*60);
|
||||
});
|
||||
|
||||
$body = $response->getBody();
|
||||
$body->write($datatables->generate());
|
||||
}
|
||||
}
|
||||
@ -1,108 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use App\Controllers\AdminController;
|
||||
use App\Services\Auth;
|
||||
use App\Models\GConfig;
|
||||
|
||||
class GConfigController extends AdminController
|
||||
{
|
||||
public function update($request, $response, $args)
|
||||
{
|
||||
$key = trim($args['key']);
|
||||
$user = Auth::getUser();
|
||||
|
||||
$config = GConfig::find($key);
|
||||
$config->oldvalue = $config->value;
|
||||
$config->value = $request->getParam('value');
|
||||
$config->operator_id = $user->id;
|
||||
$config->operator_name = $user->user_name;
|
||||
$config->operator_email = $user->email;
|
||||
$config->last_update = time();
|
||||
if (!$config->save()) {
|
||||
$rs['ret'] = 0;
|
||||
$rs['msg'] = '修改失败';
|
||||
return $response->write(json_encode($rs));
|
||||
}
|
||||
$rs['ret'] = 1;
|
||||
$rs['msg'] = '修改成功';
|
||||
return $response->write(json_encode($rs));
|
||||
}
|
||||
|
||||
public function telegram($request, $response, $args)
|
||||
{
|
||||
$table_config['total_column'] = array(
|
||||
'op' => '操作',
|
||||
'name' => '配置名称',
|
||||
'key' => '配置名',
|
||||
'value' => '配置值',
|
||||
'operator_id' => '操作员 ID',
|
||||
'operator_name' => '操作员名称',
|
||||
'operator_email' => '操作员邮箱',
|
||||
'last_update' => '修改时间'
|
||||
);
|
||||
$table_config['default_show_column'] = array();
|
||||
foreach ($table_config['total_column'] as $column => $value) {
|
||||
$table_config['default_show_column'][] = $column;
|
||||
}
|
||||
$table_config['ajax_url'] = 'telegram/ajax';
|
||||
return $this->view()->assign('table_config', $table_config)->fetch('admin/config/telegram/index.tpl');
|
||||
}
|
||||
|
||||
public function telegram_edit($request, $response, $args)
|
||||
{
|
||||
$key = trim($args['key']);
|
||||
$config = GConfig::find($key);
|
||||
return $this->view()->assign('edit_config', $config)->fetch('admin/config/telegram/edit.tpl');
|
||||
}
|
||||
|
||||
public function telegram_update($request, $response, $args)
|
||||
{
|
||||
return self::update($request, $response, $args);
|
||||
}
|
||||
|
||||
public function telegram_ajax($request, $response, $args)
|
||||
{
|
||||
$start = $request->getParam("start");
|
||||
$limit_length = $request->getParam('length');
|
||||
$configs = GConfig::skip($start)->where('key', 'LIKE', "%Telegram%")->limit($limit_length)->get();
|
||||
$total_conut = GConfig::where('key', 'LIKE', "%Telegram%")->count();
|
||||
$data = [];
|
||||
foreach ($configs as $config) {
|
||||
$tempdata = [];
|
||||
$tempdata['op'] = '<a class="btn btn-brand" href="/admin/config/telegram/' . $config->key . '/edit">编辑</a>';
|
||||
$tempdata['name'] = $config->name;
|
||||
$tempdata['key'] = $config->key;
|
||||
$tempdata['value'] = $config->value;
|
||||
$tempdata['operator_id'] = $config->operator_id;
|
||||
$tempdata['operator_name'] = $config->operator_name;
|
||||
$tempdata['operator_email'] = $config->operator_email;
|
||||
$tempdata['last_update'] = date('Y-m-d H:i:s', $config->last_update);
|
||||
if (strpos($config->key, '.enable.')) {
|
||||
switch ((int) $config->value) {
|
||||
case 0:
|
||||
$tempdata['value'] = '关闭';
|
||||
break;
|
||||
case 1:
|
||||
$tempdata['value'] = '开启';
|
||||
break;
|
||||
default:
|
||||
$tempdata['value'] = '未知';
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$tempdata['value'] = '(请在编辑页面查看)';
|
||||
}
|
||||
$data[] = $tempdata;
|
||||
}
|
||||
$info = [
|
||||
'draw' => $request->getParam('draw'),
|
||||
'recordsTotal' => $total_conut,
|
||||
'recordsFiltered' => $total_conut,
|
||||
'data' => $data
|
||||
];
|
||||
|
||||
return json_encode($info, true);
|
||||
}
|
||||
}
|
||||
@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Admin;
|
||||
|
||||
use App\Controllers\AdminController;
|
||||
use App\Utils\QQWry;
|
||||
|
||||
use Ozdemir\Datatables\Datatables;
|
||||
use App\Utils\DatatablesHelper;
|
||||
|
||||
class SubscribeLogController extends AdminController
|
||||
{
|
||||
public function index($request, $response, $args)
|
||||
{
|
||||
$table_config['total_column'] = array('id' => 'ID', 'user_name' => '用户名',
|
||||
'user_id' => '用户ID', 'email' => '用户邮箱', 'subscribe_type' => '类型',
|
||||
'request_ip' => 'IP', 'location' => '归属地', 'request_time' => '时间',
|
||||
'request_user_agent' => 'User-Agent');
|
||||
$table_config['default_show_column'] = array();
|
||||
foreach ($table_config['total_column'] as $column => $value) {
|
||||
$table_config['default_show_column'][] = $column;
|
||||
}
|
||||
$table_config['ajax_url'] = 'subscribe/ajax';
|
||||
return $this->view()->assign('table_config', $table_config)->display('admin/subscribe.tpl');
|
||||
}
|
||||
|
||||
public function ajax_subscribe_log($request, $response, $args)
|
||||
{
|
||||
$datatables = new Datatables(new DatatablesHelper());
|
||||
$datatables->query('Select user_subscribe_log.id,user_subscribe_log.user_name,user_subscribe_log.user_id,user_subscribe_log.email,user_subscribe_log.subscribe_type,user_subscribe_log.request_ip,user_subscribe_log.request_ip as location,user_subscribe_log.request_time,user_subscribe_log.request_user_agent from user_subscribe_log');
|
||||
|
||||
$iplocation = new QQWry();
|
||||
$datatables->edit('location', static function ($data) use ($iplocation) {
|
||||
$location = $iplocation->getlocation($data['location']);
|
||||
return iconv('gbk', 'utf-8//IGNORE', $location['country'] . $location['area']);
|
||||
});
|
||||
|
||||
$body = $response->getBody();
|
||||
$body->write($datatables->generate());
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,162 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\Node;
|
||||
use App\Models\User;
|
||||
use App\Services\Factory;
|
||||
use App\Services\Config;
|
||||
use App\Utils\Tools;
|
||||
use App\Utils\Hash;
|
||||
use App\Utils\Helper;
|
||||
|
||||
/**
|
||||
* ApiController
|
||||
*/
|
||||
class ApiController extends BaseController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
}
|
||||
|
||||
public function token($request, $response, $args)
|
||||
{
|
||||
$accessToken = $id = $args['token'];
|
||||
$storage = Factory::createTokenStorage();
|
||||
$token = $storage->get($accessToken);
|
||||
if ($token == null) {
|
||||
$res['ret'] = 0;
|
||||
$res['msg'] = 'token is null';
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
$res['ret'] = 1;
|
||||
$res['msg'] = 'ok';
|
||||
$res['data'] = $token;
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
|
||||
public function newToken($request, $response, $args)
|
||||
{
|
||||
// $data = $request->post('sdf');
|
||||
$email = $request->getParam('email');
|
||||
|
||||
$email = strtolower($email);
|
||||
$passwd = $request->getParam('passwd');
|
||||
|
||||
// Handle Login
|
||||
$user = User::where('email', '=', $email)->first();
|
||||
|
||||
if ($user == null) {
|
||||
$res['ret'] = 0;
|
||||
$res['msg'] = '401 邮箱或者密码错误';
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
|
||||
if (!Hash::checkPassword($user->pass, $passwd)) {
|
||||
$res['ret'] = 0;
|
||||
$res['msg'] = '402 邮箱或者密码错误';
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
$tokenStr = Tools::genToken();
|
||||
$storage = Factory::createTokenStorage();
|
||||
$expireTime = time() + 3600 * 24 * 7;
|
||||
if ($storage->store($tokenStr, $user, $expireTime)) {
|
||||
$res['ret'] = 1;
|
||||
$res['msg'] = 'ok';
|
||||
$res['data']['token'] = $tokenStr;
|
||||
$res['data']['user_id'] = $user->id;
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
$res['ret'] = 0;
|
||||
$res['msg'] = 'system error';
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
|
||||
public function node($request, $response, $args)
|
||||
{
|
||||
$accessToken = Helper::getParam($request, 'access_token');
|
||||
$storage = Factory::createTokenStorage();
|
||||
$token = $storage->get($accessToken);
|
||||
$user = User::find($token->userId);
|
||||
$nodes = Node::where('sort', 0)->where('type', '1')->where(
|
||||
static function ($query) use ($user) {
|
||||
$query->where('node_group', '=', $user->node_group)
|
||||
->orWhere('node_group', '=', 0);
|
||||
}
|
||||
)->orderBy('name')->get();
|
||||
|
||||
$mu_nodes = Node::where('sort', 9)->where('node_class', '<=', $user->class)->where('type', '1')->where(
|
||||
static function ($query) use ($user) {
|
||||
$query->where('node_group', '=', $user->node_group)
|
||||
->orWhere('node_group', '=', 0);
|
||||
}
|
||||
)->orderBy('name')->get();
|
||||
|
||||
$temparray = array();
|
||||
foreach ($nodes as $node) {
|
||||
if ($node->mu_only == 0) {
|
||||
$temparray[] = array('remarks' => $node->name,
|
||||
'server' => $node->server,
|
||||
'server_port' => $user->port,
|
||||
'method' => $node->custom_method == 1 ? $user->method : $node->method,
|
||||
'obfs' => str_replace('_compatible', '', (($node->custom_rss == 1 && !($user->obfs == 'plain' && $user->protocol == 'origin')) ? $user->obfs : 'plain')),
|
||||
'obfsparam' => ($node->custom_rss == 1 && !($user->obfs == 'plain' && $user->protocol == 'origin')) ? $user->obfs_param : '',
|
||||
'remarks_base64' => base64_encode($node->name),
|
||||
'password' => $user->passwd,
|
||||
'tcp_over_udp' => false,
|
||||
'udp_over_tcp' => false,
|
||||
'group' => Config::get('appName'),
|
||||
'protocol' => str_replace('_compatible', '', (($node->custom_rss == 1 && !($user->obfs == 'plain' && $user->protocol == 'origin')) ? $user->protocol : 'origin')),
|
||||
'obfs_udp' => false,
|
||||
'enable' => true);
|
||||
}
|
||||
|
||||
if ($node->custom_rss == 1) {
|
||||
foreach ($mu_nodes as $mu_node) {
|
||||
$mu_user = User::where('port', '=', $mu_node->server)->first();
|
||||
$mu_user->obfs_param = $user->getMuMd5();
|
||||
|
||||
$temparray[] = array('remarks' => $node->name . '- ' . $mu_node->server . ' 单端口',
|
||||
'server' => $node->server,
|
||||
'server_port' => $mu_user->port,
|
||||
'method' => $mu_user->method,
|
||||
'group' => Config::get('appName'),
|
||||
'obfs' => str_replace('_compatible', '', (($node->custom_rss == 1 && !($mu_user->obfs == 'plain' && $mu_user->protocol == 'origin')) ? $mu_user->obfs : 'plain')),
|
||||
'obfsparam' => ($node->custom_rss == 1 && !($mu_user->obfs == 'plain' && $mu_user->protocol == 'origin')) ? $mu_user->obfs_param : '',
|
||||
'remarks_base64' => base64_encode($node->name . '- ' . $mu_node->server . ' 单端口'),
|
||||
'password' => $mu_user->passwd,
|
||||
'tcp_over_udp' => false,
|
||||
'udp_over_tcp' => false,
|
||||
'protocol' => str_replace('_compatible', '', (($node->custom_rss == 1 && !($mu_user->obfs == 'plain' && $mu_user->protocol == 'origin')) ? $mu_user->protocol : 'origin')),
|
||||
'obfs_udp' => false,
|
||||
'enable' => true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$res['ret'] = 1;
|
||||
$res['msg'] = 'ok';
|
||||
$res['data'] = $temparray;
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
|
||||
public function userInfo($request, $response, $args)
|
||||
{
|
||||
$id = $args['id'];
|
||||
$accessToken = Helper::getParam($request, 'access_token');
|
||||
$storage = Factory::createTokenStorage();
|
||||
$token = $storage->get($accessToken);
|
||||
if ($id != $token->userId) {
|
||||
$res['ret'] = 0;
|
||||
$res['msg'] = 'access denied';
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
$user = User::find($token->userId);
|
||||
$user->pass = null;
|
||||
$data = $user;
|
||||
$res['ret'] = 1;
|
||||
$res['msg'] = 'ok';
|
||||
$res['data'] = $data;
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: kaguya
|
||||
* Date: 2018/06/30
|
||||
* Time: 21:40
|
||||
*/
|
||||
|
||||
namespace App\Controllers\Client;
|
||||
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Controllers\LinkController;
|
||||
use App\Models\Ann;
|
||||
use App\Models\User;
|
||||
use App\Services\Auth;
|
||||
use App\Services\Config;
|
||||
use App\Services\Factory;
|
||||
use App\Utils\Helper;
|
||||
|
||||
class ClientApiController extends BaseController
|
||||
{
|
||||
public function GetAnnouncement($request, $response, $args)
|
||||
{
|
||||
$accessToken = Helper::getParam($request, 'access_token');
|
||||
$storage = Factory::createTokenStorage();
|
||||
$token = $storage->get($accessToken);
|
||||
$user = User::find($token->userId);
|
||||
$Anns = Ann::orderBy('date', 'desc')->first();
|
||||
$res['ret'] = 1;
|
||||
$res['msg'] = 'ok';
|
||||
$res['data'] = $Anns;
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
|
||||
public function Redirect($request, $response, $args)
|
||||
{
|
||||
$user = Auth::getUser();
|
||||
$url = $request->getQueryParams()['target'];
|
||||
if (!$user->isLogin) {
|
||||
$accessToken = Helper::getParam($request, 'access_token');
|
||||
$storage = Factory::createTokenStorage();
|
||||
$token = $storage->get($accessToken);
|
||||
if ($token == null) {
|
||||
$res['ret'] = 0;
|
||||
$res['msg'] = 'token is null';
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
$user = User::find($token->userId);
|
||||
$time = 3600 * 24;
|
||||
Auth::login($user->id, $time);
|
||||
}
|
||||
return $response->withRedirect($url);
|
||||
}
|
||||
|
||||
public function GetSubLink($request, $response, $args)
|
||||
{
|
||||
$accessToken = Helper::getParam($request, 'access_token');
|
||||
$mu = Helper::getParam($request, 'mu');
|
||||
$storage = Factory::createTokenStorage();
|
||||
$token = $storage->get($accessToken);
|
||||
$user = User::find($token->userId);
|
||||
$ssr_sub_token = LinkController::GenerateSSRSubCode($user->id, 0);
|
||||
$res['ret'] = 1;
|
||||
$res['msg'] = 'ok';
|
||||
$res['data'] = Config::get('subUrl') . $ssr_sub_token;
|
||||
if ($mu != '') $res['data'] = $res['data'].'?mu=' . $mu;
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
}
|
||||
@ -1,575 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 部分应用自定义配置
|
||||
*
|
||||
* PHP version 7.2+
|
||||
*
|
||||
* @category GeekQu
|
||||
* @package App/Controllers/ConfController
|
||||
* @author GeekQu <iloves@live.com>
|
||||
* @license MIT https://github.com/GeekQu/ss-panel-v3-mod_Uim/blob/dev/LICENSE
|
||||
* @link https://github.com/GeekQu
|
||||
*/
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\Config;
|
||||
use App\Utils\ConfRender;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
use Symfony\Component\Yaml\Exception\ParseException;
|
||||
|
||||
/**
|
||||
* ConfController
|
||||
*
|
||||
* @category GeekQu
|
||||
* @package App/Controllers/ConfController
|
||||
* @author GeekQu <iloves@live.com>
|
||||
* @license MIT https://github.com/GeekQu/ss-panel-v3-mod_Uim/blob/dev/LICENSE
|
||||
* @link https://github.com/GeekQu
|
||||
*/
|
||||
class ConfController extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* YAML 转数组
|
||||
*
|
||||
* @param string $Content YAML 字符串
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function YAML2Array($Content)
|
||||
{
|
||||
try {
|
||||
return Yaml::parse($Content);
|
||||
} catch (ParseException $exception) {
|
||||
return printf('无法解析 YAML 字符串: %s', $exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从远端自定义配置文件生成 Surge 托管配置
|
||||
*
|
||||
* @param object $User 用户
|
||||
* @param string $AllProxys Surge 格式的全部节点
|
||||
* @param array $Nodes 全部节点数组
|
||||
* @param string $SourceContent 远程配置内容
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getSurgeConfs($User, $AllProxys, $Nodes, $Configs, $local = false)
|
||||
{
|
||||
$General = self::getSurgeConfGeneral($Configs['General']);
|
||||
$Proxys = (isset($Configs['Proxy'])
|
||||
? self::getSurgeConfProxy($Configs['Proxy'])
|
||||
: '');
|
||||
|
||||
if (isset($Configs['Proxy Group'])) {
|
||||
$Configs['ProxyGroup'] = $Configs['Proxy Group'];
|
||||
}
|
||||
$ProxyGroups = self::getSurgeConfProxyGroup(
|
||||
$Nodes,
|
||||
$Configs['ProxyGroup']
|
||||
);
|
||||
$ProxyGroup = self::getSurgeProxyGroup2String($ProxyGroups);
|
||||
|
||||
$Rule = self::getSurgeConfRule($Configs['Rule'], $local);
|
||||
$Conf = '#!MANAGED-CONFIG '
|
||||
. Config::get('baseUrl') . $_SERVER['REQUEST_URI'] .
|
||||
"\n\n#---------------------------------------------------#" .
|
||||
"\n## 上次更新于:" . date("Y-m-d h:i:s") .
|
||||
"\n#---------------------------------------------------#" .
|
||||
"\n\n[General]"
|
||||
. $General .
|
||||
"\n\n[Proxy]\n"
|
||||
. $AllProxys . $Proxys .
|
||||
"\n\n[Proxy Group]"
|
||||
. $ProxyGroup .
|
||||
"\n\n[Rule]\n"
|
||||
. $Rule;
|
||||
|
||||
return $Conf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Surge 配置中的 General
|
||||
*
|
||||
* @param array $General Surge General 定义
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getSurgeConfGeneral($General)
|
||||
{
|
||||
$return = '';
|
||||
if (count($General) != 0) {
|
||||
foreach ($General as $key => $value) {
|
||||
$return .= "\n$key = $value";
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Surge 配置中的 Proxy
|
||||
*
|
||||
* @param array $Proxys 自定义配置中的额外 Proxy
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getSurgeConfProxy($Proxys)
|
||||
{
|
||||
$return = '';
|
||||
if (count($Proxys) != 0) {
|
||||
foreach ($Proxys as $value) {
|
||||
if (!preg_match('/(\[General|Replica|Proxy|Proxy\sGroup|Rule|Host|URL\sRewrite|Header\sRewrite|MITM|Script\])/', $value)) {
|
||||
$return .= "\n$value";
|
||||
}
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Surge 配置中的 ProxyGroup
|
||||
*
|
||||
* @param array $Nodes 全部节点数组
|
||||
* @param array $ProxyGroups Surge 策略组定义
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getSurgeConfProxyGroup($Nodes, $ProxyGroups)
|
||||
{
|
||||
$return = [];
|
||||
foreach ($ProxyGroups as $ProxyGroup) {
|
||||
if (in_array($ProxyGroup['type'], ['select', 'url-test', 'fallback'])) {
|
||||
$proxies = [];
|
||||
if (
|
||||
isset($ProxyGroup['content']['left-proxies'])
|
||||
&& count($ProxyGroup['content']['left-proxies']) != 0
|
||||
) {
|
||||
$proxies = $ProxyGroup['content']['left-proxies'];
|
||||
}
|
||||
foreach ($Nodes as $item) {
|
||||
$item = self::getMatchProxy($item, $ProxyGroup);
|
||||
if ($item !== null && !in_array($item['remark'], $proxies)) {
|
||||
$proxies[] = $item['remark'];
|
||||
}
|
||||
}
|
||||
if (isset($ProxyGroup['content']['right-proxies'])) {
|
||||
$proxies = array_merge($proxies, $ProxyGroup['content']['right-proxies']);
|
||||
}
|
||||
$ProxyGroup['proxies'] = $proxies;
|
||||
}
|
||||
$return[] = $ProxyGroup;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取匹配的节点
|
||||
*
|
||||
* @param array $Proxy 节点
|
||||
* @param array $Rule 匹配规则
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getMatchProxy($Proxy, $Rule)
|
||||
{
|
||||
$return = null;
|
||||
switch (true) {
|
||||
case (isset($Rule['content']['class'])):
|
||||
if ($Proxy['class'] == $Rule['content']['class']) {
|
||||
if (isset($Rule['content']['regex'])) {
|
||||
if (preg_match('/' . $Rule['content']['regex'] . '/i', $Proxy['remark'])) {
|
||||
$return = $Proxy;
|
||||
}
|
||||
} else {
|
||||
$return = $Proxy;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case (isset($Rule['content']['noclass'])):
|
||||
if ($Proxy['class'] != $Rule['content']['noclass']) {
|
||||
if (isset($Rule['content']['regex'])) {
|
||||
if (preg_match('/' . $Rule['content']['regex'] . '/i', $Proxy['remark'])) {
|
||||
$return = $Proxy;
|
||||
}
|
||||
} else {
|
||||
$return = $Proxy;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case (!isset($Rule['content']['class'])
|
||||
&& !isset($Rule['content']['noclass'])
|
||||
&& isset($Rule['content']['regex'])
|
||||
&& preg_match('/' . $Rule['content']['regex'] . '/i', $Proxy['remark'])
|
||||
):
|
||||
$return = $Proxy;
|
||||
break;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Surge ProxyGroup 去除无用策略组
|
||||
*
|
||||
* @param array $ProxyGroups 策略组
|
||||
* @param array $checks 要检查的策略组名
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function fixSurgeProxyGroup($ProxyGroups, $checks)
|
||||
{
|
||||
if (count($checks) == 0) {
|
||||
return $ProxyGroups;
|
||||
}
|
||||
$clean_names = [];
|
||||
$newProxyGroups = [];
|
||||
foreach ($ProxyGroups as $ProxyGroup) {
|
||||
if (in_array($ProxyGroup['name'], $checks) && count($ProxyGroup['proxies']) == 0) {
|
||||
$clean_names[] = $ProxyGroup['name'];
|
||||
continue;
|
||||
}
|
||||
$newProxyGroups[] = $ProxyGroup;
|
||||
}
|
||||
if (count($clean_names) >= 1) {
|
||||
$ProxyGroups = $newProxyGroups;
|
||||
$newProxyGroups = [];
|
||||
foreach ($ProxyGroups as $ProxyGroup) {
|
||||
if (!in_array($ProxyGroup['name'], $checks) && $ProxyGroup['type'] != 'ssid') {
|
||||
$newProxies = [];
|
||||
foreach ($ProxyGroup['proxies'] as $proxie) {
|
||||
if (!in_array($proxie, $clean_names)) {
|
||||
$newProxies[] = $proxie;
|
||||
}
|
||||
}
|
||||
$ProxyGroup['proxies'] = $newProxies;
|
||||
}
|
||||
$newProxyGroups[] = $ProxyGroup;
|
||||
}
|
||||
}
|
||||
|
||||
return $newProxyGroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Surge ProxyGroup 转字符串
|
||||
*
|
||||
* @param array $ProxyGroups Surge 策略组定义
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getSurgeProxyGroup2String($ProxyGroups)
|
||||
{
|
||||
$return = '';
|
||||
foreach ($ProxyGroups as $ProxyGroup) {
|
||||
$str = '';
|
||||
if (in_array($ProxyGroup['type'], ['select', 'url-test', 'fallback'])) {
|
||||
$proxies = implode(', ', $ProxyGroup['proxies']);
|
||||
if (in_array($ProxyGroup['type'], ['url-test', 'fallback'])) {
|
||||
$str .= ($ProxyGroup['name']
|
||||
. ' = '
|
||||
. $ProxyGroup['type']
|
||||
. ', '
|
||||
. $proxies
|
||||
. ', url = ' . $ProxyGroup['url']
|
||||
. ', interval = ' . $ProxyGroup['interval']);
|
||||
} else {
|
||||
$str .= ($ProxyGroup['name']
|
||||
. ' = '
|
||||
. $ProxyGroup['type']
|
||||
. ', '
|
||||
. $proxies);
|
||||
}
|
||||
} elseif ($ProxyGroup['type'] == 'ssid') {
|
||||
$wifi = '';
|
||||
foreach ($ProxyGroup['content'] as $key => $value) {
|
||||
$wifi .= ', "' . $key . '" = ' . $value;
|
||||
}
|
||||
$cellular = (isset($ProxyGroup['cellular'])
|
||||
? ', cellular = ' . $ProxyGroup['cellular']
|
||||
: '');
|
||||
$str .= ($ProxyGroup['name']
|
||||
. ' = '
|
||||
. $ProxyGroup['type']
|
||||
. ', default = '
|
||||
. $ProxyGroup['default']
|
||||
. $cellular
|
||||
. $wifi);
|
||||
} else {
|
||||
$str .= '';
|
||||
}
|
||||
$return .= "\n$str";
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Surge 配置中的 Rule
|
||||
*
|
||||
* @param array $Rules Surge 规则加载地址
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getSurgeConfRule($Rules, $local)
|
||||
{
|
||||
// 加载本地规则文件
|
||||
if ($local) {
|
||||
$render = ConfRender::getTemplateRender();
|
||||
return $render->fetch(trim($Rules['source']));
|
||||
}
|
||||
|
||||
// 加载远程规则文件
|
||||
$return = '';
|
||||
if (isset($Rules['source']) && $Rules['source'] != '') {
|
||||
$sourceURL = trim($Rules['source']);
|
||||
// 远程规则仅支持 github 以及 gitlab
|
||||
if (preg_match('/^https:\/\/((gist\.)?github\.com|raw\.githubusercontent\.com|gitlab\.com)/i', $sourceURL)) {
|
||||
$return = @file_get_contents($sourceURL);
|
||||
if (!$return) {
|
||||
$return = ('// 远程规则加载失败'
|
||||
. PHP_EOL
|
||||
. 'GEOIP,CN,DIRECT'
|
||||
. PHP_EOL
|
||||
. 'FINAL,DIRECT,dns-failed');
|
||||
}
|
||||
} else {
|
||||
$return = ('// 远程规则仅支持 github 以及 gitlab'
|
||||
. PHP_EOL
|
||||
. 'GEOIP,CN,DIRECT'
|
||||
. PHP_EOL
|
||||
. 'FINAL,DIRECT,dns-failed');
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从远端自定义配置文件生成 Clash 配置
|
||||
*
|
||||
* @param object $User 用户
|
||||
* @param array $AllProxys 全部节点数组
|
||||
* @param string $SourceContent 远程配置内容
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getClashConfs($User, $AllProxys, $Configs, $local = false)
|
||||
{
|
||||
if (isset($Configs['Proxy']) || count($Configs['Proxy']) != 0) {
|
||||
$tmpProxys = array_merge($AllProxys, $Configs['Proxy']);
|
||||
} else {
|
||||
$tmpProxys = $AllProxys;
|
||||
}
|
||||
$Proxys = [];
|
||||
foreach ($tmpProxys as $Proxy) {
|
||||
unset($Proxy['class']);
|
||||
$Proxys[] = $Proxy;
|
||||
}
|
||||
$tmp = self::getClashConfGeneral($Configs['General']);
|
||||
$tmp['Proxy'] = $Proxys;
|
||||
if (isset($Configs['ProxyGroup'])) {
|
||||
$tmp['Proxy Group'] = self::getClashConfProxyGroup(
|
||||
$AllProxys,
|
||||
$Configs['ProxyGroup']
|
||||
);
|
||||
} else {
|
||||
$tmp['Proxy Group'] = self::getClashConfProxyGroup(
|
||||
$AllProxys,
|
||||
$Configs['Proxy Group']
|
||||
);
|
||||
}
|
||||
$Conf = '#!MANAGED-CONFIG '
|
||||
. Config::get('baseUrl') . $_SERVER['REQUEST_URI'] .
|
||||
"\n\n#---------------------------------------------------#" .
|
||||
"\n## 上次更新于:" . date("Y-m-d h:i:s") .
|
||||
"\n#---------------------------------------------------#" .
|
||||
"\n\n"
|
||||
. Yaml::dump($tmp, 4, 2) .
|
||||
"\n\n"
|
||||
. self::getClashConfRule($Configs['Rule'], $local);
|
||||
|
||||
return $Conf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clash 配置中的 General
|
||||
*
|
||||
* @param array $General Clash General 定义
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getClashConfGeneral($General)
|
||||
{
|
||||
if (count($General) != 0) {
|
||||
foreach ($General as $key) {
|
||||
if (in_array(
|
||||
$key,
|
||||
[
|
||||
'Proxy',
|
||||
'Proxy Group',
|
||||
'Rule'
|
||||
]
|
||||
)) {
|
||||
unset($key);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $General;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clash 配置中的 ProxyGroup
|
||||
*
|
||||
* @param array $Nodes 全部节点数组
|
||||
* @param array $ProxyGroups Clash 策略组定义
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getClashConfProxyGroup($Nodes, $ProxyGroups)
|
||||
{
|
||||
$return = [];
|
||||
foreach ($ProxyGroups as $ProxyGroup) {
|
||||
$tmp = [];
|
||||
if (in_array($ProxyGroup['type'], ['select', 'url-test', 'fallback', 'load-balance'])) {
|
||||
$proxies = [];
|
||||
if (
|
||||
isset($ProxyGroup['content']['left-proxies'])
|
||||
&& count($ProxyGroup['content']['left-proxies']) != 0
|
||||
) {
|
||||
$proxies = $ProxyGroup['content']['left-proxies'];
|
||||
}
|
||||
foreach ($Nodes as $item) {
|
||||
$item['remark'] = $item['name'];
|
||||
$item = self::getMatchProxy($item, $ProxyGroup);
|
||||
if ($item !== null && !in_array($item['name'], $proxies)) {
|
||||
$proxies[] = $item['name'];
|
||||
}
|
||||
}
|
||||
if (isset($ProxyGroup['content']['right-proxies'])) {
|
||||
$proxies = array_merge($proxies, $ProxyGroup['content']['right-proxies']);
|
||||
}
|
||||
$tmp = [
|
||||
'name' => $ProxyGroup['name'],
|
||||
'type' => $ProxyGroup['type'],
|
||||
'proxies' => $proxies
|
||||
];
|
||||
if ($ProxyGroup['type'] != 'select') {
|
||||
$tmp['url'] = $ProxyGroup['url'];
|
||||
$tmp['interval'] = $ProxyGroup['interval'];
|
||||
}
|
||||
$return[] = $tmp;
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clash 配置中的 Rule
|
||||
*
|
||||
* @param array $Rules Clash 规则加载地址
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getClashConfRule($Rules, $local)
|
||||
{
|
||||
// 加载本地规则文件
|
||||
if ($local) {
|
||||
$render = ConfRender::getTemplateRender();
|
||||
return $render->fetch(trim($Rules['source']));
|
||||
}
|
||||
|
||||
// 加载远程规则文件
|
||||
$return = ('Rule:' . PHP_EOL);
|
||||
if (isset($Rules['source']) && $Rules['source'] != '') {
|
||||
$sourceURL = trim($Rules['source']);
|
||||
// 远程规则仅支持 github 以及 gitlab
|
||||
if (preg_match('/^https:\/\/((gist\.)?github\.com|raw\.githubusercontent\.com|gitlab\.com)/i', $sourceURL)) {
|
||||
$sourceContent = @file_get_contents($sourceURL);
|
||||
if (!$sourceContent) {
|
||||
$return .= ('// 远程规则加载失败'
|
||||
. PHP_EOL
|
||||
. 'GEOIP,CN,DIRECT'
|
||||
. PHP_EOL
|
||||
. 'MATCH,DIRECT');
|
||||
} else {
|
||||
try {
|
||||
$sourceRule = Yaml::parse($sourceContent);
|
||||
} catch (ParseException $exception) {
|
||||
$sourceRule['error'] = printf('无法解析 YAML 字符串: %s', $exception->getMessage());
|
||||
}
|
||||
if (isset($sourceRule['error']) || !isset($sourceRule['Rule'])) {
|
||||
$return .= $sourceContent;
|
||||
} else {
|
||||
$return .= Yaml::dump($sourceRule['Rule'], 4, 2);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$return .= ('// 远程规则仅支持 github 以及 gitlab'
|
||||
. PHP_EOL
|
||||
. 'GEOIP,CN,DIRECT'
|
||||
. PHP_EOL
|
||||
. 'MATCH,DIRECT');
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clash ProxyGroup 去除无用策略组
|
||||
*
|
||||
* @param array $ProxyGroups 策略组
|
||||
* @param array $checks 要检查的策略组名
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function fixClashProxyGroup($ProxyGroups, $checks)
|
||||
{
|
||||
if (count($checks) == 0) {
|
||||
return $ProxyGroups;
|
||||
}
|
||||
$clean_names = [];
|
||||
$newProxyGroups = [];
|
||||
foreach ($ProxyGroups as $ProxyGroup) {
|
||||
if (in_array($ProxyGroup['name'], $checks) && count($ProxyGroup['proxies']) == 0) {
|
||||
$clean_names[] = $ProxyGroup['name'];
|
||||
continue;
|
||||
}
|
||||
$newProxyGroups[] = $ProxyGroup;
|
||||
}
|
||||
if (count($clean_names) >= 1) {
|
||||
$ProxyGroups = $newProxyGroups;
|
||||
$newProxyGroups = [];
|
||||
foreach ($ProxyGroups as $ProxyGroup) {
|
||||
if (!in_array($ProxyGroup['name'], $checks)) {
|
||||
$newProxies = [];
|
||||
foreach ($ProxyGroup['proxies'] as $proxie) {
|
||||
if (!in_array($proxie, $clean_names)) {
|
||||
$newProxies[] = $proxie;
|
||||
}
|
||||
}
|
||||
$ProxyGroup['proxies'] = $newProxies;
|
||||
}
|
||||
$newProxyGroups[] = $ProxyGroup;
|
||||
}
|
||||
}
|
||||
|
||||
return $newProxyGroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clash ProxyGroup 转字符串
|
||||
*
|
||||
* @param array $ProxyGroups ProxyGroup
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getClashProxyGroup2String($ProxyGroups)
|
||||
{
|
||||
return Yaml::dump($ProxyGroups, 4, 2);
|
||||
}
|
||||
|
||||
// 待续 Quantumult...
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Controllers\Mu;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\NodeOnlineLog;
|
||||
use App\Models\NodeInfoLog;
|
||||
|
||||
class NodeController extends BaseController
|
||||
{
|
||||
public function onlineUserLog($request, $response, $args)
|
||||
{
|
||||
$node_id = $args['id'];
|
||||
$count = $request->getParam('count');
|
||||
$log = new NodeOnlineLog();
|
||||
$log->node_id = $node_id;
|
||||
$log->online_user = $count;
|
||||
$log->log_time = time();
|
||||
if (!$log->save()) {
|
||||
$res = [
|
||||
'ret' => 0,
|
||||
'msg' => 'update failed',
|
||||
];
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
$res = [
|
||||
'ret' => 1,
|
||||
'msg' => 'ok',
|
||||
];
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
|
||||
public function info($request, $response, $args)
|
||||
{
|
||||
$node_id = $args['id'];
|
||||
$load = $request->getParam('load');
|
||||
$uptime = $request->getParam('uptime');
|
||||
$log = new NodeInfoLog();
|
||||
$log->node_id = $node_id;
|
||||
$log->load = $load;
|
||||
$log->uptime = $uptime;
|
||||
$log->log_time = time();
|
||||
if (!$log->save()) {
|
||||
$res = [
|
||||
'ret' => 0,
|
||||
'msg' => 'update failed',
|
||||
];
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
$res = [
|
||||
'ret' => 1,
|
||||
'msg' => 'ok',
|
||||
];
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Mu;
|
||||
|
||||
use App\Models\Node;
|
||||
use App\Models\TrafficLog;
|
||||
use App\Models\User;
|
||||
use App\Controllers\BaseController;
|
||||
use App\Utils\Tools;
|
||||
|
||||
class UserController extends BaseController
|
||||
{
|
||||
// User List
|
||||
public function index($request, $response, $args)
|
||||
{
|
||||
$node = Node::where('node_ip', '=', $_SERVER['REMOTE_ADDR'])->where(
|
||||
static function ($query) {
|
||||
$query->where('sort', '=', 0)
|
||||
->orWhere('sort', '=', 10)->orWhere('sort', '=', 12);
|
||||
}
|
||||
)->first();
|
||||
$node->node_heartbeat = time();
|
||||
$node->save();
|
||||
|
||||
if ($node->node_group != 0) {
|
||||
$users_raw = User::where(
|
||||
static function ($query) use ($node) {
|
||||
$query->where(
|
||||
static function ($query1) use ($node) {
|
||||
$query1->where('class', '>=', $node->node_class)
|
||||
->where('node_group', '=', $node->node_group);
|
||||
}
|
||||
)->orwhere('is_admin', 1);
|
||||
}
|
||||
)
|
||||
->where('enable', 1)->where('expire_in', '>', date('Y-m-d H:i:s'))->get();
|
||||
} else {
|
||||
$users_raw = User::where(
|
||||
static function ($query) use ($node) {
|
||||
$query->where(
|
||||
static function ($query1) use ($node) {
|
||||
$query1->where('class', '>=', $node->node_class);
|
||||
}
|
||||
)->orwhere('is_admin', 1);
|
||||
}
|
||||
)->where('enable', 1)->where('expire_in', '>', date('Y-m-d H:i:s'))->get();
|
||||
}
|
||||
if (($node->node_bandwidth_limit != 0) && $node->node_bandwidth_limit < $node->node_bandwidth) {
|
||||
$users = null;
|
||||
|
||||
$res = [
|
||||
'ret' => 1,
|
||||
'data' => $users
|
||||
];
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
|
||||
$key_list = array('method', 'id', 'port', 'passwd', 'u', 'd', 'enable',
|
||||
't', 'transfer_enable', 'switch', 'email');
|
||||
|
||||
$users_output = array();
|
||||
|
||||
foreach ($users_raw as $user_raw) {
|
||||
if ($user_raw->transfer_enable > $user_raw->u + $user_raw->d) {
|
||||
$user_raw = Tools::keyFilter($user_raw, $key_list);
|
||||
$users_output[] = $user_raw;
|
||||
}
|
||||
}
|
||||
|
||||
$res = [
|
||||
'ret' => 1,
|
||||
'msg' => 'ok',
|
||||
'data' => $users_output
|
||||
];
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
|
||||
// Update Traffic
|
||||
public function addTraffic($request, $response, $args)
|
||||
{
|
||||
$id = $args['id'];
|
||||
$u = $request->getParam('u');
|
||||
$d = $request->getParam('d');
|
||||
$nodeId = $request->getParam('node_id');
|
||||
$node = Node::find($nodeId);
|
||||
|
||||
$node->node_bandwidth = $node->node_bandwidth + $d + $u;
|
||||
|
||||
$node->save();
|
||||
|
||||
|
||||
$rate = $node->traffic_rate;
|
||||
$user = User::find($id);
|
||||
|
||||
$user->t = time();
|
||||
$user->u += ($u * $rate);
|
||||
$user->d += ($d * $rate);
|
||||
if (!$user->save()) {
|
||||
$res = [
|
||||
'ret' => 0,
|
||||
'msg' => 'update failed',
|
||||
];
|
||||
//return $this->echoJson($response, $res);
|
||||
}
|
||||
// log
|
||||
$traffic = new TrafficLog();
|
||||
$traffic->user_id = $id;
|
||||
$traffic->u = $u;
|
||||
$traffic->d = $d;
|
||||
$traffic->node_id = $nodeId;
|
||||
$traffic->rate = $rate;
|
||||
$traffic->traffic = Tools::flowAutoShow(($u + $d) * $rate);
|
||||
$traffic->log_time = time();
|
||||
$traffic->save();
|
||||
|
||||
$res = [
|
||||
'ret' => 1,
|
||||
'msg' => 'ok',
|
||||
];
|
||||
return $this->echoJson($response, $res);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Middleware;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use App\Services\Factory;
|
||||
use App\Utils\Helper;
|
||||
|
||||
class Api
|
||||
{
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
|
||||
{
|
||||
$accessToken = Helper::getParam($request, 'access_token');
|
||||
if ($accessToken == null) {
|
||||
$res['ret'] = 0;
|
||||
$res['msg'] = 'token is null';
|
||||
$response->getBody()->write(json_encode($res));
|
||||
return $response;
|
||||
}
|
||||
$storage = Factory::createTokenStorage();
|
||||
$token = $storage->get($accessToken);
|
||||
if ($token == null) {
|
||||
$res['ret'] = 0;
|
||||
$res['msg'] = 'token is null';
|
||||
$response->getBody()->write(json_encode($res));
|
||||
return $response;
|
||||
}
|
||||
if ($token->expireTime < time()) {
|
||||
$res['ret'] = 0;
|
||||
$res['msg'] = 'token is expire';
|
||||
$response->getBody()->write(json_encode($res));
|
||||
return $response;
|
||||
}
|
||||
$response = $next($request, $response);
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
@ -1,42 +1,51 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Middleware;
|
||||
|
||||
use App\Services\Config;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use App\Utils\Helper;
|
||||
use App\Models\Node;
|
||||
|
||||
class Mod_Mu
|
||||
{
|
||||
/**
|
||||
* @param \Slim\Http\Request $request
|
||||
* @param \Slim\Http\Response $response
|
||||
* @param callable $next
|
||||
*
|
||||
* @return \Slim\Http\Response
|
||||
*/
|
||||
public function __invoke($request, $response, $next)
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
|
||||
{
|
||||
$key = $request->getQueryParam('key');
|
||||
$key = Helper::getParam($request, 'key');
|
||||
if ($key === null) {
|
||||
return $response->withjson([
|
||||
'ret' => 0,
|
||||
'data' => 'Your key is null.'
|
||||
]);
|
||||
$res['ret'] = 0;
|
||||
$res['data'] = 'null';
|
||||
$response->getBody()->write(json_encode($res));
|
||||
return $response;
|
||||
}
|
||||
|
||||
$auth = false;
|
||||
$keys = Config::getMuKey();
|
||||
$auth = in_array($key, $keys);
|
||||
foreach ($keys as $k) {
|
||||
if ($key == $k) {
|
||||
$auth = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$node = Node::where('node_ip', 'LIKE', $_SERVER['REMOTE_ADDR'] . '%')->first();
|
||||
if ($auth === false
|
||||
|| ($node === null && $_SERVER['REMOTE_ADDR'] != '127.0.0.1')
|
||||
) {
|
||||
return $response->withJson([
|
||||
'ret' => 0,
|
||||
'data' => 'Token or IP is invalid. Now, your IP address is ' . $_SERVER['REMOTE_ADDR']
|
||||
]);
|
||||
if ($node == null && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
|
||||
$res['ret'] = 0;
|
||||
$res['data'] = 'token or source is invalid, Your ip address is ' . $_SERVER['REMOTE_ADDR'];
|
||||
$response->getBody()->write(json_encode($res));
|
||||
return $response;
|
||||
}
|
||||
|
||||
if ($auth == false) {
|
||||
$res['ret'] = 0;
|
||||
$res['data'] = 'token or source is invalid';
|
||||
$response->getBody()->write(json_encode($res));
|
||||
return $response;
|
||||
}
|
||||
|
||||
return $next($request, $response);
|
||||
$response = $next($request, $response);
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Middleware;
|
||||
|
||||
use App\Services\Config;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use App\Utils\Helper;
|
||||
use App\Models\Node;
|
||||
|
||||
class Mu
|
||||
{
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
|
||||
{
|
||||
$key = Helper::getParam($request, 'key');
|
||||
if ($key === null) {
|
||||
$res['ret'] = 0;
|
||||
$res['msg'] = 'key is null';
|
||||
$response->getBody()->write(json_encode($res));
|
||||
return $response;
|
||||
}
|
||||
|
||||
$auth = false;
|
||||
$keyset = explode(',', Config::get('muKey'));
|
||||
foreach ($keyset as $sinkey) {
|
||||
if ($key == $sinkey) {
|
||||
$auth = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($auth == false) {
|
||||
$res['ret'] = 0;
|
||||
$res['msg'] = 'token or source is invalid';
|
||||
$response->getBody()->write(json_encode($res));
|
||||
return $response;
|
||||
}
|
||||
|
||||
$node = Node::where('node_ip', 'LIKE', $_SERVER['REMOTE_ADDR'] . '%')->first();
|
||||
if ($node == null && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
|
||||
$res['ret'] = 0;
|
||||
$res['msg'] = 'token or source is invalid';
|
||||
$response->getBody()->write(json_encode($res));
|
||||
return $response;
|
||||
}
|
||||
|
||||
$response = $next($request, $response);
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class DetectBanLog extends Model
|
||||
{
|
||||
protected $connection = "default";
|
||||
protected $table = "detect_ban_log";
|
||||
}
|
||||
@ -1,55 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Services\DefaultConfig;
|
||||
|
||||
class GConfig extends Model
|
||||
{
|
||||
|
||||
/**
|
||||
* The connection name for the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $connection = 'default';
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'gconfig';
|
||||
|
||||
/**
|
||||
* The primary key associated with the table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'key';
|
||||
|
||||
/**
|
||||
* Indicates if the IDs are auto-incrementing.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $incrementing = false;
|
||||
|
||||
/**
|
||||
* The "type" of the auto-incrementing ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $keyType = 'string';
|
||||
|
||||
public static function recover($user)
|
||||
{
|
||||
$this->oldvalue = $this->value;
|
||||
$this->value = DefaultConfig::default_value($this->key)['value'];
|
||||
$this->operator_id = $user->id;
|
||||
$this->operator_name = ('[恢复默认] - ' . $user->user_name);
|
||||
$this->operator_email = $user->email;
|
||||
$this->last_update = time();
|
||||
$this->save();
|
||||
}
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class UserSubscribeLog extends Model
|
||||
{
|
||||
protected $connection = 'default';
|
||||
protected $table = 'user_subscribe_log';
|
||||
}
|
||||
@ -1,554 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
class AppsProfiles
|
||||
{
|
||||
/**
|
||||
* Surge 策略组配置
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function Surge()
|
||||
{
|
||||
$Apps_Profiles = [
|
||||
'lhie1' => [
|
||||
'Checks' => ['🇭🇰 香港', '🇯🇵 日本', '🇸🇬 坡坡', '🇨🇳 台湾', '🇺🇸 美国', '🇰🇷 韩国', '🇨🇳 中继'],
|
||||
'ProxyGroup' => [
|
||||
[
|
||||
'name' => '🍃 Proxy',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'left-proxies' => ['🇭🇰 香港', '🇯🇵 日本', '🇸🇬 坡坡', '🇨🇳 台湾', '🇺🇸 美国', '🇰🇷 韩国', '🇨🇳 中继', '🚀 Direct']
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => '🍂 Domestic',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'left-proxies' => ['🚀 Direct', '🍃 Proxy', '🇨🇳 中继']
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => '🍎 Only',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'left-proxies' => ['🚀 Direct', '🇭🇰 香港', '🇯🇵 日本', '🇸🇬 坡坡', '🇨🇳 台湾', '🇺🇸 美国', '🇰🇷 韩国', '🇨🇳 中继']
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => '☁️ Others',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'left-proxies' => ['🍃 Proxy', '🍂 Domestic']
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => '🇭🇰 香港',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'regex' => '(香港|HK)'
|
||||
],
|
||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
||||
'interval' => 3600
|
||||
],
|
||||
[
|
||||
'name' => '🇯🇵 日本',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'regex' => '(日本|JP)'
|
||||
],
|
||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
||||
'interval' => 3600
|
||||
],
|
||||
[
|
||||
'name' => '🇸🇬 坡坡',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'regex' => '(新加坡|SG)'
|
||||
],
|
||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
||||
'interval' => 3600
|
||||
],
|
||||
[
|
||||
'name' => '🇨🇳 台湾',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'regex' => '(台湾|TW)'
|
||||
],
|
||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
||||
'interval' => 3600
|
||||
],
|
||||
[
|
||||
'name' => '🇺🇸 美国',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'regex' => '(美国|US)'
|
||||
],
|
||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
||||
'interval' => 3600
|
||||
],
|
||||
[
|
||||
'name' => '🇰🇷 韩国',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'regex' => '(韩国|KR)'
|
||||
],
|
||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
||||
'interval' => 3600
|
||||
],
|
||||
[
|
||||
'name' => '🇨🇳 中继',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'regex' => '(中继|中转|中国|回国|China)'
|
||||
],
|
||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
||||
'interval' => 3600
|
||||
]
|
||||
]
|
||||
],
|
||||
'123456' => [
|
||||
'Checks' => [],
|
||||
'ProxyGroup' => [
|
||||
[
|
||||
'name' => '🍃 Proxy',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'regex' => '(.*)'
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => '🍂 Domestic',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'left-proxies' => ['🚀 Direct', '🍃 Proxy']
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => '🍎 Only',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'left-proxies' => ['🚀 Direct', '🍃 Proxy']
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => '☁️ Others',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'left-proxies' => ['🍃 Proxy', '🍂 Domestic']
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
return $Apps_Profiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Surfboard 策略组配置
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function Surfboard()
|
||||
{
|
||||
$Apps_Profiles = [
|
||||
'lhie1' => [
|
||||
'Checks' => ['🇭🇰 香港', '🇯🇵 日本', '🇸🇬 坡坡', '🇨🇳 台湾', '🇺🇸 美国', '🇰🇷 韩国', '🇨🇳 中继'],
|
||||
'ProxyGroup' => [
|
||||
[
|
||||
'name' => '🍃 Proxy',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'left-proxies' => ['🇭🇰 香港', '🇯🇵 日本', '🇸🇬 坡坡', '🇨🇳 台湾', '🇺🇸 美国', '🇰🇷 韩国', '🇨🇳 中继', '🚀 Direct']
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => '🍂 Domestic',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'left-proxies' => ['🚀 Direct', '🍃 Proxy', '🇨🇳 中继']
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => '☁️ Others',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'left-proxies' => ['🍃 Proxy', '🍂 Domestic']
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => '🇭🇰 香港',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'regex' => '(香港|HK)'
|
||||
],
|
||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
||||
'interval' => 3600
|
||||
],
|
||||
[
|
||||
'name' => '🇯🇵 日本',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'regex' => '(日本|JP)'
|
||||
],
|
||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
||||
'interval' => 3600
|
||||
],
|
||||
[
|
||||
'name' => '🇸🇬 坡坡',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'regex' => '(新加坡|SG)'
|
||||
],
|
||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
||||
'interval' => 3600
|
||||
],
|
||||
[
|
||||
'name' => '🇨🇳 台湾',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'regex' => '(台湾|TW)'
|
||||
],
|
||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
||||
'interval' => 3600
|
||||
],
|
||||
[
|
||||
'name' => '🇺🇸 美国',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'regex' => '(美国|US)'
|
||||
],
|
||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
||||
'interval' => 3600
|
||||
],
|
||||
[
|
||||
'name' => '🇰🇷 韩国',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'regex' => '(韩国|KR)'
|
||||
],
|
||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
||||
'interval' => 3600
|
||||
],
|
||||
[
|
||||
'name' => '🇨🇳 中继',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'regex' => '(中继|中转|中国|回国|China)'
|
||||
],
|
||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
||||
'interval' => 3600
|
||||
]
|
||||
]
|
||||
],
|
||||
'123456' => [
|
||||
'Checks' => [],
|
||||
'ProxyGroup' => [
|
||||
[
|
||||
'name' => '🍃 Proxy',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'regex' => '(.*)'
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => '🍂 Domestic',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'left-proxies' => ['🚀 Direct', '🍃 Proxy']
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => '☁️ Others',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'left-proxies' => ['🍃 Proxy', '🍂 Domestic']
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
return $Apps_Profiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clash 策略组配置
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function Clash()
|
||||
{
|
||||
$Apps_Profiles = [
|
||||
'lhie1' => [
|
||||
'Checks' => ['香港', '日本', '坡坡', '台湾', '美国', '韩国', '中继'],
|
||||
'ProxyGroup' => [
|
||||
[
|
||||
'name' => '香港',
|
||||
'type' => 'url-test',
|
||||
'content' => [
|
||||
'regex' => '(香港|HK)'
|
||||
],
|
||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
||||
'interval' => 3600
|
||||
],
|
||||
[
|
||||
'name' => '日本',
|
||||
'type' => 'url-test',
|
||||
'content' => [
|
||||
'regex' => '(日本|JP)'
|
||||
],
|
||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
||||
'interval' => 3600
|
||||
],
|
||||
[
|
||||
'name' => '坡坡',
|
||||
'type' => 'url-test',
|
||||
'content' => [
|
||||
'regex' => '(新加坡|SG)'
|
||||
],
|
||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
||||
'interval' => 3600
|
||||
],
|
||||
[
|
||||
'name' => '美国',
|
||||
'type' => 'url-test',
|
||||
'content' => [
|
||||
'regex' => '(美国|US)'
|
||||
],
|
||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
||||
'interval' => 3600
|
||||
],
|
||||
[
|
||||
'name' => '台湾',
|
||||
'type' => 'url-test',
|
||||
'content' => [
|
||||
'regex' => '(台湾|TW)'
|
||||
],
|
||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
||||
'interval' => 3600
|
||||
],
|
||||
[
|
||||
'name' => '韩国',
|
||||
'type' => 'url-test',
|
||||
'content' => [
|
||||
'regex' => '(韩国|KR)'
|
||||
],
|
||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
||||
'interval' => 3600
|
||||
],
|
||||
[
|
||||
'name' => '中继',
|
||||
'type' => 'url-test',
|
||||
'content' => [
|
||||
'regex' => '(中继|中转|中国|回国|China)'
|
||||
],
|
||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
||||
'interval' => 3600
|
||||
],
|
||||
[
|
||||
'name' => 'Proxy',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'left-proxies' => ['香港', '日本', '坡坡', '台湾', '美国', '韩国', '中继']
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => 'Domestic',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'left-proxies' => ['DIRECT', 'Proxy', '中继']
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => 'AsianTV',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'left-proxies' => ['Domestic', 'Proxy', '中继']
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => 'GlobalTV',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'left-proxies' => ['Proxy', '香港', '日本', '坡坡', '台湾', '美国', '韩国', '中继']
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => 'Others',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'left-proxies' => ['Proxy', 'Domestic']
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'ConnersHua_Pro' => [
|
||||
'Checks' => ['香港', '日本', '坡坡', '台湾', '美国', '韩国', '中继'],
|
||||
'ProxyGroup' => [
|
||||
[
|
||||
'name' => '香港',
|
||||
'type' => 'url-test',
|
||||
'content' => [
|
||||
'regex' => '(香港|HK)'
|
||||
],
|
||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
||||
'interval' => 3600
|
||||
],
|
||||
[
|
||||
'name' => '日本',
|
||||
'type' => 'url-test',
|
||||
'content' => [
|
||||
'regex' => '(日本|JP)'
|
||||
],
|
||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
||||
'interval' => 3600
|
||||
],
|
||||
[
|
||||
'name' => '坡坡',
|
||||
'type' => 'url-test',
|
||||
'content' => [
|
||||
'regex' => '(新加坡|SG)'
|
||||
],
|
||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
||||
'interval' => 3600
|
||||
],
|
||||
[
|
||||
'name' => '美国',
|
||||
'type' => 'url-test',
|
||||
'content' => [
|
||||
'regex' => '(美国|US)'
|
||||
],
|
||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
||||
'interval' => 3600
|
||||
],
|
||||
[
|
||||
'name' => '台湾',
|
||||
'type' => 'url-test',
|
||||
'content' => [
|
||||
'regex' => '(台湾|TW)'
|
||||
],
|
||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
||||
'interval' => 3600
|
||||
],
|
||||
[
|
||||
'name' => '韩国',
|
||||
'type' => 'url-test',
|
||||
'content' => [
|
||||
'regex' => '(韩国|KR)'
|
||||
],
|
||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
||||
'interval' => 3600
|
||||
],
|
||||
[
|
||||
'name' => '中继',
|
||||
'type' => 'url-test',
|
||||
'content' => [
|
||||
'regex' => '(中继|中转|中国|回国|China|CN)'
|
||||
],
|
||||
'url' => 'http://www.qualcomm.cn/generate_204',
|
||||
'interval' => 3600
|
||||
],
|
||||
[
|
||||
'name' => 'PROXY',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'left-proxies' => ['香港', '日本', '坡坡', '台湾', '美国', '韩国', '中继']
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => 'Final',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'left-proxies' => ['PROXY', 'DIRECT']
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => 'ForeignMedia',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'left-proxies' => ['PROXY', '香港', '日本', '坡坡', '台湾', '美国', '韩国', '中继']
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => 'DomesticMedia',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'left-proxies' => ['DIRECT', 'PROXY', '中继']
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => 'Apple',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'left-proxies' => ['DIRECT', 'PROXY']
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => 'Hijacking',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'left-proxies' => ['DIRECT', 'REJECT']
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'ConnersHua_BacktoCN' => [
|
||||
'Checks' => [],
|
||||
'ProxyGroup' => [
|
||||
[
|
||||
'name' => 'PROXY',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'regex' => '(中继|中转|中国|回国|China)'
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'123456' => [
|
||||
'Checks' => [],
|
||||
'ProxyGroup' => [
|
||||
[
|
||||
'name' => 'Proxy',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'regex' => '(.*)'
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => 'Domestic',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'left-proxies' => ['DIRECT', 'Proxy']
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => 'AsianTV',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'left-proxies' => ['Domestic', 'Proxy']
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => 'GlobalTV',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'left-proxies' => ['Proxy']
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => 'Others',
|
||||
'type' => 'select',
|
||||
'content' => [
|
||||
'left-proxies' => ['Proxy', 'Domestic']
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
return $Apps_Profiles;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Auth;
|
||||
|
||||
class File
|
||||
{
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Services\Auth;
|
||||
|
||||
use App\Services\Factory;
|
||||
|
||||
class Token extends Base
|
||||
{
|
||||
protected $storage;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->storage = Factory::createTokenStorage();
|
||||
}
|
||||
|
||||
public function login($uid, $time)
|
||||
{
|
||||
// TODO: Implement getUser() method.
|
||||
}
|
||||
|
||||
public function logout()
|
||||
{
|
||||
// TODO: Implement logout() method.
|
||||
}
|
||||
|
||||
public function getUser()
|
||||
{
|
||||
$token = Cookie::get('token');
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
class Cache
|
||||
{
|
||||
}
|
||||
@ -1,201 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* BitPayX - Yet Another Payment for FIAT
|
||||
* Make Payment Safer, Faster, Cheaper.
|
||||
*
|
||||
* Date: 2019/6/15
|
||||
* Time: 10:08 AM PST
|
||||
*/
|
||||
|
||||
namespace App\Services\Gateway;
|
||||
|
||||
use App\Models\Paylist;
|
||||
use App\Services\Auth;
|
||||
use App\Services\Config;
|
||||
use App\Services\View;
|
||||
|
||||
class BitPayX extends AbstractPayment
|
||||
{
|
||||
private $bitpayAppSecret;
|
||||
private $bitpayGatewayUri;
|
||||
|
||||
/*****************************************************************
|
||||
* BitPay Helper Function
|
||||
******************************************************************/
|
||||
public function __construct($bitpayAppSecret)
|
||||
{
|
||||
$this->bitpayAppSecret = $bitpayAppSecret;
|
||||
$this->bitpayGatewayUri = 'https://api.mugglepay.com/v1/';
|
||||
}
|
||||
|
||||
public function prepareSignId($tradeno)
|
||||
{
|
||||
$data_sign = array();
|
||||
$data_sign['merchant_order_id'] = $tradeno;
|
||||
$data_sign['secret'] = $this->bitpayAppSecret;
|
||||
$data_sign['type'] = 'FIAT';
|
||||
ksort($data_sign);
|
||||
return http_build_query($data_sign);
|
||||
}
|
||||
|
||||
public function sign($data)
|
||||
{
|
||||
return strtolower(md5(md5($data) . $this->bitpayAppSecret));
|
||||
}
|
||||
|
||||
public function verify($data, $signature)
|
||||
{
|
||||
$mySign = $this->sign($data);
|
||||
return $mySign === $signature;
|
||||
}
|
||||
|
||||
public function mprequest($data, $type = 'pay')
|
||||
{
|
||||
$headers = array('content-type: application/json', 'token: ' . $this->bitpayAppSecret);
|
||||
$curl = curl_init();
|
||||
if ($type === 'pay') {
|
||||
$this->bitpayGatewayUri .= 'orders';
|
||||
curl_setopt($curl, CURLOPT_URL, $this->bitpayGatewayUri);
|
||||
curl_setopt($curl, CURLOPT_POST, 1);
|
||||
$data_string = json_encode($data);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
|
||||
} elseif ($type === 'query') {
|
||||
$this->bitpayGatewayUri .= 'orders/merchant_order_id/status?id=' . $data['merchant_order_id'];
|
||||
curl_setopt($curl, CURLOPT_URL, $this->bitpayGatewayUri);
|
||||
curl_setopt($curl, CURLOPT_HTTPGET, 1);
|
||||
}
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
||||
$data = curl_exec($curl);
|
||||
curl_close($curl);
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function query($tradeNo)
|
||||
{
|
||||
$data['merchant_order_id'] = $tradeNo;
|
||||
return json_decode($this->mprequest($data, 'query'), true);
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
* Abstract Payment Implentation
|
||||
******************************************************************/
|
||||
public function purchase($request, $response, $args)
|
||||
{
|
||||
$price = $request->getParam('price');
|
||||
$type = $request->getParam('type');
|
||||
// file_put_contents(BASE_PATH.'/bitpay_purchase.log', $price . " " . $type . "\r\n", FILE_APPEND);
|
||||
if ($price <= 0) {
|
||||
return json_encode(['errcode' => -1, 'errmsg' => '请输入合理的金额。']);
|
||||
}
|
||||
$user = Auth::getUser();
|
||||
$pl = new Paylist();
|
||||
$pl->userid = $user->id;
|
||||
$pl->total = $price;
|
||||
$pl->tradeno = self::generateGuid();
|
||||
$pl->save();
|
||||
$data['merchant_order_id'] = $pl->tradeno;
|
||||
$data['price_amount'] = (float)$price;
|
||||
$data['price_currency'] = 'CNY';
|
||||
if ($type === 'WECHAT' || $type === 'ALIPAY') {
|
||||
$data['pay_currency'] = $type;
|
||||
}
|
||||
$data['title'] = '支付单号:' . $pl->tradeno;
|
||||
$data['description'] = '充值:' . $price . ' 元';
|
||||
$data['callback_url'] = Config::get('baseUrl') . '/payment/notify';
|
||||
|
||||
$data['success_url'] = Config::get('baseUrl') . '/user/payment/return?merchantTradeNo=';
|
||||
$data['success_url'] .= $pl->tradeno;
|
||||
$data['cancel_url'] = $data['success_url'];
|
||||
|
||||
$str_to_sign = $this->prepareSignId($pl->tradeno);
|
||||
$data['token'] = $this->sign($str_to_sign);
|
||||
$result = json_decode($this->mprequest($data), true);
|
||||
$result['pid'] = $pl->tradeno;
|
||||
// file_put_contents(BASE_PATH.'/bitpay_purchase.log', json_encode($data)."\r\n", FILE_APPEND);
|
||||
// file_put_contents(BASE_PATH.'/bitpay_purchase.log', json_encode($result)."\r\n", FILE_APPEND);
|
||||
if ($result['status'] === 200 || $result['status'] === 201) {
|
||||
$result['payment_url'] .= '&lang=zh';
|
||||
return json_encode(array('url' => $result['payment_url'], 'errcode' => 0, 'pid' => $pl->id));
|
||||
}
|
||||
return json_encode(['errcode' => -1, 'errmsg' => $result . error]);
|
||||
}
|
||||
|
||||
public function notify($request, $response, $args)
|
||||
{
|
||||
if (!$this->bitpayAppSecret || $this->bitpayAppSecret === '') {
|
||||
$return = [];
|
||||
$return['status'] = 400;
|
||||
echo json_encode($return);
|
||||
return;
|
||||
}
|
||||
$inputString = file_get_contents('php://input', 'r');
|
||||
$inputStripped = str_replace(array("\r", "\n", "\t", "\v"), '', $inputString);
|
||||
$inputJSON = json_decode($inputStripped, true); //convert JSON into array
|
||||
$data = array();
|
||||
if ($inputJSON !== null) {
|
||||
$data['status'] = $inputJSON['status'];
|
||||
$data['order_id'] = $inputJSON['order_id'];
|
||||
$data['merchant_order_id'] = $inputJSON['merchant_order_id'];
|
||||
$data['price_amount'] = $inputJSON['price_amount'];
|
||||
$data['price_currency'] = $inputJSON['price_currency'];
|
||||
$data['created_at_t'] = $inputJSON['created_at_t'];
|
||||
}
|
||||
// file_put_contents(BASE_PATH.'/bitpay_notify.log', json_encode($data)."\r\n", FILE_APPEND);
|
||||
// 准备待签名数据
|
||||
$str_to_sign = $this->prepareSignId($inputJSON['merchant_order_id']);
|
||||
$resultVerify = $this->verify($str_to_sign, $inputJSON['token']);
|
||||
$isPaid = $data !== null && $data['status'] !== null && $data['status'] === 'PAID';
|
||||
// file_put_contents(BASE_PATH.'/bitpay_notify.log', $resultVerify."\r\n".$isPaid."\r\n", FILE_APPEND);
|
||||
if ($resultVerify && $isPaid) {
|
||||
$this->postPayment($data['merchant_order_id'], 'BitPayX');
|
||||
// echo 'SUCCESS';
|
||||
$return = [];
|
||||
$return['status'] = 200;
|
||||
echo json_encode($return);
|
||||
} else {
|
||||
// echo 'FAIL';
|
||||
$return = [];
|
||||
$return['status'] = 400;
|
||||
echo json_encode($return);
|
||||
}
|
||||
}
|
||||
|
||||
public function getPurchaseHTML()
|
||||
{
|
||||
return View::getSmarty()->fetch('user/bitpayx.tpl');
|
||||
}
|
||||
|
||||
public function getReturnHTML($request, $response, $args)
|
||||
{
|
||||
$pid = $_GET['merchantTradeNo'];
|
||||
$p = Paylist::where('tradeno', '=', $pid)->first();
|
||||
$money = $p->total;
|
||||
if ($p->status === 1) {
|
||||
$success = 1;
|
||||
} else {
|
||||
$data = $this->query($pid);
|
||||
$isPaid = $data !== null && $data['order'] !== null && $data['order']['status'] !== null && $data['order']['status'] === 'PAID';
|
||||
// file_put_contents(BASE_PATH.'/bitpay_return.log', $pid . " " . $data ."\r\n". $isPaid . "\r\n", FILE_APPEND);
|
||||
if ($isPaid) {
|
||||
$this->postPayment($pid, 'BitPayX');
|
||||
$success = 1;
|
||||
} else {
|
||||
$success = 0;
|
||||
}
|
||||
}
|
||||
return View::getSmarty()->assign('money', $money)->assign('success', $success)->fetch('user/pay_success.tpl');
|
||||
}
|
||||
|
||||
public function getStatus($request, $response, $args)
|
||||
{
|
||||
$return = [];
|
||||
$p = Paylist::where('tradeno', $_POST['pid'])->first();
|
||||
$return['ret'] = 1;
|
||||
$return['result'] = $p->status;
|
||||
// file_put_contents(BASE_PATH.'/bitpay_status_success.log', json_encode($return)."\r\n", FILE_APPEND);
|
||||
return json_encode($return);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,161 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: tonyzou
|
||||
* Author:
|
||||
* Date: 2018/9/24
|
||||
* Time: 下午4:01
|
||||
*/
|
||||
|
||||
/**
|
||||
* Made By Leo
|
||||
* 黛米付接口
|
||||
* 2.1.4版本
|
||||
* 适用于 V1 API 黛米付面板V1
|
||||
* copyright all rights reserved
|
||||
*/
|
||||
|
||||
namespace App\Services\Gateway;
|
||||
|
||||
use App\Services\View;
|
||||
use App\Services\Auth;
|
||||
use App\Services\Config;
|
||||
|
||||
use App\Models\Paylist;
|
||||
|
||||
|
||||
class DoiAMPay extends AbstractPayment
|
||||
{
|
||||
public function getPurchaseHTML()
|
||||
{
|
||||
return View::getSmarty()->assign('enabled', Config::get('doiampay')['enabled'])->fetch('user/doiam.tpl');
|
||||
}
|
||||
|
||||
public function notify($request, $response, $args)
|
||||
{
|
||||
$order_data = $_POST;
|
||||
$status = $order_data['status']; //获取传递过来的交易状态
|
||||
$invoiceid = $order_data['out_trade_no']; //订单号
|
||||
$transid = $order_data['trade_no']; //转账交易号
|
||||
$amount = $order_data['money']; //获取递过来的总价格
|
||||
if (!DoiAM::checksign($_POST, Config::get('doiampay')['mchdata'][$args['type']]['token'])) {
|
||||
return json_encode(array('errcode' => 2333));
|
||||
}
|
||||
if ($status == 'success') {
|
||||
$this->postPayment($invoiceid, '黛米付' . ['wepay' => '(微信)', 'qqpay' => '(QQ支付)', 'alipay' => '(支付宝)'][$args['type']]);
|
||||
return json_encode(['errcode' => 0]);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
public function purchase($request, $response, $args)
|
||||
{
|
||||
$type = $request->getParam('type');
|
||||
$price = $request->getParam('price');
|
||||
if (Config::get('doiampay')['enabled'][$type] == 0) {
|
||||
return json_encode(['errcode' => -1, 'errmsg' => '非法的支付方式.']);
|
||||
}
|
||||
if ($price <= 0) {
|
||||
return json_encode(['errcode' => -1, 'errmsg' => '非法的金额.']);
|
||||
}
|
||||
$user = Auth::getUser();
|
||||
$settings = Config::get('doiampay')['mchdata'][$type];
|
||||
$pl = new Paylist();
|
||||
$pl->userid = $user->id;
|
||||
$pl->total = $price;
|
||||
$pl->tradeno = self::generateGuid();
|
||||
$pl->save();
|
||||
$data = [
|
||||
'trade' => $pl->tradeno,
|
||||
'price' => $price,
|
||||
'phone' => $settings['phone'],
|
||||
'mchid' => $settings['mchid'],
|
||||
'subject' => Config::get('appName') . '充值' . $price . '元',
|
||||
'body' => Config::get('appName') . '充值' . $price . '元',
|
||||
'type' => 'Mod',
|
||||
];
|
||||
$data = DoiAM::sign($data, $settings['token']);
|
||||
$ret = DoiAM::post('https://api.daimiyun.cn/v2/' . $type . '/create', $data);
|
||||
$result = json_decode($ret, true);
|
||||
if ($result && $result['errcode'] == 0) {
|
||||
$result['pid'] = $pl->tradeno;
|
||||
return json_encode($result);
|
||||
}
|
||||
|
||||
return json_encode([
|
||||
'errcode' => -1,
|
||||
'errmsg' => '接口调用失败!' . $ret,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function getReturnHTML($request, $response, $args)
|
||||
{
|
||||
$money = $_GET['money'];
|
||||
echo "您已经成功支付 $money 元,正在跳转..";
|
||||
echo <<<HTML
|
||||
<script>
|
||||
location.href="/user/code";
|
||||
</script>
|
||||
HTML;
|
||||
}
|
||||
|
||||
public function getStatus($request, $response, $args)
|
||||
{
|
||||
$p = Paylist::where('tradeno', $_POST['pid'])->first();
|
||||
$return['ret'] = 1;
|
||||
$return['result'] = $p->status;
|
||||
return json_encode($return);
|
||||
}
|
||||
}
|
||||
|
||||
class DoiAM
|
||||
{
|
||||
public static function sort(&$array)
|
||||
{
|
||||
ksort($array);
|
||||
}
|
||||
|
||||
public static function getsign($array, $key)
|
||||
{
|
||||
unset($array['sign']);
|
||||
self::sort($array);
|
||||
$sss = http_build_query($array);
|
||||
$sign = hash('sha256', $sss . $key);
|
||||
$sign = sha1($sign . hash('sha256', $key));
|
||||
return $sign;
|
||||
}
|
||||
|
||||
public static function sign($array, $key)
|
||||
{
|
||||
$array['sign'] = self::getSign($array, $key);
|
||||
return $array;
|
||||
}
|
||||
|
||||
public static function checksign($array, $key)
|
||||
{
|
||||
$new = $array;
|
||||
$new = self::sign($new, $key);
|
||||
if (!isset($array['sign'])) {
|
||||
return false;
|
||||
}
|
||||
return $array['sign'] == $new['sign'];
|
||||
}
|
||||
|
||||
public static function post($url, $data = null)
|
||||
{
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
||||
if (!empty($data)) {
|
||||
curl_setopt($curl, CURLOPT_POST, 1);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||
}
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
$output = curl_exec($curl);
|
||||
curl_close($curl);
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
@ -1,139 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Gateway;
|
||||
|
||||
use App\Services\Auth;
|
||||
use App\Models\Paylist;
|
||||
|
||||
class TomatoPay extends AbstractPayment
|
||||
{
|
||||
public function purchase($request, $response, $args)
|
||||
{
|
||||
$type = $request->getParsedBodyParam('type');
|
||||
$price = $request->getParsedBodyParam('price');
|
||||
if ($price <= 0) {
|
||||
return $response->write(json_encode(['errcode' => -1, 'errmsg' => "非法的金额."]));
|
||||
}
|
||||
$user = Auth::getUser();
|
||||
$settings = $_ENV['tomatopay'][$type];
|
||||
$pl = new Paylist();
|
||||
$pl->userid = $user->id;
|
||||
$pl->total = $price;
|
||||
$pl->tradeno = self::generateGuid();
|
||||
$pl->save();
|
||||
$fqaccount = $settings['account'];
|
||||
$fqkey = $settings['token'];
|
||||
$fqmchid = $settings['mchid'];
|
||||
$fqtrade = $pl->tradeno;
|
||||
$fqcny = $price;
|
||||
|
||||
$signs = md5(
|
||||
'mchid=' . $fqmchid . '&account=' . $fqaccount . '&cny=' . $fqcny . '&type=1&trade=' . $fqtrade . $fqkey
|
||||
);
|
||||
$url = 'https://b.fanqieui.com/gateways/' . $type . '.php?account='
|
||||
. $fqaccount . '&mchid=' . $fqmchid . '&type=1'
|
||||
. '&trade=' . $fqtrade . '&cny=' . $fqcny . '&signs=' . $signs;
|
||||
$result = "<script language='javascript' type='text/javascript'>window.location.href='" . $url . "';</script>";
|
||||
return $response->write(json_encode(['code' => $result, 'errcode' => 0, 'pid' => $pl->id]));
|
||||
}
|
||||
|
||||
public function notify($request, $response, $args)
|
||||
{
|
||||
$type = $args['type'];
|
||||
$settings = $_ENV['tomatopay'][$type];
|
||||
$order_data = $request->getParsedBody();
|
||||
$signs = $order_data['sign'];
|
||||
unset($order_data['sign']);
|
||||
$security = $order_data;
|
||||
$o = '';
|
||||
foreach ($security as $k => $v) {
|
||||
$o .= "$k=" . urlencode($v) . "&";
|
||||
}
|
||||
$sign = md5(substr($o, 0, -1) . $settings['token']);
|
||||
if ($sign == $signs) {
|
||||
$this->postPayment($order_data['out_trade_no'], "在线支付");
|
||||
return $response->write('success');
|
||||
} else {
|
||||
return $response->write('failed');
|
||||
}
|
||||
}
|
||||
public function getPurchaseHTML()
|
||||
{
|
||||
return '
|
||||
<div class="card-inner">
|
||||
<p class="card-heading">充值</p>
|
||||
<h5>支付方式:</h5>
|
||||
<h5 style="color:red">推荐使用支付宝支付,更快到账!</h5>
|
||||
<br/>
|
||||
<nav class="tab-nav margin-top-no">
|
||||
<ul class="nav nav-list">
|
||||
|
||||
|
||||
<li>
|
||||
<a class="waves-attach waves-effect type active" data-toggle="tab" data-pay="alipay"><img src="/images/alipay.jpg" height="50px"></img></a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a class="waves-attach waves-effect type" data-toggle="tab" data-pay="wxpay"><img src="/images/weixin.jpg" height="50px"></img></a>
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
<div class="tab-nav-indicator"></div>
|
||||
</nav>
|
||||
<div class="form-group form-group-label">
|
||||
<label class="floating-label" for="amount">金额</label>
|
||||
<input class="form-control" id="amount" type="text">
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-action">
|
||||
<div class="card-action-btn pull-left">
|
||||
<button class="btn btn-flat waves-attach" id="tomato_pay" ><span class="icon">check</span> 充值</NOtton>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
var type = "wxpay";
|
||||
var type = "alipay";
|
||||
var pid = 0;
|
||||
$(".type").click(function(){
|
||||
type = $(this).data("pay");
|
||||
});
|
||||
$("#tomato_pay").click(function(){
|
||||
var price = parseFloat($("#amount").val());
|
||||
console.log("将要使用"+type+"方法充值"+price+"元")
|
||||
if(isNaN(price)){
|
||||
$("#result").modal();
|
||||
$("#msg").html("非法的金额!");
|
||||
}
|
||||
$.ajax({
|
||||
\'url\':"/user/payment/purchase",
|
||||
\'data\':{
|
||||
\'price\':price,
|
||||
\'type\':type,
|
||||
},
|
||||
\'dataType\':\'json\',
|
||||
\'type\':"POST",
|
||||
success:function(data){
|
||||
console.log(data);
|
||||
if(data.errcode==-1){
|
||||
$("#result").modal();
|
||||
$("#msg").html(data.errmsg);
|
||||
}
|
||||
if(data.errcode==0){
|
||||
pid = data.pid;
|
||||
if(type=="wxpay"){
|
||||
$("#result").modal();
|
||||
$("#msg").html("正在跳转到微信..."+data.code);
|
||||
}else if(type=="alipay"){
|
||||
$("#result").modal();
|
||||
$("#msg").html("正在跳转到支付宝..."+data.code);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
setTimeout(f, 1000);
|
||||
});
|
||||
</script>
|
||||
';
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,211 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: tonyzou
|
||||
* Date: 2018/9/28
|
||||
* Time: 9:08 PM
|
||||
*/
|
||||
|
||||
namespace App\Services\Gateway;
|
||||
|
||||
use App\Services\View;
|
||||
use App\Services\Auth;
|
||||
use App\Services\Config;
|
||||
use App\Models\Paylist;
|
||||
|
||||
class TrimePay extends AbstractPayment
|
||||
{
|
||||
|
||||
private $appSecret;
|
||||
private $gatewayUri;
|
||||
|
||||
/**
|
||||
* 签名初始化
|
||||
* @param merKey 签名密钥
|
||||
*/
|
||||
|
||||
public function __construct($appSecret)
|
||||
{
|
||||
$this->appSecret = $appSecret;
|
||||
$this->gatewayUri = 'https://api.Trimepay.com/gateway/';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @name 准备签名/验签字符串
|
||||
*/
|
||||
public function prepareSign($data)
|
||||
{
|
||||
ksort($data);
|
||||
return http_build_query($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name 生成签名
|
||||
* @param sourceData
|
||||
* @return 签名数据
|
||||
*/
|
||||
public function sign($data)
|
||||
{
|
||||
return strtolower(md5(md5($data) . $this->appSecret));
|
||||
}
|
||||
|
||||
/*
|
||||
* @name 验证签名
|
||||
* @param signData 签名数据
|
||||
* @param sourceData 原数据
|
||||
* @return
|
||||
*/
|
||||
public function verify($data, $signature)
|
||||
{
|
||||
$mySign = $this->sign($data);
|
||||
return $mySign === $signature;
|
||||
}
|
||||
|
||||
public function post($data, $type = 'pay')
|
||||
{
|
||||
if ($type == 'pay') {
|
||||
$this->gatewayUri .= 'pay/go';
|
||||
} elseif ($type == 'refund') {
|
||||
$this->gatewayUri .= 'refund/go';
|
||||
} elseif ($type == 'pre') {
|
||||
$this->gatewayUri .= 'pay/pre';
|
||||
} else {
|
||||
$this->gatewayUri .= 'query/go';
|
||||
}
|
||||
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_URL, $this->gatewayUri);
|
||||
curl_setopt($curl, CURLOPT_HEADER, 0);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($curl, CURLOPT_POST, 1);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||
$data = curl_exec($curl);
|
||||
curl_close($curl);
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
public function purchase($request, $response, $args)
|
||||
{
|
||||
$price = $request->getParam('price');
|
||||
$type = $request->getParam('type');
|
||||
|
||||
|
||||
if ($price <= 0) {
|
||||
return json_encode(['code' => -1, 'errmsg' => '非法的金额.']);
|
||||
}
|
||||
$user = Auth::getUser();
|
||||
$pl = new Paylist();
|
||||
$pl->userid = $user->id;
|
||||
$pl->total = $price;
|
||||
$pl->tradeno = self::generateGuid();
|
||||
$pl->save();
|
||||
|
||||
|
||||
$data['appId'] = Config::get('trimepay_appid');
|
||||
$data['payType'] = $type;
|
||||
$data['merchantTradeNo'] = $pl->tradeno;
|
||||
$data['totalFee'] = (float)$price * 100;
|
||||
$data['notifyUrl'] = Config::get('baseUrl') . '/payment/notify';
|
||||
$data['returnUrl'] = Config::get('baseUrl') . '/user/payment/return';
|
||||
$params = $this->prepareSign($data);
|
||||
$data['sign'] = $this->sign($params);
|
||||
switch ($type) {
|
||||
case ('WEPAY_JSAPI'):
|
||||
$result = json_decode($this->post($data, $type = 'pre'), true);
|
||||
break;
|
||||
default:
|
||||
$result = json_decode($this->post($data), true);
|
||||
}
|
||||
$result['pid'] = $pl->tradeno;
|
||||
return json_encode($result);
|
||||
}
|
||||
|
||||
public function query($tradeNo)
|
||||
{
|
||||
$data['appId'] = Config::get('trimepay_appid');
|
||||
$data['merchantTradeNo'] = $tradeNo;
|
||||
$params = $this->prepareSign($data);
|
||||
$data['sign'] = $this->sign($params);
|
||||
return json_decode($this->post($data, $type = 'query'), true);
|
||||
}
|
||||
|
||||
public function notify($request, $response, $args)
|
||||
{
|
||||
$data = array();
|
||||
$data['payStatus'] = $request->getParam('payStatus');
|
||||
$data['payFee'] = $request->getParam('payFee');
|
||||
$data['callbackTradeNo'] = $request->getParam('callbackTradeNo');
|
||||
$data['payType'] = $request->getParam('payType');
|
||||
$data['merchantTradeNo'] = $request->getParam('merchantTradeNo');
|
||||
|
||||
//file_put_contents(BASE_PATH.'/storage/trimepay_notify.log', json_encode($data)."\r\n", FILE_APPEND);
|
||||
// 准备待签名数据
|
||||
$str_to_sign = $this->prepareSign($data);
|
||||
// 验证签名
|
||||
$resultVerify = $this->verify($str_to_sign, $request->getParam('sign'));
|
||||
if ($resultVerify) {
|
||||
//file_put_contents('./trimepay_notify_success.log', json_encode($data)."\r\n", FILE_APPEND);
|
||||
$this->postPayment($data['merchantTradeNo'], 'TrimePay');
|
||||
echo 'SUCCESS';
|
||||
} else {
|
||||
echo 'FAIL';
|
||||
}
|
||||
}
|
||||
|
||||
public function refund($merchantTradeNo)
|
||||
{
|
||||
$data['appId'] = Config::get('trimepay_appid');
|
||||
$data['merchantTradeNo'] = $merchantTradeNo;
|
||||
$params = $this->prepareSign($data);
|
||||
$data['sign'] = $this->sign($params);
|
||||
|
||||
return $this->post($data, 'refund');
|
||||
}
|
||||
|
||||
|
||||
public function getPurchaseHTML()
|
||||
{
|
||||
return View::getSmarty()->fetch('user/trimepay.tpl');
|
||||
}
|
||||
|
||||
public function getReturnHTML($request, $response, $args)
|
||||
{
|
||||
$pid = $_GET['merchantTradeNo'];
|
||||
$p = Paylist::where('tradeno', '=', $pid)->first();
|
||||
$money = $p->total;
|
||||
if ($p->status == 1) {
|
||||
$success = 1;
|
||||
} else {
|
||||
$data = array();
|
||||
$data['payStatus'] = $request->getParam('payStatus');
|
||||
$data['payFee'] = $request->getParam('payFee');
|
||||
$data['callbackTradeNo'] = $request->getParam('callbackTradeNo');
|
||||
$data['payType'] = $request->getParam('payType');
|
||||
$data['merchantTradeNo'] = $request->getParam('merchantTradeNo');
|
||||
// 准备待签名数据
|
||||
$str_to_sign = $this->prepareSign($data);
|
||||
// 验证签名
|
||||
$resultVerify = $this->verify($str_to_sign, $request->getParam('sign'));
|
||||
if ($resultVerify) {
|
||||
$this->postPayment($data['merchantTradeNo'], 'TrimePay');
|
||||
$success = 1;
|
||||
} else {
|
||||
$success = 0;
|
||||
}
|
||||
}
|
||||
return View::getSmarty()->assign('money', $money)->assign('success', $success)->fetch('user/pay_success.tpl');
|
||||
}
|
||||
|
||||
public function getStatus($request, $response, $args)
|
||||
{
|
||||
$return = [];
|
||||
$p = Paylist::where('tradeno', $_POST['pid'])->first();
|
||||
$return['ret'] = 1;
|
||||
$return['result'] = $p->status;
|
||||
return json_encode($return);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Slim\App;
|
||||
use Zeuxisoo\Whoops\Provider\Slim\WhoopsMiddleware;
|
||||
|
||||
/***
|
||||
* The slim documents: http://www.slimframework.com/docs/objects/router.html
|
||||
*/
|
||||
class Slim
|
||||
{
|
||||
public $app;
|
||||
|
||||
public function newApp()
|
||||
{
|
||||
// config
|
||||
$debug = false;
|
||||
if (defined('DEBUG')) {
|
||||
$debug = true;
|
||||
}
|
||||
|
||||
// Make a Slim App
|
||||
$app = new App([
|
||||
'settings' => [
|
||||
'debug' => $debug,
|
||||
'whoops.editor' => 'sublime',
|
||||
'displayErrorDetails' => $debug
|
||||
]
|
||||
]);
|
||||
$app->add(new WhoopsMiddleware());
|
||||
$this->app = $app;
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
$this->app->run();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Token;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
abstract class Base
|
||||
{
|
||||
abstract public function store($token, User $user, $expireTime);
|
||||
|
||||
abstract public function delete($token);
|
||||
|
||||
abstract public function get($token);
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Services\Token;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Token as TokenModel;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
|
||||
class DB extends Base
|
||||
{
|
||||
public function store($tokenStr, User $user, $expireTime)
|
||||
{
|
||||
$token = new TokenModel();
|
||||
$token->token = $tokenStr;
|
||||
$token->user_id = $user->id;
|
||||
$token->create_time = time();
|
||||
$token->expire_time = $expireTime;
|
||||
if ($token->save()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function delete($token)
|
||||
{
|
||||
$token = TokenModel::where('token', $token)->first();
|
||||
if ($token == null) {
|
||||
return false;
|
||||
}
|
||||
$token->delete();
|
||||
return true;
|
||||
}
|
||||
|
||||
public function get($token)
|
||||
{
|
||||
try {
|
||||
$tokenModel = TokenModel::where('token', $token)->firstOrFail();
|
||||
} catch (ModelNotFoundException $e) {
|
||||
return null;
|
||||
}
|
||||
$token = new Token();
|
||||
$token->token = $tokenModel->token;
|
||||
$token->userId = $tokenModel->user_id;
|
||||
$token->createTime = $tokenModel->create_time;
|
||||
$token->expireTime = $tokenModel->expire_time;
|
||||
return $token;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Token;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\Aws\Factory;
|
||||
|
||||
class Dynamodb extends Base
|
||||
{
|
||||
protected $client;
|
||||
|
||||
protected $tableName = 'token';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->client = Factory::createDynamodb();
|
||||
$this->tableName = 'token';
|
||||
}
|
||||
|
||||
public function store($token, User $user, $expireTime)
|
||||
{
|
||||
$result = $this->client->putItem(array(
|
||||
'TableName' => $this->tableName,
|
||||
'Item' => array(
|
||||
'token' => array('S' => $token),
|
||||
'user_id' => array('N' => (string)$user->id),
|
||||
'create_time' => array('N' => (string)time()),
|
||||
'expire_time' => array('N' => (string)$expireTime)
|
||||
)
|
||||
));
|
||||
return true;
|
||||
}
|
||||
|
||||
public function delete($token)
|
||||
{
|
||||
$this->client->deleteItem(array(
|
||||
'TableName' => $this->tableName,
|
||||
'Key' => array(
|
||||
'token' => array('S' => $token),
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
public function get($token)
|
||||
{
|
||||
$result = $this->client->getItem(array(
|
||||
'ConsistentRead' => true,
|
||||
'TableName' => $this->tableName,
|
||||
'Key' => array(
|
||||
'token' => array('S' => $token),
|
||||
)
|
||||
));
|
||||
$token = new Token();
|
||||
$token->token = $result['Item']['token']['S'];
|
||||
$token->userId = $result['Item']['user_id']['N'];
|
||||
$token->createTime = $result['Item']['create_time']['N'];
|
||||
$token->expireTime = $result['Item']['expire_time']['N'];
|
||||
return $token;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Services\Token;
|
||||
|
||||
class Token
|
||||
{
|
||||
public $token;
|
||||
public $userId;
|
||||
public $createTime;
|
||||
public $expireTime;
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: rico93
|
||||
* Date: 2019/1/26
|
||||
* Time: 12:22
|
||||
*/
|
||||
|
||||
namespace App\Utils;
|
||||
|
||||
use RemotelyLiving\PHPDNS\Resolvers\GoogleDNS;
|
||||
class DNSoverHTTPS
|
||||
{
|
||||
public static function gethostbyName($hostname){
|
||||
$resolver = new GoogleDNS();
|
||||
return $resolver->getARecords($hostname)->pickFirst()->toArray()["IPAddress"];
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,179 @@
|
||||
<?php
|
||||
|
||||
namespace App\Utils;
|
||||
/**
|
||||
* Made By Leo
|
||||
* 黛米付接口
|
||||
* 2.1.4版本
|
||||
* 适用于 V1 API 黛米付面板V1
|
||||
* copyright all rights reserved
|
||||
*/
|
||||
|
||||
use App\Services\View;
|
||||
use App\Services\Auth;
|
||||
use App\Services\Config;
|
||||
use App\Models\User;
|
||||
use App\Models\Code;
|
||||
use App\Models\Paylist;
|
||||
use App\Models\Payback;
|
||||
|
||||
class DoiAMPay
|
||||
{
|
||||
|
||||
|
||||
public static function render()
|
||||
{
|
||||
return View::getSmarty()->assign('enabled', Config::get('doiampay')['enabled'])->fetch('user/doiam.tpl');
|
||||
}
|
||||
|
||||
public function handle($request, $response, $args)
|
||||
{
|
||||
$type = $request->getParam('type');
|
||||
$price = $request->getParam('price');
|
||||
if (Config::get('doiampay')['enabled'][$type] == 0) {
|
||||
return json_encode(['errcode' => -1, 'errmsg' => '非法的支付方式.']);
|
||||
}
|
||||
if ($price <= 0) {
|
||||
return json_encode(['errcode' => -1, 'errmsg' => '非法的金额.']);
|
||||
}
|
||||
$user = Auth::getUser();
|
||||
$settings = Config::get('doiampay')['mchdata'][$type];
|
||||
$pl = new Paylist();
|
||||
$pl->userid = $user->id;
|
||||
$pl->total = $price;
|
||||
$pl->save();
|
||||
$data = [
|
||||
'trade' => $pl->id,
|
||||
'price' => $price,
|
||||
'phone' => $settings['phone'],
|
||||
'mchid' => $settings['mchid'],
|
||||
'subject' => Config::get('appName') . '充值' . $price . '元',
|
||||
'body' => Config::get('appName') . '充值' . $price . '元',
|
||||
'type' => 'Mod',
|
||||
];
|
||||
$data = DoiAM::sign($data, $settings['token']);
|
||||
$ret = DoiAM::post('https://api.daimiyun.cn/v2/' . $type . '/create', $data);
|
||||
$result = json_decode($ret, true);
|
||||
if ($result and $result['errcode'] == 0) {
|
||||
$result['pid'] = $pl->id;
|
||||
return json_Encode($result);
|
||||
}
|
||||
|
||||
return json_encode([
|
||||
'errcode' => -1,
|
||||
'errmsg' => '接口调用失败!' . $ret,
|
||||
]);
|
||||
}
|
||||
|
||||
public function status($request, $response, $args)
|
||||
{
|
||||
return json_encode(Paylist::find($_POST['pid']));
|
||||
}
|
||||
|
||||
public function handle_return($request, $response, $args)
|
||||
{
|
||||
$money = $_GET['money'];
|
||||
echo "您已经成功支付 $money 元,正在跳转..";
|
||||
echo <<<HTML
|
||||
<script>
|
||||
location.href="/user/code";
|
||||
</script>
|
||||
HTML;
|
||||
}
|
||||
|
||||
public function handle_callback($request, $response, $args)
|
||||
{
|
||||
$order_data = $_POST;
|
||||
$status = $order_data['status']; //获取传递过来的交易状态
|
||||
$invoiceid = $order_data['out_trade_no']; //订单号
|
||||
$transid = $order_data['trade_no']; //转账交易号
|
||||
$amount = $order_data['money']; //获取递过来的总价格
|
||||
if (!DoiAM::checksign($_POST, Config::get('doiampay')['mchdata'][$args['type']]['token'])) {
|
||||
return json_encode(array('errcode' => 2333));
|
||||
}
|
||||
if ($status == 'success') {
|
||||
$p = Paylist::find($invoiceid);
|
||||
if ($p->status == 1) {
|
||||
return json_encode(['errcode' => 0]);
|
||||
}
|
||||
$p->status = 1;
|
||||
$p->save();
|
||||
$user = User::find($p->userid);
|
||||
$user->money += $p->total;
|
||||
$user->save();
|
||||
$codeq = new Code();
|
||||
$codeq->code = ['wepay' => '微信', 'qqpay' => 'QQ支付', 'alipay' => '支付宝'][$args['type']] . '充值';
|
||||
$codeq->isused = 1;
|
||||
$codeq->type = -1;
|
||||
$codeq->number = $p->total;
|
||||
$codeq->usedatetime = date('Y-m-d H:i:s');
|
||||
$codeq->userid = $user->id;
|
||||
$codeq->save();
|
||||
if ($user->ref_by != '' && $user->ref_by != 0 && $user->ref_by != null) {
|
||||
$gift_user = User::where('id', '=', $user->ref_by)->first();
|
||||
$gift_user->money += ($codeq->number * (Config::get('code_payback') / 100));
|
||||
$gift_user->save();
|
||||
$Payback = new Payback();
|
||||
$Payback->total = $codeq->number;
|
||||
$Payback->userid = $user->id;
|
||||
$Payback->ref_by = $user->ref_by;
|
||||
$Payback->ref_get = $codeq->number * (Config::get('code_payback') / 100);
|
||||
$Payback->datetime = time();
|
||||
$Payback->save();
|
||||
}
|
||||
return json_encode(['errcode' => 0]);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
class DoiAM
|
||||
{
|
||||
public static function sort(&$array)
|
||||
{
|
||||
ksort($array);
|
||||
}
|
||||
|
||||
public static function getsign($array, $key)
|
||||
{
|
||||
unset($array['sign']);
|
||||
self::sort($array);
|
||||
$sss = http_build_query($array);
|
||||
$sign = hash('sha256', $sss . $key);
|
||||
$sign = sha1($sign . hash('sha256', $key));
|
||||
return $sign;
|
||||
}
|
||||
|
||||
public static function sign($array, $key)
|
||||
{
|
||||
$array['sign'] = self::getSign($array, $key);
|
||||
return $array;
|
||||
}
|
||||
|
||||
public static function checksign($array, $key)
|
||||
{
|
||||
$new = $array;
|
||||
$new = self::sign($new, $key);
|
||||
if (!isset($array['sign'])) {
|
||||
return false;
|
||||
}
|
||||
return $array['sign'] == $new['sign'];
|
||||
}
|
||||
|
||||
public static function post($url, $data = null)
|
||||
{
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
||||
if (!empty($data)) {
|
||||
curl_setopt($curl, CURLOPT_POST, 1);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||
}
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
$output = curl_exec($curl);
|
||||
curl_close($curl);
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,420 @@
|
||||
<?php
|
||||
|
||||
namespace App\Utils;
|
||||
|
||||
/**
|
||||
* Socket communication class.
|
||||
*
|
||||
* Originally designed for use with DirectAdmin's API, this class will fill any HTTP socket need.
|
||||
*
|
||||
* Very, very basic usage:
|
||||
* $Socket = new HTTPSocket;
|
||||
* echo $Socket->get('http://user:pass@somesite.com/somedir/some.file?query=string&this=that');
|
||||
*
|
||||
* @author Phi1 'l0rdphi1' Stier <l0rdphi1@liquenox.net>
|
||||
* @package HTTPSocket
|
||||
* @version 2.7.2
|
||||
* 2.7.2
|
||||
* added x-use-https header check
|
||||
* added max number of location redirects
|
||||
* added custom settable message if x-use-https is found, so users can be told where to set their scripts
|
||||
* if a redirect host is https, add ssl:// to remote_host
|
||||
* 2.7.1
|
||||
* added isset to headers['location'], line 306
|
||||
*/
|
||||
class HTTPSocket
|
||||
{
|
||||
public $version = '2.7.2';
|
||||
|
||||
/* all vars are private except $error, $query_cache, and $doFollowLocationHeader */
|
||||
|
||||
public $method = 'GET';
|
||||
|
||||
public $remote_host;
|
||||
public $remote_port;
|
||||
public $remote_uname;
|
||||
public $remote_passwd;
|
||||
|
||||
public $result;
|
||||
public $result_header;
|
||||
public $result_body;
|
||||
public $result_status_code;
|
||||
|
||||
public $lastTransferSpeed;
|
||||
|
||||
public $bind_host;
|
||||
|
||||
public $error = array();
|
||||
public $warn = array();
|
||||
public $query_cache = array();
|
||||
|
||||
public $doFollowLocationHeader = true;
|
||||
public $redirectURL;
|
||||
public $max_redirects = 5;
|
||||
public $ssl_setting_message = 'DirectAdmin appears to be using SSL. Change your script to connect to ssl://';
|
||||
|
||||
public $extra_headers = array();
|
||||
|
||||
/**
|
||||
* Create server "connection".
|
||||
*
|
||||
*/
|
||||
public function connect($host, $port = '')
|
||||
{
|
||||
if (!is_numeric($port)) {
|
||||
$port = 80;
|
||||
}
|
||||
|
||||
$this->remote_host = $host;
|
||||
$this->remote_port = $port;
|
||||
}
|
||||
|
||||
public function bind($ip = '')
|
||||
{
|
||||
if ($ip == '') {
|
||||
$ip = $_SERVER['SERVER_ADDR'];
|
||||
}
|
||||
|
||||
$this->bind_host = $ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the method being used to communicate.
|
||||
*
|
||||
* @param string|null request method. supports GET, POST, and HEAD. default is GET
|
||||
*/
|
||||
public function set_method($method = 'GET')
|
||||
{
|
||||
$this->method = strtoupper($method);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify a username and password.
|
||||
*
|
||||
* @param string|null username. defualt is null
|
||||
* @param string|null password. defualt is null
|
||||
*/
|
||||
public function set_login($uname = '', $passwd = '')
|
||||
{
|
||||
if ($uname !== '') {
|
||||
$this->remote_uname = $uname;
|
||||
}
|
||||
|
||||
if ($passwd !== '') {
|
||||
$this->remote_passwd = $passwd;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the server
|
||||
*
|
||||
* @param string containing properly formatted server API. See DA API docs and examples. Http:// URLs O.K. too.
|
||||
* @param string|array query to pass to url
|
||||
* @param int if connection KB/s drops below value here, will drop connection
|
||||
*/
|
||||
public function query($request, $content = '', $doSpeedCheck = 0)
|
||||
{
|
||||
$this->error = $this->warn = array();
|
||||
$this->result_status_code = null;
|
||||
|
||||
// is our request a http:// ... ?
|
||||
if (preg_match('!^http://!i', $request) || preg_match('!^https://!i', $request)) {
|
||||
$location = parse_url($request);
|
||||
if (preg_match('!^https://!i', $request)) {
|
||||
$this->connect('ssl://' . $location['host'], $location['port']);
|
||||
} else {
|
||||
$this->connect($location['host'], $location['port']);
|
||||
}
|
||||
$this->set_login($location['user'], $location['pass']);
|
||||
|
||||
$request = $location['path'];
|
||||
$content = $location['query'];
|
||||
|
||||
|
||||
if ($request == '') {
|
||||
$request = '/';
|
||||
}
|
||||
}
|
||||
|
||||
$array_headers = array(
|
||||
'User-Agent' => "HTTPSocket/$this->version",
|
||||
'Host' => $this->remote_port == 80 ? $this->remote_host : "$this->remote_host:$this->remote_port",
|
||||
'Accept' => '*/*',
|
||||
'Connection' => 'Close');
|
||||
|
||||
foreach ($this->extra_headers as $key => $value) {
|
||||
$array_headers[$key] = $value;
|
||||
}
|
||||
|
||||
$this->result = $this->result_header = $this->result_body = '';
|
||||
|
||||
// was content sent as an array? if so, turn it into a string
|
||||
if (is_array($content)) {
|
||||
$pairs = array();
|
||||
|
||||
foreach ($content as $key => $value) {
|
||||
$pairs[] = "$key=" . urlencode($value);
|
||||
}
|
||||
|
||||
$content = implode('&', $pairs);
|
||||
unset($pairs);
|
||||
}
|
||||
|
||||
$OK = true;
|
||||
|
||||
// instance connection
|
||||
if ($this->bind_host) {
|
||||
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
|
||||
socket_bind($socket, $this->bind_host);
|
||||
|
||||
if (!@socket_connect($socket, $this->remote_host, $this->remote_port)) {
|
||||
$OK = false;
|
||||
}
|
||||
} else {
|
||||
$socket = @fsockopen($this->remote_host, $this->remote_port, $sock_errno, $sock_errstr, 10);
|
||||
}
|
||||
|
||||
if (!$socket || !$OK) {
|
||||
$this->error[] = "Can't create socket connection to $this->remote_host:$this->remote_port.";
|
||||
return 0;
|
||||
}
|
||||
|
||||
// if we have a username and password, add the header
|
||||
if (isset($this->remote_uname, $this->remote_passwd)) {
|
||||
$array_headers['Authorization'] = 'Basic ' . base64_encode("$this->remote_uname:$this->remote_passwd");
|
||||
}
|
||||
|
||||
// for DA skins: if $this->remote_passwd is NULL, try to use the login key system
|
||||
if (isset($this->remote_uname) && $this->remote_passwd == null) {
|
||||
$array_headers['Cookie'] = "session={$_SERVER['SESSION_ID']}; key={$_SERVER['SESSION_KEY']}";
|
||||
}
|
||||
|
||||
// if method is POST, add content length & type headers
|
||||
if ($this->method == 'POST') {
|
||||
$array_headers['Content-type'] = 'application/x-www-form-urlencoded';
|
||||
$array_headers['Content-length'] = strlen($content);
|
||||
} // else method is GET or HEAD. we don't support anything else right now.
|
||||
elseif ($content) {
|
||||
$request .= "?$content";
|
||||
}
|
||||
|
||||
// prepare query
|
||||
$query = "$this->method $request HTTP/1.0\r\n";
|
||||
foreach ($array_headers as $key => $value) {
|
||||
$query .= "$key: $value\r\n";
|
||||
}
|
||||
$query .= "\r\n";
|
||||
|
||||
// if POST we need to append our content
|
||||
if ($this->method == 'POST' && $content) {
|
||||
$query .= "$content\r\n\r\n";
|
||||
}
|
||||
|
||||
// query connection
|
||||
if ($this->bind_host) {
|
||||
socket_write($socket, $query);
|
||||
|
||||
// now load results
|
||||
while ($out = socket_read($socket, 2048)) {
|
||||
$this->result .= $out;
|
||||
}
|
||||
} else {
|
||||
fwrite($socket, $query, strlen($query));
|
||||
|
||||
// now load results
|
||||
$this->lastTransferSpeed = 0;
|
||||
$status = stream_get_meta_data($socket);
|
||||
$startTime = time();
|
||||
$length = 0;
|
||||
$prevSecond = 0;
|
||||
while (!feof($socket) && !$status['timed_out']) {
|
||||
$chunk = fgets($socket, 1024);
|
||||
$length += strlen($chunk);
|
||||
$this->result .= $chunk;
|
||||
|
||||
$elapsedTime = time() - $startTime;
|
||||
|
||||
if ($elapsedTime > 0) {
|
||||
$this->lastTransferSpeed = ($length / 1024) / $elapsedTime;
|
||||
}
|
||||
|
||||
if ($doSpeedCheck > 0 && $elapsedTime > 5 && $this->lastTransferSpeed < $doSpeedCheck) {
|
||||
$this->warn[] = 'kB/s for last 5 seconds is below 50 kB/s (~' . (($length / 1024) / $elapsedTime) . '), dropping connection...';
|
||||
$this->result_status_code = 503;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->lastTransferSpeed == 0) {
|
||||
$this->lastTransferSpeed = $length / 1024;
|
||||
}
|
||||
}
|
||||
|
||||
[$this->result_header, $this->result_body] = preg_split("/\r\n\r\n/", $this->result, 2);
|
||||
|
||||
if ($this->bind_host) {
|
||||
socket_close($socket);
|
||||
} else {
|
||||
fclose($socket);
|
||||
}
|
||||
|
||||
$this->query_cache[] = $query;
|
||||
|
||||
|
||||
$headers = $this->fetch_header();
|
||||
|
||||
// what return status did we get?
|
||||
if (!$this->result_status_code) {
|
||||
preg_match("#HTTP/1\.. (\d+)#", $headers[0], $matches);
|
||||
$this->result_status_code = $matches[1];
|
||||
}
|
||||
|
||||
// did we get the full file?
|
||||
if (!empty($headers['content-length']) && $headers['content-length'] != strlen($this->result_body)) {
|
||||
$this->result_status_code = 206;
|
||||
}
|
||||
|
||||
// now, if we're being passed a location header, should we follow it?
|
||||
if ($this->doFollowLocationHeader) {
|
||||
//dont bother if we didn't even setup the script correctly
|
||||
if (isset($headers['x-use-https']) && $headers['x-use-https'] == 'yes') {
|
||||
die($this->ssl_setting_message);
|
||||
}
|
||||
|
||||
if (isset($headers['location'])) {
|
||||
if ($this->max_redirects <= 0) {
|
||||
die('Too many redirects on: ' . $headers['location']);
|
||||
}
|
||||
|
||||
$this->max_redirects--;
|
||||
$this->redirectURL = $headers['location'];
|
||||
$this->query($headers['location']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getTransferSpeed()
|
||||
{
|
||||
return $this->lastTransferSpeed;
|
||||
}
|
||||
|
||||
/**
|
||||
* The quick way to get a URL's content :)
|
||||
*
|
||||
* @param string URL
|
||||
* @param boolean return as array? (like PHP's file() command)
|
||||
* @return string result body
|
||||
*/
|
||||
public function get($location, $asArray = false)
|
||||
{
|
||||
$this->query($location);
|
||||
|
||||
if ($this->get_status_code() == 200) {
|
||||
if ($asArray) {
|
||||
return explode("\n", $this->fetch_body());
|
||||
}
|
||||
|
||||
return $this->fetch_body();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last status code.
|
||||
* 200 = OK;
|
||||
* 403 = FORBIDDEN;
|
||||
* etc.
|
||||
*
|
||||
* @return int status code
|
||||
*/
|
||||
public function get_status_code()
|
||||
{
|
||||
return $this->result_status_code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a header, sent with the next query.
|
||||
*
|
||||
* @param string header name
|
||||
* @param string header value
|
||||
*/
|
||||
public function add_header($key, $value)
|
||||
{
|
||||
$this->extra_headers[$key] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears any extra headers.
|
||||
*
|
||||
*/
|
||||
public function clear_headers()
|
||||
{
|
||||
$this->extra_headers = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the result of a query.
|
||||
*
|
||||
* @return string result
|
||||
*/
|
||||
public function fetch_result()
|
||||
{
|
||||
return $this->result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the header of result (stuff before body).
|
||||
*
|
||||
* @param string (optional) header to return
|
||||
* @return array result header
|
||||
*/
|
||||
public function fetch_header($header = '')
|
||||
{
|
||||
$array_headers = preg_split("/\r\n/", $this->result_header);
|
||||
|
||||
$array_return = array(0 => $array_headers[0]);
|
||||
unset($array_headers[0]);
|
||||
|
||||
foreach ($array_headers as $pair) {
|
||||
[$key, $value] = explode(': ', $pair, 2);
|
||||
$array_return[strtolower($key)] = $value;
|
||||
}
|
||||
|
||||
if ($header != '') {
|
||||
return $array_return[strtolower($header)];
|
||||
}
|
||||
|
||||
return $array_return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the body of result (stuff after header).
|
||||
*
|
||||
* @return string result body
|
||||
*/
|
||||
public function fetch_body()
|
||||
{
|
||||
return $this->result_body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return parsed body in array format.
|
||||
*
|
||||
* @return array result parsed
|
||||
*/
|
||||
public function fetch_parsed_body()
|
||||
{
|
||||
parse_str($this->result_body, $x);
|
||||
return $x;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set a specifc message on how to change the SSL setting, in the event that it's not set correctly.
|
||||
*/
|
||||
public function set_ssl_setting_message($str)
|
||||
{
|
||||
$this->ssl_setting_message = $str;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Utils;
|
||||
|
||||
|
||||
class Helper
|
||||
{
|
||||
public static function getParam($request, $queryString): ?string
|
||||
{
|
||||
return $request->getQueryParams()[$queryString] ?? null;
|
||||
}
|
||||
|
||||
public static function getData($request, $name)
|
||||
{
|
||||
return $request->getParsedBody()[$name];
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Utils;
|
||||
|
||||
class Pay
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
@ -1,27 +1,88 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Utils;
|
||||
|
||||
use App\Services\Config;
|
||||
use Zxing\QrReader;
|
||||
use ZBarCodeImage;
|
||||
use ZBarCodeScanner;
|
||||
|
||||
class QRcode
|
||||
{
|
||||
/**
|
||||
* Decode QR code
|
||||
*
|
||||
* @param string $source QR code source url/path
|
||||
*
|
||||
* @return string|null Decoded string, null for empty
|
||||
*/
|
||||
public static function decode(string $source)
|
||||
public static function decode($url)
|
||||
{
|
||||
$img = file_get_contents($source);
|
||||
$qrcode = new QrReader($img, QrReader::SOURCE_TYPE_BLOB);
|
||||
$text = $qrcode->text();
|
||||
if ($text == false || $text == '') {
|
||||
switch (Config::get('qrcode')) {
|
||||
case 'phpzbar':
|
||||
return self::phpzbar_decode($url);
|
||||
case 'online':
|
||||
return self::online_decode($url);
|
||||
case 'zxing_local':
|
||||
return self::zxing_local_decode($url);
|
||||
default:
|
||||
return self::zxing_decode($url);
|
||||
}
|
||||
}
|
||||
|
||||
public static function online_decode($url)
|
||||
{
|
||||
$data = array();
|
||||
$data['fileurl'] = $url;
|
||||
$param = http_build_query($data, '', '&');
|
||||
|
||||
$sock = new HTTPSocket();
|
||||
$sock->connect('api.qrserver.com', 80);
|
||||
$sock->set_method('GET');
|
||||
$sock->query('/v1/read-qr-code/', $param);
|
||||
|
||||
$raw_text = $sock->fetch_body();
|
||||
$result_array = json_decode($raw_text, true);
|
||||
if (isset($result_array[0])) {
|
||||
return $result_array[0]['symbol'][0]['data'];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function phpzbar_decode($url)
|
||||
{
|
||||
$filepath = BASE_PATH . '/storage/' . time() . random_int(1, 100) . '.png';
|
||||
$img = file_get_contents($url);
|
||||
file_put_contents($filepath, $img);
|
||||
|
||||
/* Create new image object */
|
||||
$image = new ZBarCodeImage($filepath);
|
||||
|
||||
/* Create a barcode scanner */
|
||||
$scanner = new ZBarCodeScanner();
|
||||
|
||||
/* Scan the image */
|
||||
$barcode = $scanner->scan($image);
|
||||
|
||||
unlink($filepath);
|
||||
|
||||
return ($barcode[0]['data'] ?? null);
|
||||
}
|
||||
|
||||
public static function zxing_local_decode($url)
|
||||
{
|
||||
$filepath = BASE_PATH . '/storage/' . time() . random_int(1, 100) . '.png';
|
||||
$img = file_get_contents($url);
|
||||
file_put_contents($filepath, $img);
|
||||
|
||||
$qrcode = new QrReader($filepath);
|
||||
$text = $qrcode->text(); //return decoded text from QR Code
|
||||
|
||||
unlink($filepath);
|
||||
|
||||
if ($text == null || $text == '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
public static function zxing_decode($url)
|
||||
{
|
||||
$raw_text = file_get_contents('https://zxing.org/w/decode?u=' . urlencode($url));
|
||||
return Tools::get_middle_text($raw_text, '<tr><td>Raw text</td><td><pre>', '</pre></td></tr><tr><td>Raw bytes</td><td><pre>');
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Utils;
|
||||
|
||||
class Response
|
||||
{
|
||||
public static function redirect($response, $to)
|
||||
{
|
||||
return $response->withStatus(302)->withHeader('Location', $to);
|
||||
}
|
||||
}
|
||||
@ -1,84 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Utils\Telegram\Commands;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\Config;
|
||||
use Telegram\Bot\Actions;
|
||||
use Telegram\Bot\Commands\Command;
|
||||
|
||||
/**
|
||||
* Class CheckinCommand.
|
||||
*/
|
||||
class CheckinCommand extends Command
|
||||
{
|
||||
/**
|
||||
* @var string Command Name
|
||||
*/
|
||||
protected $name = 'checkin';
|
||||
|
||||
/**
|
||||
* @var string Command Description
|
||||
*/
|
||||
protected $description = '';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function handle($arguments)
|
||||
{
|
||||
$Update = $this->getUpdate();
|
||||
$Message = $Update->getMessage();
|
||||
|
||||
// 消息会话 ID
|
||||
$ChatID = $Message->getChat()->getId();
|
||||
|
||||
if ($ChatID < 0) {
|
||||
// 群组
|
||||
if (Config::get('new_telegram_group_quiet') === true) {
|
||||
// 群组中不回应
|
||||
return;
|
||||
}
|
||||
if ($ChatID != Config::get('new_telegram_group_chatid')) {
|
||||
// 非我方群组
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 发送 '输入中' 会话状态
|
||||
$this->replyWithChatAction(['action' => Actions::TYPING]);
|
||||
|
||||
// 触发用户
|
||||
$SendUser = [
|
||||
'id' => $Message->getFrom()->getId(),
|
||||
'name' => $Message->getFrom()->getFirstName() . ' ' . $Message->getFrom()->getLastName(),
|
||||
'username' => $Message->getFrom()->getUsername(),
|
||||
];
|
||||
|
||||
$User = User::where('telegram_id', $SendUser['id'])->first();
|
||||
if ($User == null) {
|
||||
// 回送信息
|
||||
$this->replyWithMessage(
|
||||
[
|
||||
'text' => '您未绑定本站账号,您可以进入网站的 **资料编辑**,在右下方绑定您的账号.',
|
||||
'parse_mode' => 'Markdown',
|
||||
]
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$checkin = $User->checkin();
|
||||
|
||||
$text = [
|
||||
$checkin['msg']
|
||||
];
|
||||
|
||||
// 回送信息
|
||||
$this->replyWithMessage(
|
||||
[
|
||||
'text' => implode(PHP_EOL, $text),
|
||||
'parse_mode' => 'Markdown',
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1,87 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Utils\Telegram\Commands;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\Config;
|
||||
use App\Utils\Telegram\{Process, Reply};
|
||||
use Telegram\Bot\Actions;
|
||||
use Telegram\Bot\Commands\Command;
|
||||
|
||||
/**
|
||||
* Class HelpCommand.
|
||||
*/
|
||||
class HelpCommand extends Command
|
||||
{
|
||||
/**
|
||||
* @var string Command Name
|
||||
*/
|
||||
protected $name = 'help';
|
||||
|
||||
/**
|
||||
* @var string Command Description
|
||||
*/
|
||||
protected $description = '菜单';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function handle($arguments)
|
||||
{
|
||||
$Update = $this->getUpdate();
|
||||
$Message = $Update->getMessage();
|
||||
|
||||
// 消息会话 ID
|
||||
$ChatID = $Message->getChat()->getId();
|
||||
|
||||
if ($ChatID > 0) {
|
||||
// 私人会话
|
||||
|
||||
// 发送 '输入中' 会话状态
|
||||
$this->replyWithChatAction(['action' => Actions::TYPING]);
|
||||
|
||||
// 触发用户
|
||||
$SendUser = [
|
||||
'id' => $Message->getFrom()->getId(),
|
||||
'name' => $Message->getFrom()->getFirstName() . ' ' . $Message->getFrom()->getLastName(),
|
||||
'username' => $Message->getFrom()->getUsername(),
|
||||
];
|
||||
|
||||
$user = Process::getUser($SendUser['id']);
|
||||
|
||||
$reply = Reply::getInlinekeyboard($user, 'index');
|
||||
|
||||
// 回送信息
|
||||
$this->replyWithMessage(
|
||||
[
|
||||
'text' => $reply['text'],
|
||||
'parse_mode' => 'Markdown',
|
||||
'disable_web_page_preview' => false,
|
||||
'reply_to_message_id' => null,
|
||||
'reply_markup' => json_encode(
|
||||
[
|
||||
'inline_keyboard' => $reply['keyboard']
|
||||
]
|
||||
),
|
||||
]
|
||||
);
|
||||
} else {
|
||||
// 群组
|
||||
|
||||
if (Config::get('new_telegram_group_quiet') === true || strpos($Message->getText(), '/' . $this->name) !== 0) {
|
||||
// 群组中不回应
|
||||
return;
|
||||
}
|
||||
|
||||
// 发送 '输入中' 会话状态
|
||||
$this->replyWithChatAction(['action' => Actions::TYPING]);
|
||||
|
||||
// 回送信息
|
||||
$this->replyWithMessage(
|
||||
[
|
||||
'text' => '喵?',
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,102 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Utils\Telegram\Commands;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\Config;
|
||||
use App\Utils\TelegramSessionManager;
|
||||
use Telegram\Bot\Actions;
|
||||
use Telegram\Bot\Commands\Command;
|
||||
|
||||
/**
|
||||
* Class StratCommand.
|
||||
*/
|
||||
class StartCommand extends Command
|
||||
{
|
||||
/**
|
||||
* @var string Command Name
|
||||
*/
|
||||
protected $name = 'start';
|
||||
|
||||
/**
|
||||
* @var string Command Description
|
||||
*/
|
||||
protected $description = 'Start Command to get you started';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function handle($arguments)
|
||||
{
|
||||
$Update = $this->getUpdate();
|
||||
$Message = $Update->getMessage();
|
||||
|
||||
// 消息会话 ID
|
||||
$ChatID = $Message->getChat()->getId();
|
||||
|
||||
if ($ChatID > 0) {
|
||||
// 私人会话
|
||||
|
||||
// 发送 '输入中' 会话状态
|
||||
$this->replyWithChatAction(['action' => Actions::TYPING]);
|
||||
|
||||
// 触发用户
|
||||
$SendUser = [
|
||||
'id' => $Message->getFrom()->getId(),
|
||||
'name' => $Message->getFrom()->getFirstName() . ' ' . $Message->getFrom()->getLastName(),
|
||||
'username' => $Message->getFrom()->getUsername(),
|
||||
];
|
||||
// 消息内容
|
||||
$MessageText = trim($arguments);
|
||||
if ($MessageText != '') {
|
||||
$BindCode = $MessageText;
|
||||
if (strlen($BindCode) == 16) {
|
||||
$Uid = TelegramSessionManager::verify_bind_session($BindCode);
|
||||
if ($Uid == 0) {
|
||||
$text = '绑定失败了呢,经检查发现:【' . $BindCode . '】的有效期为 10 分钟,您可以在我们网站上的 **资料编辑** 页面刷新后重试.';
|
||||
} else {
|
||||
$BinsUser = User::where('id', $Uid)->first();
|
||||
$BinsUser->telegram_id = $SendUser['id'];
|
||||
$BinsUser->im_type = 4;
|
||||
$BinsUser->im_value = $SendUser['username'];
|
||||
$BinsUser->save();
|
||||
if ($BinsUser->is_admin >= 1) {
|
||||
$text = '尊敬的**管理员**您好,恭喜绑定成功。' . PHP_EOL .'当前绑定邮箱为:' . $BinsUser->email;
|
||||
} else {
|
||||
if ($BinsUser->class >= 1) {
|
||||
$text = '尊敬的 **VIP ' . $BinsUser->class . '** 用户您好.' . PHP_EOL . '恭喜您绑定成功,当前绑定邮箱为:' . $BinsUser->email;
|
||||
} else {
|
||||
$text = '绑定成功了,您的邮箱为:' . $BinsUser->email;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 回送信息
|
||||
$this->replyWithMessage(
|
||||
[
|
||||
'text' => $text,
|
||||
'parse_mode' => 'Markdown',
|
||||
]
|
||||
);
|
||||
}
|
||||
// 触发 /help
|
||||
$this->triggerCommand('help');
|
||||
} else {
|
||||
// 群组
|
||||
|
||||
if (Config::get('new_telegram_group_quiet') === true) {
|
||||
// 群组中不回应
|
||||
return;
|
||||
}
|
||||
|
||||
// 发送 '输入中' 会话状态
|
||||
$this->replyWithChatAction(['action' => Actions::TYPING]);
|
||||
// 回送信息
|
||||
$this->replyWithMessage(
|
||||
[
|
||||
'text' => '喵喵喵.',
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,99 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Utils\Telegram\Commands;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\Config;
|
||||
use Telegram\Bot\Actions;
|
||||
use Telegram\Bot\Commands\Command;
|
||||
|
||||
/**
|
||||
* Class UnbindCommand.
|
||||
*/
|
||||
class UnbindCommand extends Command
|
||||
{
|
||||
/**
|
||||
* @var string Command Name
|
||||
*/
|
||||
protected $name = 'unbind';
|
||||
|
||||
/**
|
||||
* @var string Command Description
|
||||
*/
|
||||
protected $description = '';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function handle($arguments)
|
||||
{
|
||||
$Update = $this->getUpdate();
|
||||
$Message = $Update->getMessage();
|
||||
|
||||
// 消息 ID
|
||||
$MessageID = $Message->getMessageId();
|
||||
|
||||
// 消息会话 ID
|
||||
$ChatID = $Message->getChat()->getId();
|
||||
|
||||
// 触发用户
|
||||
$SendUser = [
|
||||
'id' => $Message->getFrom()->getId(),
|
||||
'name' => $Message->getFrom()->getFirstName() . ' ' . $Message->getFrom()->getLastName(),
|
||||
'username' => $Message->getFrom()->getUsername(),
|
||||
];
|
||||
|
||||
$User = User::where('telegram_id', $SendUser['id'])->first();
|
||||
|
||||
if ($ChatID > 0) {
|
||||
// 私人
|
||||
|
||||
// 发送 '输入中' 会话状态
|
||||
$this->replyWithChatAction(['action' => Actions::TYPING]);
|
||||
|
||||
if ($User == null) {
|
||||
// 回送信息
|
||||
$this->replyWithMessage(
|
||||
[
|
||||
'text' => '您未绑定本站账号,您可以进入网站的 **资料编辑**,在右下方绑定您的账号.',
|
||||
'parse_mode' => 'Markdown',
|
||||
]
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// 消息内容
|
||||
$MessageText = trim($arguments);
|
||||
|
||||
if ($MessageText == $User->email) {
|
||||
$User->telegram_id = 0;
|
||||
if ($User->save()) {
|
||||
$text = '解绑成功.';
|
||||
} else {
|
||||
$text = '解绑失败.';
|
||||
}
|
||||
// 回送信息
|
||||
$this->replyWithMessage(
|
||||
[
|
||||
'text' => $text,
|
||||
'parse_mode' => 'Markdown',
|
||||
]
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$text = '发送 **/unbind 账户邮箱** 进行解绑.';
|
||||
if ($MessageText != '') {
|
||||
$text = '键入的 Email 地址与您的账户不匹配.';
|
||||
}
|
||||
|
||||
// 回送信息
|
||||
$this->replyWithMessage(
|
||||
[
|
||||
'text' => $text,
|
||||
'parse_mode' => 'Markdown',
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,53 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Utils\Telegram;
|
||||
|
||||
use App\Utils\TelegramSessionManager;
|
||||
|
||||
class Message
|
||||
{
|
||||
public static function MessageMethod($user, $bot, $Message)
|
||||
{
|
||||
// 触发用户
|
||||
$SendUser = [
|
||||
'id' => $Message->getFrom()->getId(),
|
||||
'name' => $Message->getFrom()->getFirstName() . ' ' . $Message->getFrom()->getLastName(),
|
||||
'username' => $Message->getFrom()->getUsername(),
|
||||
];
|
||||
|
||||
// 消息会话 ID
|
||||
$ChatID = $Message->getChat()->getId();
|
||||
|
||||
// 消息内容
|
||||
$MessageData = $Message->getText();
|
||||
if ($MessageData != null) {
|
||||
$MessageData = trim($MessageData);
|
||||
if (is_numeric($MessageData) && strlen($MessageData) == 6) {
|
||||
if ($user != null) {
|
||||
$uid = TelegramSessionManager::verify_login_number($MessageData, $user->id);
|
||||
if ($uid != 0) {
|
||||
$bot->sendMessage(
|
||||
[
|
||||
'chat_id' => $ChatID,
|
||||
'text' => '登录验证成功,邮箱:' . $user->email,
|
||||
]
|
||||
);
|
||||
} else {
|
||||
$bot->sendMessage(
|
||||
[
|
||||
'chat_id' => $ChatID,
|
||||
'text' => '登录验证失败,数字无效',
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// // 图片内容
|
||||
// $PhotoData = $Message->getPhoto();
|
||||
// if ($PhotoData != null) {
|
||||
// }
|
||||
}
|
||||
}
|
||||
@ -1,68 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Utils\Telegram;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\Config;
|
||||
use Telegram\Bot\Api;
|
||||
use Exception;
|
||||
|
||||
class Process
|
||||
{
|
||||
public static function index()
|
||||
{
|
||||
try {
|
||||
$bot = new Api(Config::get('new_telegram_token'));
|
||||
$bot->addCommands(
|
||||
[
|
||||
Commands\HelpCommand::class,
|
||||
Commands\StartCommand::class,
|
||||
Commands\PingCommand::class,
|
||||
Commands\CheckinCommand::class,
|
||||
Commands\MyCommand::class,
|
||||
Commands\UnbindCommand::class,
|
||||
]
|
||||
);
|
||||
$update = $bot->commandsHandler(true);
|
||||
if ($update->getCallbackQuery() !== null) {
|
||||
$id = $update->getCallbackQuery()->getFrom()->getId();
|
||||
$user = self::getUser($id);
|
||||
Callback::CallbackQueryMethod($user, $bot, $update->getCallbackQuery());
|
||||
}
|
||||
if ($update->getMessage() !== null) {
|
||||
$id = $update->getMessage()->getFrom()->getId();
|
||||
$user = self::getUser($id);
|
||||
Message::MessageMethod($user, $bot, $update->getMessage());
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public static function getUser($telegram_id)
|
||||
{
|
||||
return User::where('telegram_id', $telegram_id)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a POST request to Telegram Bot API.
|
||||
* 伪异步,无结果返回.
|
||||
*
|
||||
* @param array $params
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function SendPost($Method, $Params)
|
||||
{
|
||||
$URL = 'https://api.telegram.org/bot' . Config::get('new_telegram_token') . '/' . $Method;
|
||||
$POSTData = json_encode($Params);
|
||||
$C = curl_init();
|
||||
curl_setopt($C, CURLOPT_URL, $URL);
|
||||
curl_setopt($C, CURLOPT_POST, 1);
|
||||
curl_setopt($C, CURLOPT_HTTPHEADER, ['Content-Type:application/json; charset=utf-8']);
|
||||
curl_setopt($C, CURLOPT_POSTFIELDS, $POSTData);
|
||||
curl_setopt($C, CURLOPT_TIMEOUT, 1);
|
||||
curl_exec($C);
|
||||
curl_close($C);
|
||||
}
|
||||
}
|
||||
@ -1,172 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Utils\Telegram;
|
||||
|
||||
class Reply
|
||||
{
|
||||
|
||||
public static function getInlinekeyboard($user = null, $type = null)
|
||||
{
|
||||
$back = [
|
||||
[
|
||||
'text' => '回主菜单',
|
||||
'callback_data' => 'index'
|
||||
]
|
||||
];
|
||||
if ($type === null) return $back;
|
||||
switch ($type) {
|
||||
case 'index':
|
||||
// 主菜单
|
||||
$notLogin = [
|
||||
[
|
||||
'text' => '产品介绍',
|
||||
'callback_data' => 'general.pricing'
|
||||
],
|
||||
[
|
||||
'text' => '服务条款',
|
||||
'callback_data' => 'general.terms'
|
||||
]
|
||||
];
|
||||
$isLogin = [
|
||||
[
|
||||
[
|
||||
'text' => '用户中心',
|
||||
'callback_data' => 'user.index'
|
||||
],
|
||||
[
|
||||
'text' => '资料编辑',
|
||||
'callback_data' => 'user.edit'
|
||||
],
|
||||
],
|
||||
[
|
||||
[
|
||||
'text' => '订阅中心',
|
||||
'callback_data' => 'user.subscribe'
|
||||
],
|
||||
[
|
||||
'text' => '分享计划',
|
||||
'callback_data' => 'user.invite'
|
||||
],
|
||||
],
|
||||
];
|
||||
if ($user != null) {
|
||||
if ($user->isAdmin()) {
|
||||
$text = '尊敬的管理员您好:';
|
||||
} else {
|
||||
if ($user->class > 0) {
|
||||
$text = '尊敬的 VIP ' . $user->class . '您好:';
|
||||
} else {
|
||||
$text = '尊敬的用户您好:';
|
||||
}
|
||||
}
|
||||
$return = [
|
||||
'text' => $text,
|
||||
'keyboard' => $isLogin,
|
||||
];
|
||||
} else {
|
||||
$text = '游客您好,以下是 BOT 菜单:' . PHP_EOL . PHP_EOL . '本站用户请前往用户中心进行 Telegram 绑定操作.';
|
||||
$return = [
|
||||
'text' => $text,
|
||||
'keyboard' => [
|
||||
$notLogin,
|
||||
],
|
||||
];
|
||||
}
|
||||
break;
|
||||
case 'user.index':
|
||||
// 用户中心
|
||||
if ($user->class > 0) {
|
||||
$text = '尊敬的 VIP ' . $user->class . ' 您好:';
|
||||
} else {
|
||||
$text = '尊敬的用户您好:';
|
||||
}
|
||||
$keyboard = [
|
||||
[
|
||||
[
|
||||
'text' => '登录记录',
|
||||
'callback_data' => 'user.index.login_log'
|
||||
],
|
||||
[
|
||||
'text' => '使用记录',
|
||||
'callback_data' => 'user.index.usage_log'
|
||||
],
|
||||
],
|
||||
[
|
||||
[
|
||||
'text' => '返利记录',
|
||||
'callback_data' => 'user.index.rebate_log'
|
||||
],
|
||||
[
|
||||
'text' => '订阅记录',
|
||||
'callback_data' => 'user.index.subscribe_log'
|
||||
],
|
||||
],
|
||||
$back
|
||||
];
|
||||
$text .= (PHP_EOL . PHP_EOL .
|
||||
'当前余额:' . $user->money .
|
||||
PHP_EOL .
|
||||
'在线设备:' . ($user->node_connector != 0 ? $user->online_ip_count() . ' / ' . $user->node_connector : $user->online_ip_count() . ' / 不限制') .
|
||||
PHP_EOL .
|
||||
'端口速率:' . ($user->node_speedlimit != 0 ? $user->node_speedlimit . 'Mbps' : '无限制') .
|
||||
PHP_EOL .
|
||||
'上次使用:' . $user->lastSsTime() .
|
||||
PHP_EOL .
|
||||
'过期时间:' . $user->class_expire);
|
||||
$return = [
|
||||
'text' => $text,
|
||||
'keyboard' => $keyboard,
|
||||
];
|
||||
break;
|
||||
case 'user.edit':
|
||||
// 资料编辑
|
||||
if ($user->class > 0) {
|
||||
$text = '尊敬的 VIP ' . $user->class . '您好:';
|
||||
} else {
|
||||
$text = '尊敬的用户您好:';
|
||||
}
|
||||
$keyboard = [
|
||||
[
|
||||
[
|
||||
'text' => '重置订阅链接',
|
||||
'callback_data' => 'user.edit.update_link'
|
||||
],
|
||||
[
|
||||
'text' => '重置链接密码',
|
||||
'callback_data' => 'user.edit.update_passwd'
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
'text' => '更改加密方式',
|
||||
'callback_data' => 'user.edit.encrypt'
|
||||
],
|
||||
[
|
||||
'text' => '更改协议类型',
|
||||
'callback_data' => 'user.edit.protocol'
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
'text' => '更改混淆类型',
|
||||
'callback_data' => 'user.edit.obfs'
|
||||
],
|
||||
],
|
||||
[
|
||||
[
|
||||
'text' => '每日邮件接收',
|
||||
'callback_data' => 'user.edit.sendemail'
|
||||
],
|
||||
],
|
||||
$back
|
||||
];
|
||||
$return = [
|
||||
'text' => $text,
|
||||
'keyboard' => $keyboard,
|
||||
];
|
||||
break;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue