From 57ea9274181c45e188edd2f145ef736cc36ccb1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cwanyongkang=E2=80=9D?= <“937888580@qq.com”> Date: Tue, 23 Feb 2021 10:45:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=98=9F=E6=98=9F=E4=B8=8A=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/AgentClient11Service.cs | 443 ++++++++++++++++++ .../Service/AgentClientBaseService.cs | 3 +- .../Hncore.Pass.Vpn/Service/AgentService.cs | 2 + 3 files changed, 447 insertions(+), 1 deletion(-) create mode 100644 Services/Hncore.Pass.Vpn/Service/AgentClient11Service.cs diff --git a/Services/Hncore.Pass.Vpn/Service/AgentClient11Service.cs b/Services/Hncore.Pass.Vpn/Service/AgentClient11Service.cs new file mode 100644 index 0000000..402df67 --- /dev/null +++ b/Services/Hncore.Pass.Vpn/Service/AgentClient11Service.cs @@ -0,0 +1,443 @@ +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 Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; +using System.Text; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.IO; +using System.Threading.Tasks; +namespace Hncore.Pass.Vpn.Service +{ + public class AgentClient11Service:AgentClientBaseService + { + string LoginUrl { get; set; } = "api/login"; + string LoginCodeUrl { get; set; } = "main/imgcode.html"; + string RefrushTokenUrl { get; set; } = "agent/index.html"; + string SingleAddUrl { get; set; } = "api/number"; + string SingleReAddUrl { get; set; } = "api/number/renew"; + string MuiltAddUrl { get; set; } = "agent/memberMuiltAdd.html"; + string RefundUrl { get; set; } = "api/number/refund"; + string UpdateUrl = "api/number/";//agent/memberUpdate/id/1155709.html + string OnlineUrl { get; set; } = "api/numberLine/"; + string KIllUrl { get; set; } = "api/numberOffline"; + string searchAccountUrl = "api/numberSingle/"; + string searchTestAccountUrl = "api/numberSingle/"; + string DeleteUrl { get; set; } = "api/number/refund";//1160862.html"; + IHttpClientFactory m_HttpClientFactory; + public AgentClient11Service(IHttpClientFactory httpClientFactory):base(httpClientFactory) + { + m_HttpClientFactory = httpClientFactory; + } + + public override async Task RefrushStatus() + { + return 1; + } + 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 Login(AgentLoginRequest request) + { + return new ApiResult(request.Key); + } + public override bool CheckAccount(int productId,List accounts) + { + return false; + } + + /// + /// 新开 + /// + /// + /// + /// + /// + public override async Task NewAccount(string packageKey, string account, string pwd, int connCount = 1, int accountType = 1, int payCount = 1) + { + + var time_s = DateTime.Now.GetUnixTimeStamp(); + var agentid = "admin1"; + var nonce = MD5(time_s.ToString()); + var apikey = "d50f2b2ffd421efa67df8efb96d5ff6c"; + var sign = MD5(time_s+nonce+apikey); + + var userid = "zhanghao"; + + var url = "/api/raduserCreate?agentid="+agentid+"&ti="+time_s+"&nonce="+nonce+"&sign="+sign+"&userid="+userid+"&username="+account+"&password="+pwd+"&prdid=8&maxonline="+connCount+"&day="+packageKey; + + var client = CreateHttpClient(); + + var resp = await client.GetAsync(url); + var content = await resp.Content.ReadAsStringAsync(); + JObject jo = (JObject)JsonConvert.DeserializeObject(content); + var status = jo["errcode"].ToString(); + if (status =="0") + { + return new ApiResult(ResultCode.C_SUCCESS); + } + else + { + return new ApiResult(ResultCode.C_INVALID_ERROR, "开户失败"); + } + } + + /// + /// 新开 + /// + /// + /// + /// + /// + public override async Task 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(){ + {"group","single" }, + {"number",account }, + {"password",pwd }, + {"connect",connCount.ToString()}, + {"interval","1"}, + {"type",packageKey}, + {"body","api"}, + {"mobile","13073735878"} + }; + var title = GetOpTitle("NewAccount", account); + LogHelper.Info(title, map.ToJson()); + try + { + var resp = await client.PostAsForm(this.SingleAddUrl, map); + var content = await resp.Content.ReadAsStringAsync(); + JObject jo = (JObject)JsonConvert.DeserializeObject(content); + var status = jo["status"].ToString(); + if (status =="400") + { + return new ApiResult(ResultCode.C_SUCCESS); + } + 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, "开户失败"); + } + } + + /// + /// 续费 + /// + /// + /// + /// + /// + public override async Task NewReAccount(string packageKey, string account, int connCount, int payCount = 1) + { + + var time_s = DateTime.Now.GetUnixTimeStamp(); + var agentid = "admin1"; + var nonce = MD5(time_s.ToString()); + var apikey = "d50f2b2ffd421efa67df8efb96d5ff6c"; + var sign = MD5(time_s+nonce+apikey); + + + + var url = "/api/raduserRenew?agentid="+agentid+"&ti="+time_s+"&nonce="+nonce+"&sign="+sign+"&username="+account+"&day="+packageKey; + + var client = CreateHttpClient(); + + var resp = await client.GetAsync(url); + var content = await resp.Content.ReadAsStringAsync(); + JObject jo = (JObject)JsonConvert.DeserializeObject(content); + var status = jo["errcode"].ToString(); + if (status =="0") + { + return new ApiResult(1); + } + else + { + return new ApiResult(ResultCode.C_INVALID_ERROR, "续费失败"); + } + } + /// + /// 删除账号 + /// + /// + /// + /// + public override async Task 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; + } + } + /// + /// 得到账号信息 + /// + /// + /// + /// + public override async Task> GetAccountInfo(string account,bool isTest=false) + { + + var time_s = DateTime.Now.GetUnixTimeStamp(); + var agentid = "admin1"; + var nonce = MD5(time_s.ToString()); + var apikey = "d50f2b2ffd421efa67df8efb96d5ff6c"; + var sign = MD5(time_s+nonce+apikey); + + var url = "/api/raduserInfo?agentid="+agentid+"&ti="+time_s+"&nonce="+nonce+"&sign="+sign+"&username="+account; + + var client = CreateHttpClient(); + + var resp = await client.GetAsync(url); + var content = await resp.Content.ReadAsStringAsync(); + JObject jo = (JObject)JsonConvert.DeserializeObject(content); + var status = jo["errcode"].ToString(); + var data = jo["data"]; + if (status =="0") + { + var trData = new OriginAccountModel + { + Id = "", + Account = data["username"].ToString(), + Pwd = data["password"].ToString(), + AccountType = "", + Package = "", + ConnectCount = "", + RegistTime = data["createtime"].ToString(), + EndTime = data["expiretime"].ToString(), + RestTime = "", + Amount = "", + Remark = "", + }; + return new ApiResult(trData); + } + else + { + return new ApiResult(ResultCode.C_INVALID_ERROR, "没有查询到信息"); + } + + + + } + /// + /// 修改账号密码 + /// + /// + /// + /// + /// + public override async Task UpdateAccountPwd(string account, string pwd) + { + + var time_s = DateTime.Now.GetUnixTimeStamp(); + var agentid = "admin1"; + var nonce = MD5(time_s.ToString()); + var apikey = "d50f2b2ffd421efa67df8efb96d5ff6c"; + var sign = MD5(time_s+nonce+apikey); + + var url = "/api/raduserChpw?agentid="+agentid+"&ti="+time_s+"&nonce="+nonce+"&sign="+sign+"&username="+account+"&newpass="+pwd; + + var client = CreateHttpClient(); + + var resp = await client.GetAsync(url); + var content = await resp.Content.ReadAsStringAsync(); + JObject jo = (JObject)JsonConvert.DeserializeObject(content); + var status = jo["errcode"].ToString(); + if (status =="0") + { + return true; + } + else + { + return false; + } + + } + /// + /// 退款 + /// + /// + /// + /// + public override async Task Refund(string account, string packageKey, int days) + { + + + + return new ApiResult(1); + + } + /// + /// 是否在线 + /// + /// + /// + /// + public override async Task>> OnLine(string account) + { + + var time_s = DateTime.Now.GetUnixTimeStamp(); + var agentid = "admin1"; + var nonce = MD5(time_s.ToString()); + var apikey = "d50f2b2ffd421efa67df8efb96d5ff6c"; + var sign = MD5(time_s+nonce+apikey); + + var url = "/api/raduserAcct?agentid="+agentid+"&ti="+time_s+"&nonce="+nonce+"&sign="+sign+"&username="+account; + + var client = CreateHttpClient(); + + var resp = await client.GetAsync(url); + var content = await resp.Content.ReadAsStringAsync(); + JObject jo = (JObject)JsonConvert.DeserializeObject(content); + var status = jo["errcode"].ToString(); + var retData = new List(); + if (status =="0") + { + foreach (var tr in jo["data"]) + { + JObject jsondata = (JObject)JsonConvert.DeserializeObject(tr.ToJson()); + + var trData = new OriginAccountOnlineModel + { + Account = account, + ServerIP = jsondata["serverip"].ToString(), + LoginTime = jsondata["starttime"].ToString(), + OnlineTime = "", + LoginIP = jsondata["framedip"].ToString(), + UpStream = "", + DownStream = "", + Id= "{account:\""+account+"\",radacctid:\""+jsondata["radacctid"].ToString()+"\"}", + + }; + + retData.Add(trData); + } + return new ApiResult>(retData); + } + else + { + return new ApiResult>(ResultCode.C_INVALID_ERROR, "查询失败"); + } + + } + /// + /// 踢号 + /// + /// + /// + /// + public override async Task KillOut( string id) + { + + var time_s = DateTime.Now.GetUnixTimeStamp(); + var agentid = "admin1"; + var nonce = MD5(time_s.ToString()); + var apikey = "d50f2b2ffd421efa67df8efb96d5ff6c"; + var sign = MD5(time_s+nonce+apikey); + + JObject userinfo = (JObject)JsonConvert.DeserializeObject(id); + + var url = "/api/raduserDisconnect?agentid="+agentid+"&ti="+time_s+"&nonce="+nonce+"&sign="+sign+"&username="+userinfo["account"]+"&radacctid="+userinfo["radacctid"]; + + var client = CreateHttpClient(); + var title = GetOpTitle("KillOut", id); + var info = ""; + + + try + { + + var resp = await client.GetAsync(url); + var content = await resp.Content.ReadAsStringAsync(); + JObject jo = (JObject)JsonConvert.DeserializeObject(content); + var status = jo["errcode"].ToString(); + if (status =="0") + { + return true; + } + } + catch (Exception ex) + { + LogHelper.Error(title, ex.Message + "-->info:" + info); + } + return false; + } + + /// + /// 是否存在 + /// + /// + /// + public override async Task Exist(string account) + { + var time_s = DateTime.Now.GetUnixTimeStamp(); + var agentid = "admin1"; + var nonce = MD5(time_s.ToString()); + var apikey = "d50f2b2ffd421efa67df8efb96d5ff6c"; + var sign = MD5(time_s+nonce+apikey); + + var url = "/api/raduserExist?agentid="+agentid+"&ti="+time_s+"&nonce="+nonce+"&sign="+sign+"&username="+account; + + var client = CreateHttpClient(); + + var resp = await client.GetAsync(url); + var content = await resp.Content.ReadAsStringAsync(); + JObject jo = (JObject)JsonConvert.DeserializeObject(content); + var status = jo["errcode"].ToString(); + if (status =="0") + { + return true; + } + return false; + } + } +} diff --git a/Services/Hncore.Pass.Vpn/Service/AgentClientBaseService.cs b/Services/Hncore.Pass.Vpn/Service/AgentClientBaseService.cs index d530046..b9e3d27 100644 --- a/Services/Hncore.Pass.Vpn/Service/AgentClientBaseService.cs +++ b/Services/Hncore.Pass.Vpn/Service/AgentClientBaseService.cs @@ -67,7 +67,7 @@ namespace Hncore.Pass.Vpn.Service } public virtual string MD5(string password) { - byte[] textBytes = System.Text.Encoding.Default.GetBytes(password); + byte[] textBytes = System.Text.Encoding.Default.GetBytes(password); try { System.Security.Cryptography.MD5CryptoServiceProvider cryptHandler; cryptHandler = new System.Security.Cryptography.MD5CryptoServiceProvider(); @@ -84,6 +84,7 @@ namespace Hncore.Pass.Vpn.Service catch { throw; } + } protected virtual void AddCookie(HttpClient client, string cookie) diff --git a/Services/Hncore.Pass.Vpn/Service/AgentService.cs b/Services/Hncore.Pass.Vpn/Service/AgentService.cs index 3fbab08..6582ec6 100644 --- a/Services/Hncore.Pass.Vpn/Service/AgentService.cs +++ b/Services/Hncore.Pass.Vpn/Service/AgentService.cs @@ -63,6 +63,8 @@ namespace Hncore.Pass.Vpn.Service agent = new AgentClient9Service(m_HttpClientFactory) { ClientName = product.GroupNO }; if (product.GroupNO == "g10") agent = new AgentClient10Service(m_HttpClientFactory) { ClientName = product.GroupNO }; + if (product.GroupNO == "g11") + agent = new AgentClient11Service(m_HttpClientFactory) { ClientName = product.GroupNO }; agent.Product = product; return agent; }