308 lines
9.2 KiB
PHP
308 lines
9.2 KiB
PHP
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | 作者:修缘 联系QQ:278896498 QQ群:1054861244
|
||
// | 声明:未经作者许可,禁止倒卖等商业运营,违者必究
|
||
// | 另接php业务,网站制作、代理后台、gm后台、支付对接等
|
||
// +----------------------------------------------------------------------
|
||
// | 创建时间: 2022/1/5 13:10
|
||
// +----------------------------------------------------------------------
|
||
|
||
|
||
namespace app\common\model;
|
||
|
||
use think\facade\Config;
|
||
use think\facade\Env;
|
||
use Wenpeng\Curl\Curl;
|
||
|
||
class GameGm extends Model
|
||
{
|
||
static $api_url;
|
||
static $sign;
|
||
static $Curl;
|
||
|
||
|
||
/**
|
||
* Author:修缘
|
||
* 联系QQ:278896498
|
||
* Date: 2022/1/5 22:46
|
||
*/
|
||
protected static function init()
|
||
{
|
||
parent::init(); // TODO: Change the autogenerated stub
|
||
$ip = Config::get('game.gm.ip');
|
||
$port = Config::get('game.gm.port');
|
||
self::$api_url = "http://{$ip}:$port";
|
||
self::$sign = Config::get('game.gm.sign');
|
||
self::$Curl = new Curl();
|
||
|
||
}
|
||
|
||
|
||
|
||
public static function apiResult($result)
|
||
{
|
||
|
||
if ($result->info()['http_code'] != 200) {
|
||
exception(lang('gm_api_error'));
|
||
}
|
||
$result = json_decode($result->data(), true);
|
||
if (isset($result) && $result['code'] != 0) {
|
||
exception($result['msg']);
|
||
}
|
||
return $result;
|
||
}
|
||
|
||
public static function sync_data(string $path)
|
||
{
|
||
$data = [
|
||
'sign' => self::$sign,
|
||
'server_id' => 0,
|
||
'path' => $path
|
||
];
|
||
$result = self::$Curl->url(self::$api_url . '/say_sync_data?' . http_build_query($data));
|
||
return self::apiResult($result);
|
||
}
|
||
public static function send_mail(array $param, $type)
|
||
{
|
||
$data = [
|
||
'title' => $param['mail_title'],
|
||
'content' => $param['mail_content'],
|
||
'gets' => 0,
|
||
'sign' => self::$sign,
|
||
];
|
||
|
||
if (isset($param['gets'])) {
|
||
$data['gets'] = get_mail_item_array($param['gets']);
|
||
|
||
}
|
||
switch ($type) {
|
||
case 'S' :
|
||
$data['target'] = "S:{$param['server_id']}";
|
||
break;
|
||
case 'R' :
|
||
$data['target'] = "R:{$param['role_id']}";
|
||
break;
|
||
case 'I' :
|
||
$data['target'] = "I:";
|
||
break;
|
||
}
|
||
|
||
$result = self::$Curl->url(self::$api_url . '/say_send_mail?' . http_build_query($data));
|
||
return self::apiResult($result);
|
||
}
|
||
|
||
public static function create_robot(int $server_id, int $num)
|
||
{
|
||
$data = [
|
||
'server_id' => $server_id,
|
||
'num' => $num,
|
||
'sign' => self::$sign,
|
||
];
|
||
$result = self::$Curl->url(self::$api_url . '/say_create_robot?' . http_build_query($data));
|
||
return self::apiResult($result);
|
||
}
|
||
|
||
public static function clear_robot(int $server_id, int $num)
|
||
{
|
||
$data = [
|
||
'server_id' => $server_id,
|
||
'num' => $num,
|
||
'sign' => self::$sign,
|
||
];
|
||
$result = self::$Curl->url(self::$api_url . '/say_clear_robot?' . http_build_query($data));
|
||
return self::apiResult($result);
|
||
}
|
||
|
||
public static function set_comment(int $server_id, string $notice_content)
|
||
{
|
||
$data = [
|
||
'title' => 1233,
|
||
'serverId' => $server_id,
|
||
'text' => $notice_content,
|
||
'sign' => self::$sign,
|
||
];
|
||
$result = self::$Curl->url(self::$api_url . '/say_set_comment?' . http_build_query($data));
|
||
return self::apiResult($result);
|
||
}
|
||
|
||
public static function sys_notice(array $param)
|
||
{
|
||
$data = [
|
||
'text' => $param['inform_content'],
|
||
'type' => $param['inform_type'],
|
||
'server_id' => $param['server_id'],
|
||
'interval' => $param['interval'],
|
||
'times' => $param['times'],
|
||
'sign' => self::$sign,
|
||
];
|
||
$result = self::$Curl->url(self::$api_url . '/say_sys_notice?' . http_build_query($data));
|
||
return self::apiResult($result);
|
||
}
|
||
|
||
public static function agent_charge(int $role_id, int $charge_id, int $count = 1)
|
||
{
|
||
$data = [
|
||
'role_id' => $role_id,
|
||
'charge_id' => $charge_id,
|
||
'count' => $count,
|
||
'sign' => self::$sign,
|
||
];
|
||
$result = self::$Curl->url(self::$api_url . '/say_agent_charge?' . http_build_query($data));
|
||
return self::apiResult($result);
|
||
}
|
||
|
||
public static function frozen_mac(string $account)
|
||
{
|
||
$data = [
|
||
'account_id' => $account,
|
||
'sign' => self::$sign,
|
||
];
|
||
$result = self::$Curl->url(self::$api_url . '/say_frozen_mac?' . http_build_query($data));
|
||
return self::apiResult($result);
|
||
}
|
||
|
||
// public static function unfrozen_mac(string $account)
|
||
// {
|
||
// $data = [
|
||
// 'account_id' => $account,
|
||
// 'sign' => self::$sign,
|
||
// ];
|
||
// $result = self::$Curl->url(self::$api_url . '/say_unfrozen_mac?' . http_build_query($data));
|
||
// return self::apiResult($result);
|
||
// }
|
||
|
||
public static function add_exp(int $role_id, int $exp_num)
|
||
{
|
||
$data = [
|
||
'role_id' => $role_id,
|
||
'exp' => $exp_num,
|
||
'sign' => self::$sign,
|
||
];
|
||
$result = self::$Curl->url(self::$api_url . '/say_add_exp?' . http_build_query($data));
|
||
return self::apiResult($result);
|
||
}
|
||
|
||
public static function unfrozen_ip(string $ip)
|
||
{
|
||
$data = [
|
||
'frozen_ip' => $ip,
|
||
'sign' => self::$sign,
|
||
];
|
||
$result = self::$Curl->url(self::$api_url . '/say_unfrozen_ip?' . http_build_query($data));
|
||
return self::apiResult($result);
|
||
}
|
||
|
||
public static function frozen_ip(string $ip)
|
||
{
|
||
$data = [
|
||
'frozen_ip' => $ip,
|
||
'sign' => self::$sign,
|
||
];
|
||
$result = self::$Curl->url(self::$api_url . '/say_frozen_ip?' . http_build_query($data));
|
||
return self::apiResult($result);
|
||
}
|
||
|
||
public static function add_item(int $role_id, int $item_id, int $item_num)
|
||
{
|
||
$data = [
|
||
'item' => $item_id,
|
||
'num' => $item_num,
|
||
'role_id' => $role_id,
|
||
'sign' => self::$sign,
|
||
];
|
||
$result = self::$Curl->url(self::$api_url . '/say_add_item?' . http_build_query($data));
|
||
return self::apiResult($result);
|
||
}
|
||
|
||
public static function add_jade(int $role_id, int $jade_num)
|
||
{
|
||
$data = [
|
||
'role_id' => $role_id,
|
||
'jade' => $jade_num,
|
||
'sign' => self::$sign,
|
||
];
|
||
$result = self::$Curl->url(self::$api_url . '/say_add_jade?' . http_build_query($data));
|
||
return self::apiResult($result);
|
||
}
|
||
|
||
public static function can_speak(int $role_id=0, int $server_id=0)
|
||
{
|
||
$data = [
|
||
'role_id' => $role_id,
|
||
'server_id' => $server_id,
|
||
'sign' => self::$sign,
|
||
];
|
||
$result = self::$Curl->url(self::$api_url . '/say_can_speak?' . http_build_query($data));
|
||
return self::apiResult($result);
|
||
}
|
||
|
||
public static function not_speak(int $role_id=0, int $server_id=0)
|
||
{
|
||
$data = [
|
||
'role_id' => $role_id,
|
||
'server_id' => $server_id,
|
||
'sign' => self::$sign,
|
||
];
|
||
$result = self::$Curl->url(self::$api_url . '/say_not_speak?' . http_build_query($data));
|
||
return self::apiResult($result);
|
||
}
|
||
|
||
public static function closeserver($time, int $server_id=0)
|
||
{
|
||
$data = [
|
||
'sign' => self::$sign,
|
||
'server_id' => $server_id,
|
||
'time' => $time
|
||
];
|
||
$result = self::$Curl->url(self::$api_url . '/say_close?' . http_build_query($data));
|
||
return self::apiResult($result);
|
||
}
|
||
|
||
public static function get_item_list()
|
||
{
|
||
$path = Env::get('config_path');
|
||
$path_file = $path . '/item.txt';
|
||
$file = '';
|
||
try {
|
||
if(!is_readable($path_file)) {
|
||
throw new \Exception(lang('item_file_open_error'));
|
||
}
|
||
$file = fopen($path_file, "r");
|
||
|
||
$txts = [];
|
||
while (!feof($file)) {
|
||
$line = fgets($file);
|
||
$txts[] = explode(';', $line);
|
||
}
|
||
fclose($file);
|
||
return $txts;
|
||
}catch (\Exception $e) {
|
||
$data = ['code' => 0, 'msg' => $e->getMessage()];
|
||
return $data;
|
||
}
|
||
}
|
||
|
||
public static function get_charge_list()
|
||
{
|
||
$path = Env::get('config_path');
|
||
$path_file = $path . '/charge.txt';
|
||
$file = '';
|
||
try {
|
||
if(!is_readable($path_file)) {
|
||
throw new \Exception(lang('item_file_open_error'));
|
||
}
|
||
$file = fopen($path_file, "r");
|
||
|
||
$txts = [];
|
||
while (!feof($file)) {
|
||
$line = fgets($file);
|
||
$txts[] = explode(';', $line);
|
||
}
|
||
fclose($file);
|
||
return $txts;
|
||
}catch (\Exception $e) {
|
||
$data = ['code' => 0, 'msg' => $e->getMessage()];
|
||
return $data;
|
||
}
|
||
}
|
||
} |