Files
juipphp/extends/jinyouapi/Jinyoujingtai.php
“wanyongkang” 323ae40042 上线金柚产品
2024-02-01 17:13:32 +08:00

565 lines
17 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace extend\jinyouapi;
/**
* 金柚网络开放平台 SDK
* 通信编码协定 UTF-8
*/
class Jinyoujingtai{
/**
* 金柚域名
*/
private static $ServerUrl = "https://jyip.net/open-api/";
/**
* APP_ID
*/
private static $app_id = '49330ae23dad78f9';
/**
* APP_key
*/
private static $app_key = 'ddb4311a227fb118cacd63cc68416ab5';
/**
* 通用时间戳10位
*/
private static function timestamp()
{
return time();
}
/**
* 通信方法
*/
private static function send_post($method, $post_data)
{
$post_data=self::signAct($post_data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, self::$ServerUrl . $method);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
/**
* key排序签名
*/
private static function signAct($body)
{
$authStr = "";
$body ["st"] = static::timestamp();
$body ["app_id"] = static::$app_id;
ksort($body);
foreach ($body as $item) {
if(!is_object($item) and !is_array($item)) {
$authStr = $authStr . $item;
}
}
$body ["sign"] = md5(md5($authStr). static::$app_key);
return $body;
}
/**
* 测试接口,测试通信
*/
public static function apiTest($data)
{
$res = self::send_post('api-test', $data);
return json_decode($res);
}
/**
* * 创建平台第三方接入账号
* @param $phone *接入方平台用户注册手机号 同应用下手机号码不可重复
* @param $cn_name *用户实名认证后的真实姓名
* @param $cn_id *用户实名认证后的身份证号码
* @param $t_id *接入方平台中客户唯一的身份标识
* @return @json
*/
public static function createUsers($phone, $cn_name, $cn_id, $t_id)
{
$post_data = [
'phone' => $phone,
'cn_name' => $cn_name,
'cn_id' => $cn_id,
't_id' => $t_id,
];
$res = self::send_post('create-third-user', $post_data);
return json_decode($res);
}
/**
* 获取当前账户的可用余额
* @return @json
*/
public static function getMyPoint()
{
$res = self::send_post('get-my-point', []);
return json_decode($res);
}
/**
* 检查VPN账户是否存在
* @param string $user vpn账户
* @param int $type 类型,0:静态;1:专线;
*/
public static function checkVpnAccountExists($user, $type)
{
$data = [
'user' => $user,
'type' => $type
];
$res = self::send_post('check-vpn-account-exists', $data);
return json_decode($res);
}
/**
* 踢线
* @param string $user VPN账户
* @param int $type 类型,0:静态;1:专线;
*/
public static function kickOffLine($user, $type)
{
$data = [
'user' => $user,
'type' => $type
];
$res = self::send_post('kick-off-line', $data);
return json_decode($res);
}
/**
* 上传用户手持身份证照片
* 文件大小限制为不超过3M,支持格式为:jpg,jpeg,bmp,webp,png
* @param $t_id mixed 接入方平台中客户唯一的身份标识
* @param $upload_img mixed 这里是以thinkphp为示例实例的ThinkFile($file_path)对象
* 在CURLFILE(string $filename, string|null $mime_type = '', string|null $posted_filename = '')中你可以直接使用绝对地址,请勿使用网络地址。
* @return @json
*/
public static function uploadExamineFile($t_id, $upload_img)
{
$post_data = array(
't_id' => $t_id,
'upload_img' => new \CURLFile($upload_img->getRealPath(), $upload_img->getMime(), 'up.jpg'),
);
$res = self::send_post('upload-examine-file', $post_data);
return json_decode($res);
}
/**
* * 查询第三方接入用户状态
* @param $t_id 接入方平台中客户唯一的身份标识,整型 数字范围1-999999999
* @return @json
*/
public static function examineStatus($t_id)
{
$post_data = [
't_id' => $t_id,
];
$res = self::send_post('examine-status', $post_data);
return json_decode($res);
}
/**
* 开启白名单,涉及到用户需要使用到娱乐应用软件,例如:微信,抖音,均需要开启白名单
* @param $user string vpn账户
* @param $type int 账户类型,0:静态账户;1:专线账户
* @param $t_id int 接入方平台中客户唯一的身份标识,整型 数字范围1-999999999
* @return @json
*/
public static function setFirewallStatus($user, $type, $t_id)
{
$post_data = [
'user' => $user,
'type' => $type,
't_id' => $t_id
];
$res = self::send_post('set-firewall-status', $post_data);
return json_decode($res);
}
/**
* * 获取VPN账户列表
* @param $page int 当前分页
* @param $page_size int 分页条目数 1-100
* @param $t_id int 接入方客户唯一值UID用于查询客户账号列表、0或缺省则查询当前应用下全部客户账号非必填字段
* @param $user string vpn账户
* @return @json
*/
public static function userList($type, $page, $page_size, $t_id = null, $user = "")
{
$post_data = [
'type' => $type,
't_id' => $t_id,
'user' => $user,
'page' => $page,
'page_size' => $page_size,
];
$res = self::send_post('user-list', $post_data);
return json_decode($res);
}
/**
* 拉取已对接的产品ID
* @param $type int 产品分类 0:静态;1:专线 非必填
* @param $is_unshar int 产品类型 0:游戏独享;1:线路独享 非必填
*/
public static function productList($type = 0, $is_unshar = 0)
{
$post_data = [
'type' => $type
];
$res = self::send_post('product-list', $post_data);
return json_decode($res);
}
/**
* 游戏列表
*/
public static function gameList()
{
$post_data = [
];
$res=self::send_post('game-list', $post_data);
return json_decode($res);
}
/**
* 获取所有静态服务器列表
* @param $area string 区域查询,可为空,例如:"福建"
* @return @json
*/
public static function getStaticNodeList($area = '')
{
$post_data = [
'area' => $area
];
$res = self::send_post('static-node-list', $post_data);
return json_decode($res);
}
/**
* 创建静态VPN账户
* @param int $days 时长,通过已对接产品接口获取
* @param int $game_id 游戏ID通过游戏列表接口获取线路独享时可以传空
* @param string $account 自定义VPN账户,当存在自定义账户时且购买数量大于则账户末尾会追加数量序号例如账号为abc数量为3则会生成abc1-3
* @param string $passwd 自定义VPN密码
* @param string $nums 购买数量
* @param int $t_id 第三方身份唯一标识符号
* @param int $product_id 产品大类ID通过已对接产品接口获取
* @param int $product_sub_id 产品小类ID通过已对接产品接口获取
* @param int $product_item_id 产品ID通过已对接产品接口获取
* @param string $remark 备注
* @param array $product_info
*/
public static function createStatic($days, $game_id, $account, $passwd, $nums, $t_id, $product_id, $product_sub_id, $product_item_id, $remark = '', $product_info = [])
{
$post_data = [
'days' => $days,
'product_item_id' => $product_item_id,
'product_id' => $product_id,
'product_sub_id' => $product_sub_id,
'nums' => $nums,
't_id' => $t_id,
'game_id' => $game_id,
'account' => $account,
'passwd' => $passwd,
'remark' => $remark
];
if (!empty($product_info)) {
$post_data ['product_info'] = json_encode($product_info);
}
$res = self::send_post('create-vpn-user', $post_data);
return json_decode($res);
}
/**
* 创建专线VPN账户
* @param int $days 时长,通过已对接产品接口获取
* @param int $game_id 游戏ID通过游戏列表接口获取线路独享时可以传空
* @param string $account 自定义VPN账户,当存在自定义账户时且购买数量大于则账户末尾会追加数量序号例如账号为abc数量为3则会生成abc1-3
* @param string $passwd 自定义VPN密码
* @param string $nums 购买数量
* @param int $t_id 第三方身份唯一标识符号
* @param int $product_id 产品大类ID通过已对接产品接口获取
* @param int $product_sub_id 产品小类ID通过已对接产品接口获取
* @param int $product_item_id 产品ID通过已对接产品接口获取
* @param string $remark 备注
* @param array $product_info
*/
public static function createFixed($days, $game_id, $account, $passwd, $nums, $t_id, $product_id, $product_sub_id, $product_item_id, $product_info = [])
{
$post_data = [
'days' => $days,
'product_item_id' => $product_item_id,
'product_id' => $product_id,
'product_sub_id' => $product_sub_id,
'nums' => $nums,
't_id' => $t_id,
'game_id' => $game_id,
'account' => $account,
'passwd' => $passwd
];
if (!empty($product_info)) {
$post_data ['product_info'] = json_encode($product_info);
}
$res = self::send_post('create-vpn-user', $post_data);
return json_decode($res);
}
/**
* 静态账户续费
* @param int $t_id 第三方身份唯一标识符号
* @param string $account 要续费的VPN账户
* @param int $product_id 产品大类ID通过已对接产品接口获取
* @param int $product_sub_id 产品小类ID通过已对接产品接口获取
* @param int $product_item_id 产品ID通过已对接产品接口获取
* @param int $days 时长,通过已对接产品接口获取
* @param $type int 账户类型,0:静态账户;1:专线账户
*/
public static function staticAccountRenew($t_id, $account, $product_id, $product_sub_id, $product_item_id, $days, $type = 0)
{
$post_data = [
'days' => $days,
'product_item_id' => $product_item_id,
'product_id' => $product_id,
'product_sub_id' => $product_sub_id,
't_id' => $t_id,
'account' => $account,
'type' => $type
];
$res = self::send_post('account-renew', $post_data);
return json_decode($res);
}
/**
* 专线账户续费
* @param int $t_id 第三方身份唯一标识符号
* @param string $account 要续费的VPN账户
* @param int $product_id 产品大类ID通过已对接产品接口获取
* @param int $product_sub_id 产品小类ID通过已对接产品接口获取
* @param int $product_item_id 产品ID通过已对接产品接口获取
* @param int $days 时长,通过已对接产品接口获取
* @param $type int 账户类型,0:静态账户;1:专线账户
*/
public static function fixedAccountRenew($t_id, $account, $product_id, $product_sub_id, $product_item_id, $days, $type = 1)
{
$post_data = [
'days' => $days,
'product_item_id' => $product_item_id,
'product_id' => $product_id,
'product_sub_id' => $product_sub_id,
't_id' => $t_id,
'account' => $account,
'type' => $type
];
$res = self::send_post('account-renew', $post_data);
return json_decode($res);
}
/**
* 获取地区剩余线路
* @param int $product_id 产品ID
* @param int $is_unshar 游戏独享0,线路独享1
* @param int $game_id 游戏ID
*/
public static function regionSurplusOuts($product_id, $is_unshar, $game_id)
{
$post_data = [
'product_id' => $product_id,
'is_unshar' => $is_unshar,
'game_id' => $game_id
];
$res = self::send_post('region-surplus-outs', $post_data);
return json_decode($res);
}
/**
* 切换地区
* @param int $t_id 第三方身份唯一标识符号
* @param int $province_id 区域ID
* @param int $rid 地区编码
* @param string $account VPN账户
* @param $type int 账户类型,0:静态账户;1:专线账户
*/
public static function changeRegion($t_id, $province_id, $rid, $account, $type = 0)
{
$post_data = [
't_id' => $t_id,
'province_id' => $province_id,
'rid' => $rid,
'account' => $account,
'type' => $type
];
$res = self::send_post('change-region', $post_data);
return json_decode($res);
}
/**
* 修改VPN账户备注
* @param int $t_id 第三方身份唯一标识符号
* @param string $remark 备注
* @param string $account VPN账户
* @param $type int 账户类型,0:静态账户;1:专线账户
*/
public static function editRemark($t_id, $remark, $account, $type = 0)
{
$post_data = [
't_id' => $t_id,
'remark' => $remark,
'account' => $account,
'type' => $type
];
$res = self::send_post('edit-remark', $post_data);
return json_decode($res);
}
/**
* 修改VPN账户密码
* @param int $t_id 第三方身份唯一标识符号
* @param string $new_password 新密码
* @param string $account VPN账户
* @param $type int 账户类型,0:静态账户;1:专线账户
*/
public static function editPassword($t_id, $new_password, $account, $type = 0)
{
$post_data = [
't_id' => $t_id,
'passwd' => $new_password,
'account' => $account,
'type' => $type
];
$res = self::send_post('edit-password', $post_data);
return json_decode($res);
}
/**
* 账户在线状态
* @param string $account VPN账户 多账户以英文状态下逗号连接,例如:account1,account2
* @param $type int 账户类型,0:静态账户;1:专线账户
*/
public static function accountIsOnline($account, $type = 0)
{
$post_data = [
'account' => $account,
'type' => $type
];
$res = self::send_post('account-is-online', $post_data);
return json_decode($res);
}
/**
* 获取可切换IP列表
* @param int $t_id 第三方身份唯一标识符号
* @param string $account VPN账户
* @param $type int 账户类型,0:静态账户;1:专线账户
*/
public static function switchIpList($t_id, $account, $type = 0)
{
$post_data = [
'account' => $account,
'type' => $type,
't_id' => $t_id
];
$res = self::send_post('switch-ip-list', $post_data);
return json_decode($res);
}
/**
* 保存切换的IP
* @param int $t_id 第三方身份唯一标识符号
* @param string $account VPN账户
* @param $type int 账户类型,0:静态账户;1:专线账户
*/
public static function saveSwitchIp($t_id, $account, $type = 0, $ip_id)
{
$post_data = [
'account' => $account,
'type' => $type,
't_id' => $t_id,
'ip_id' => $ip_id
];
$res = self::send_post('save-switch-ip', $post_data);
return json_decode($res);
}
/**
* 获取账号信息
* @param int $t_id 第三方身份唯一标识符号
* @param string $account VPN账户
* @param $type int 账户类型,0:静态账户;1:专线账户
*/
public static function accountInfo($t_id, $account, $type = 0)
{
$post_data = [
'account' => $account,
'type' => $type,
't_id' => $t_id,
];
$res = self::send_post('account-info', $post_data);
return json_decode($res);
}
}