552 lines
21 KiB
C#
552 lines
21 KiB
C#
using AngleSharp.Dom;
|
|
using AngleSharp.Html.Parser;
|
|
using Hncore.Infrastructure.Common;
|
|
using Hncore.Infrastructure.Extension;
|
|
using Hncore.Infrastructure.Serializer;
|
|
using Hncore.Infrastructure.WebApi;
|
|
using Hncore.Pass.Vpn.Model;
|
|
using Hncore.Pass.Vpn.Request.Product;
|
|
using Microsoft.Extensions.Logging;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Threading.Tasks;
|
|
using System.Security.Cryptography;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
namespace Hncore.Pass.Vpn.Service
|
|
{
|
|
//金桥
|
|
public class AgentClient4Service: AgentClient1Service
|
|
{
|
|
string LoginUrl { get; set; } = "main/agentLogin.html";
|
|
string LoginCodeUrl { get; set; } = "main/imgcode.html";
|
|
string RefrushTokenUrl { get; set; } = "agent.html";
|
|
string SingleAddUrl { get; set; } = "agent/memberSingleAdd.html";
|
|
string SingleReAddUrl { get; set; } = "agent/memberRenew.html";
|
|
string MuiltAddUrl { get; set; } = "agent/memberMuiltAdd.html";
|
|
string RefundUrl { get; set; } = "agent/memberRefundAct.html ";
|
|
string UpdateUrl = "agent/memberUpdate/id/";//agent/memberUpdate/id/1155709.html
|
|
string OnlineUrl { get; set; } = "";
|
|
string KIllUrl { get; set; } = "";
|
|
string searchAccountUrl = "agent/memberList/type/1.html?search=1&username=";
|
|
string searchTestAccountUrl = "agent/memberList/type/0.html?search=1&username=";
|
|
string DeleteUrl { get; set; } = "agent/memberDel/id/";//1160862.html";
|
|
string KillUrlClient = "/agent/disConnect/sessionid/{0}.html";
|
|
string ClientOnlineUrl { get; set; } = "agent/clientOnline/page/{0}.html";
|
|
IHttpClientFactory m_HttpClientFactory;
|
|
public AgentClient4Service(IHttpClientFactory httpClientFactory):base(httpClientFactory)
|
|
{
|
|
m_HttpClientFactory = httpClientFactory;
|
|
}
|
|
|
|
public override async Task<int> RefrushStatus()
|
|
{
|
|
int status = 0;
|
|
if (this.Token.Has())
|
|
{
|
|
var client = CreateHttpClient();
|
|
if (this.RefrushTokenUrl.Has())
|
|
{
|
|
// client.DefaultRequestHeaders.Add("Cookie", this.Token);
|
|
var getResp = await client.GetAsync(this.RefrushTokenUrl);
|
|
var content = await getResp.Content.ReadAsStringAsync();
|
|
if (getResp.StatusCode == HttpStatusCode.OK && content.IndexOf("agentLogin.html") == -1)
|
|
{
|
|
status = 1;
|
|
}
|
|
else
|
|
{
|
|
Debug.WriteLine("离线");
|
|
Debug.WriteLine(content);
|
|
}
|
|
}
|
|
}
|
|
return status;
|
|
}
|
|
public override async Task<(byte[], string)> GetCode()
|
|
{
|
|
var client = CreateHttpClient(false);
|
|
if (this.LoginUrl.NotHas()) return (null, "");
|
|
var getResp = await client.GetAsync(this.LoginUrl);
|
|
var cookie = this.GetCookie(getResp, "PHPSESSID");
|
|
if (cookie.Has())
|
|
{
|
|
client.DefaultRequestHeaders.Add("Cookie", cookie);
|
|
var ret = await client.GetByteArrayAsync(this.LoginCodeUrl + "?t=" + DateTime.Now.Millisecond);
|
|
return (ret, cookie);
|
|
}
|
|
return (null, "");
|
|
}
|
|
public override async Task<ApiResult> Login(AgentLoginRequest request)
|
|
{
|
|
var client = CreateHttpClient(false);
|
|
|
|
var map = new Dictionary<string, string>(){
|
|
{"agentName",request.Account },
|
|
{"password",request.Pwd },
|
|
{"authnum",request.Code },
|
|
};
|
|
LogHelper.Info("Login", map.ToJson());
|
|
AddCookie(client, request.Key);
|
|
//client.DefaultRequestHeaders.Add("Cookie", request.Key);
|
|
var resp = await client.PostAsForm(this.LoginUrl, map);
|
|
var content = await resp.Content.ReadAsStringAsync();
|
|
if (content.IndexOf("alert alert-danger") != -1)
|
|
{
|
|
return new ApiResult(ResultCode.C_VISITOR_CHECKING, "登录失败");
|
|
}
|
|
return new ApiResult(request.Key);
|
|
}
|
|
public override bool CheckAccount(int productId,List<string> accounts)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新开
|
|
/// </summary>
|
|
/// <param name="packageId"></param>
|
|
/// <param name="account"></param>
|
|
/// <param name="pwd"></param>
|
|
/// <returns></returns>
|
|
public override async Task<ApiResult> NewAccount(string packageKey, string account, string pwd, int connCount = 1, int accountType = 1, int payCount = 1)
|
|
{
|
|
var width = "";
|
|
var combos = "";
|
|
if(packageKey.Contains("-")){
|
|
string[] arrStr = packageKey.Split('-');
|
|
width = arrStr[0];
|
|
combos = arrStr[1];
|
|
}
|
|
Dictionary<string, string> map = new Dictionary<string, string>(){
|
|
{"width",width },
|
|
{"combos",combos },
|
|
{"account",account },
|
|
{"password",pwd },
|
|
{"conn_max",connCount.ToString() },
|
|
{"t_id","666" },
|
|
};
|
|
|
|
map = signAct(map);
|
|
|
|
var client = CreateHttpClient();
|
|
var resp = await client.PostAsForm("https://www.ip6b.com/openapi/Create_Dynamic", map);
|
|
var content = await resp.Content.ReadAsStringAsync();
|
|
JObject jo = (JObject)JsonConvert.DeserializeObject(content);
|
|
var status = jo["code"].ToString();
|
|
|
|
if (status == "200")
|
|
{
|
|
return new ApiResult(ResultCode.C_SUCCESS);
|
|
}
|
|
else
|
|
{
|
|
return new ApiResult(ResultCode.C_INVALID_ERROR, "开户失败");
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新开
|
|
/// </summary>
|
|
/// <param name="packageId"></param>
|
|
/// <param name="account"></param>
|
|
/// <param name="pwd"></param>
|
|
/// <returns></returns>
|
|
public override async Task<ApiResult> NewMuiltAccount(string packageKey, string account, string pwd, int connCount = 1, int accountType = 1,int startNum=0, int endNum=1 )
|
|
{
|
|
var client = CreateHttpClient();
|
|
var map = new Dictionary<string, string>(){
|
|
{"taocanName",packageKey },
|
|
{"usernameTpl",account },
|
|
{"password",pwd },
|
|
{"maxonline",connCount.ToString()},
|
|
{"startNum",startNum.ToString()},
|
|
{"endNum",endNum.ToString()},
|
|
{"mode",accountType.ToString()},
|
|
};
|
|
var title = GetOpTitle("NewMuiltAccount", account);
|
|
LogHelper.Info(title, map.ToJson());
|
|
try
|
|
{
|
|
var resp = await client.PostAsForm(this.MuiltAddUrl, map);
|
|
var content = await resp.Content.ReadAsStringAsync();
|
|
if (content.Has() && content.IndexOf("<td>成功</td>") != -1)
|
|
{
|
|
return new ApiResult(1);
|
|
}
|
|
else
|
|
{
|
|
LogHelper.Error(title, content);
|
|
return new ApiResult(ResultCode.C_INVALID_ERROR, "开户失败");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error(title, ex.Message);
|
|
return new ApiResult(ResultCode.C_INVALID_ERROR, "开户失败");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 续费
|
|
/// </summary>
|
|
/// <param name="productId"></param>
|
|
/// <param name="account"></param>
|
|
/// <param name="pwd"></param>
|
|
/// <returns></returns>
|
|
public override async Task<ApiResult> NewReAccount(string packageKey, string account, int connCount, int payCount = 1)
|
|
{
|
|
var width = "";
|
|
var combos = "";
|
|
if(packageKey.Contains("-")){
|
|
string[] arrStr = packageKey.Split('-');
|
|
width = arrStr[0];
|
|
combos = arrStr[1];
|
|
}
|
|
Dictionary<string, string> map = new Dictionary<string, string>(){
|
|
{"combos",combos },
|
|
{"account",account },
|
|
};
|
|
|
|
map = signAct(map);
|
|
|
|
var client = CreateHttpClient();
|
|
var resp = await client.PostAsForm("https://www.ip6b.com/openapi/Renew_Dynamic", map);
|
|
var content = await resp.Content.ReadAsStringAsync();
|
|
JObject jo = (JObject)JsonConvert.DeserializeObject(content);
|
|
var status = jo["code"].ToString();
|
|
|
|
if (status == "200")
|
|
{
|
|
return new ApiResult(1);
|
|
}
|
|
else
|
|
{
|
|
return new ApiResult(ResultCode.C_INVALID_ERROR, "续费失败");
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 删除账号
|
|
/// </summary>
|
|
/// <param name="productId"></param>
|
|
/// <param name="account"></param>
|
|
/// <returns></returns>
|
|
public override async Task<bool> DeleteAccount(string account)
|
|
{
|
|
var client = CreateHttpClient();
|
|
var infoRet = await this.GetAccountInfo(account, true);
|
|
if (infoRet.Code != ResultCode.C_SUCCESS)
|
|
return false;
|
|
|
|
var title = GetOpTitle("DeleteAccount", account);
|
|
LogHelper.Info(title, account);
|
|
try
|
|
{
|
|
var delete = this.DeleteUrl + infoRet.Data.Id + ".html";
|
|
var resp = await client.GetAsync(delete);
|
|
var content = await resp.Content.ReadAsStringAsync();
|
|
if (content.Has() && content.IndexOf("alert(\"删除成功\")") != -1)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
LogHelper.Error(title, content);
|
|
return false;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error(title, ex.Message);
|
|
return false;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 得到账号信息
|
|
/// </summary>
|
|
/// <param name="productId"></param>
|
|
/// <param name="account"></param>
|
|
/// <returns></returns>
|
|
public override async Task<ApiResult<OriginAccountModel>> GetAccountInfo(string account,bool isTest=false)
|
|
{
|
|
var trData = new OriginAccountModel
|
|
{
|
|
Id = "",
|
|
Account = account,
|
|
Pwd = "",
|
|
AccountType = "",
|
|
Package = "",
|
|
ConnectCount = "",
|
|
RegistTime = "",
|
|
EndTime = "",
|
|
RestTime = "",
|
|
Amount = "",
|
|
Remark = "",
|
|
};
|
|
return new ApiResult<OriginAccountModel>(trData);
|
|
|
|
return new ApiResult<OriginAccountModel>(ResultCode.C_INVALID_ERROR, "没有查询到信息");
|
|
|
|
}
|
|
/// <summary>
|
|
/// 修改账号密码
|
|
/// </summary>
|
|
/// <param name="productId"></param>
|
|
/// <param name="account"></param>
|
|
/// <param name="pwd"></param>
|
|
/// <returns></returns>
|
|
public override async Task<bool> UpdateAccountPwd(string account, string pwd)
|
|
{
|
|
Dictionary<string, string> map = new Dictionary<string, string>(){
|
|
{"password",pwd },
|
|
{"account",account },
|
|
};
|
|
|
|
map = signAct(map);
|
|
|
|
var client = CreateHttpClient();
|
|
var resp = await client.PostAsForm("https://www.ip6b.com/openapi/Reset_Password_Dynamic", map);
|
|
var content = await resp.Content.ReadAsStringAsync();
|
|
JObject jo = (JObject)JsonConvert.DeserializeObject(content);
|
|
var status = jo["code"].ToString();
|
|
|
|
if (status == "200")
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 退款
|
|
/// </summary>
|
|
/// <param name="packageId"></param>
|
|
/// <param name="account"></param>
|
|
/// <returns></returns>
|
|
public override async Task<ApiResult> Refund(string account, string packageKey, int days)
|
|
{
|
|
Dictionary<string, string> map = new Dictionary<string, string>(){
|
|
{"account",account },
|
|
};
|
|
|
|
map = signAct(map);
|
|
|
|
var client = CreateHttpClient();
|
|
var resp = await client.PostAsForm("https://www.ip6b.com/openapi/Refount_Account_Order", map);
|
|
var content = await resp.Content.ReadAsStringAsync();
|
|
JObject jo = (JObject)JsonConvert.DeserializeObject(content);
|
|
var status = jo["code"].ToString();
|
|
|
|
if (status == "200")
|
|
{
|
|
return new ApiResult(1);
|
|
}
|
|
else
|
|
{
|
|
return new ApiResult(ResultCode.C_INVALID_ERROR, "退款失败");
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 是否在线
|
|
/// </summary>
|
|
/// <param name="productId"></param>
|
|
/// <param name="account"></param>
|
|
/// <returns></returns>
|
|
public override async Task<ApiResult<List<OriginAccountOnlineModel>>> OnLine(string account)
|
|
{
|
|
Dictionary<string, string> map = new Dictionary<string, string>(){
|
|
{"account",account },
|
|
{"page","1" },
|
|
{"page_count","100" },
|
|
};
|
|
|
|
map = signAct(map);
|
|
|
|
var client = CreateHttpClient();
|
|
var resp = await client.PostAsForm("https://www.ip6b.com/openapi/Get_Dynamic_Online", map);
|
|
var content = await resp.Content.ReadAsStringAsync();
|
|
JObject jo = (JObject)JsonConvert.DeserializeObject(content);
|
|
var status = jo["code"].ToString();
|
|
|
|
|
|
var retData = new List<OriginAccountOnlineModel>();
|
|
|
|
if (status == "200")
|
|
{
|
|
foreach (var tr in jo["res"]["data"])
|
|
{
|
|
JObject jsondata = (JObject)JsonConvert.DeserializeObject(tr.ToJson());
|
|
|
|
var trData = new OriginAccountOnlineModel
|
|
{
|
|
Account = account,
|
|
ServerIP = "",
|
|
LoginTime = "",
|
|
OnlineTime = "",
|
|
LoginIP = jsondata["user_ip"].ToString(),
|
|
UpStream = "",
|
|
DownStream = "",
|
|
Id= jsondata["id"].ToString(),
|
|
|
|
};
|
|
|
|
retData.Add(trData);
|
|
}
|
|
return new ApiResult<List<OriginAccountOnlineModel>>(retData);
|
|
}
|
|
else
|
|
{
|
|
return new ApiResult<List<OriginAccountOnlineModel>>(ResultCode.C_INVALID_ERROR, "查询失败");
|
|
}
|
|
}
|
|
|
|
public async Task<List<OriginAccountOnlineModel>> ClientOnLine(string account,int page=1)
|
|
{
|
|
var client = CreateHttpClient();
|
|
var title = GetOpTitle("ClientOnLine", account);
|
|
var info = "";
|
|
var retData = new List<OriginAccountOnlineModel>();
|
|
try
|
|
{
|
|
var url =string.Format(this.ClientOnlineUrl,page);
|
|
var resp = await client.GetAsync(url);
|
|
var content = await resp.Content.ReadAsStringAsync();
|
|
var parser = new HtmlParser();
|
|
var document = await parser.ParseDocumentAsync(content);
|
|
var trs = document.QuerySelectorAll("table.table tr").ToList();
|
|
|
|
if (trs.Count() > 1)
|
|
{
|
|
foreach (var tr in trs.Skip(1))
|
|
{
|
|
var tds = tr.QuerySelectorAll("td").ToList();
|
|
var tdAccount = tds[1].FirstChild.TextContent;
|
|
if (tdAccount != account)
|
|
continue;
|
|
info = string.Join("", tds.Select(m => m.OuterHtml));
|
|
//序号 会员账号 登录时间 在线时长 客户端IP地址 操作
|
|
var trData = new OriginAccountOnlineModel
|
|
{
|
|
Account = account,
|
|
LoginTime = tds[2].TextContent,
|
|
OnlineTime = tds[3].TextContent,
|
|
LoginIP = tds[4].TextContent,
|
|
};
|
|
var href = tr.LastElementChild.QuerySelector("a")?.Attributes["href"]?.Value;
|
|
if (href.Has())
|
|
{
|
|
var start = href.LastIndexOf('/');
|
|
var end = href.IndexOf(".html");
|
|
if (start != -1 && end != -1)
|
|
{
|
|
trData.Id = href.Substring(start + 1, end - start).TrimEnd('.');
|
|
}
|
|
}
|
|
retData.Add(trData);
|
|
}
|
|
}
|
|
return retData;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error(title, ex.Message + "-->info:" + info);
|
|
}
|
|
return retData;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 踢号
|
|
/// </summary>
|
|
/// <param name="productId"></param>
|
|
/// <param name="account"></param>
|
|
/// <returns></returns>
|
|
public override async Task<bool> KillOut( string id)
|
|
{
|
|
Dictionary<string, string> map = new Dictionary<string, string>(){
|
|
{"sid",id },
|
|
};
|
|
|
|
map = signAct(map);
|
|
|
|
var client = CreateHttpClient();
|
|
var resp = await client.PostAsForm("https://www.ip6b.com/openapi/Kick_Off_Dynamic_Line", map);
|
|
var content = await resp.Content.ReadAsStringAsync();
|
|
JObject jo = (JObject)JsonConvert.DeserializeObject(content);
|
|
var status = jo["code"].ToString();
|
|
|
|
|
|
var retData = new List<OriginAccountOnlineModel>();
|
|
|
|
if (status == "200")
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 是否存在
|
|
/// </summary>
|
|
/// <param name="account"></param>
|
|
/// <returns></returns>
|
|
public override async Task<bool> Exist(string account)
|
|
{
|
|
Dictionary<string, string> map = new Dictionary<string, string>();
|
|
map.Add("account", account);
|
|
map = signAct(map);
|
|
|
|
var client = CreateHttpClient();
|
|
var resp = await client.PostAsForm("https://www.ip6b.com/openapi/Dynamic_Account_Exists", map);
|
|
var content = await resp.Content.ReadAsStringAsync();
|
|
JObject jo = (JObject)JsonConvert.DeserializeObject(content);
|
|
|
|
|
|
if (jo["code"].ToString() == "404") {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
private static Dictionary<string, string> signAct(Dictionary<string, string> body)
|
|
{
|
|
var authStr="";
|
|
body.Add("st",DateTime.Now.GetUnixTimeStamp().ToString());
|
|
body.Add("appid","49330ae23dad78f9");
|
|
body = body.OrderBy(kv => kv.Key).ToDictionary(kv => kv.Key, p => p.Value);
|
|
|
|
|
|
foreach (var item in body)
|
|
{
|
|
authStr=authStr+item.Value;
|
|
}
|
|
|
|
body.Add("sign",Md5(Md5(authStr)+"ddb4311a227fb118cacd63cc68416ab5"));
|
|
return body;
|
|
}
|
|
|
|
//Md5摘要
|
|
private static string Md5(string text)
|
|
{
|
|
MD5 md5 = new MD5CryptoServiceProvider();
|
|
byte[] fromData = System.Text.Encoding.UTF8.GetBytes(text);
|
|
byte[] targetData = md5.ComputeHash(fromData);
|
|
string byte2String = null;
|
|
|
|
for (int i = 0; i < targetData.Length; i++)
|
|
{
|
|
byte2String += targetData[i].ToString("x2");
|
|
}
|
|
|
|
return byte2String;
|
|
}
|
|
}
|
|
}
|