- @foreach (var package in Model.Packages.Where(m => m.IsTest == 0 && m.Status == 1&& m.Id != 1009&& m.Id != 1018).OrderBy(m => m.TenantId))
+ @foreach (var package in Model.Packages.Where(m => m.IsTest == 0 && m.Status == 1&& m.Id != 1009&& m.Id != 1018&& m.Id != 1019&& m.Id != 1020).OrderBy(m => m.TenantId))
{
@if(package.Id == 88||package.Id == 101||package.Id == 103||package.Id == 104||(package.Id>103 && package.Id>1000)){
diff --git a/Services/Hncore.Pass.Vpn/Service/AgentClient9Service.cs b/Services/Hncore.Pass.Vpn/Service/AgentClient9Service.cs
new file mode 100644
index 0000000..35fde3b
--- /dev/null
+++ b/Services/Hncore.Pass.Vpn/Service/AgentClient9Service.cs
@@ -0,0 +1,574 @@
+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 AgentClient9Service: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 AgentClient9Service(IHttpClientFactory httpClientFactory):base(httpClientFactory)
+ {
+ m_HttpClientFactory = httpClientFactory;
+ }
+
+ public override async Task
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 Login(AgentLoginRequest request)
+ {
+ var client = CreateHttpClient(false);
+
+ var map = new Dictionary(){
+ {"secret_id","yLeKmE6swXSk84VS" },
+ {"secret_key","bQYKH5hV5kcQ4bjaDHJBgM8PeUe82gwr" },
+ };
+ 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 accounts)
+ {
+ return false;
+ }
+
+ ///
+ /// 新开
+ ///
+ ///
+ ///
+ ///
+ ///
+ public override async Task NewAccount(string packageKey, string account, string pwd, int connCount = 1, int accountType = 1, int payCount = 1)
+ {
+ var client = CreateHttpClient();
+ var interval = "1";
+ if(packageKey == "2"){
+ interval ="2";
+ packageKey = "month";
+ } else if(packageKey == "3") {
+ interval ="2";
+ packageKey = "month";
+ }
+ var map = new Dictionary(){
+ {"group","single" },
+ {"number",account },
+ {"password",pwd },
+ {"connect",connCount.ToString()},
+ {"interval",interval},
+ {"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 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 client = CreateHttpClient();
+
+ var infoRet = await this.GetAccountInfo(account);
+ var id = infoRet.Data.Id;
+
+ var map = new Dictionary(){
+ {"type",packageKey },
+ {"ids[]",id },
+ {"interval","1" },
+ };
+ var title = GetOpTitle("NewReAccount", account);
+ LogHelper.Info(title, map.ToJson());
+ try
+ {
+ var resp = await client.PostAsForm(this.SingleReAddUrl, map);
+ var content = await resp.Content.ReadAsStringAsync();
+ JObject jo = (JObject)JsonConvert.DeserializeObject(content);
+ var status = jo["status"].ToString();
+ if (status =="400")
+ {
+ 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, "续费失败");
+ }
+ }
+ ///
+ /// 删除账号
+ ///
+ ///
+ ///
+ ///
+ 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 client = CreateHttpClient();
+ var title = GetOpTitle("GetAccountInfo", account);
+
+ var info = "";
+ try
+ {
+ var url = this.searchAccountUrl + account;
+ if (isTest)
+ {
+ url = this.searchTestAccountUrl + account;
+ }
+ var resp = await client.GetAsync(url);
+ var content = await resp.Content.ReadAsStringAsync();
+
+ JObject jo = (JObject)JsonConvert.DeserializeObject(content);
+ var data = jo["data"];
+
+ var trData = new OriginAccountModel
+ {
+ Id = data["id"].ToString(),
+ Account = data["number"].ToString(),
+ Pwd = data["password"].ToString(),
+ AccountType = data["status"].ToBool()?"未到期":"已到期",
+ Package = "",
+ ConnectCount = data["connect"].ToString(),
+ RegistTime = data["add_time"].ToString(),
+ EndTime = data["end_time"].ToString(),
+ RestTime = "",
+ Amount = data["balance"].ToString(),
+ Remark = data["body"].ToString(),
+ };
+ return new ApiResult(trData);
+ }
+ catch (Exception ex)
+ {
+ LogHelper.Error(title, ex.Message+"-->info:"+ info);
+ return new ApiResult(ResultCode.C_INVALID_ERROR, "查询失败");
+ }
+
+ return new ApiResult(ResultCode.C_INVALID_ERROR, "没有查询到信息");
+
+ }
+ ///
+ /// 修改账号密码
+ ///
+ ///
+ ///
+ ///
+ ///
+ public override async Task UpdateAccountPwd(string account, string pwd)
+ {
+ var ret = await this.GetAccountInfo(account);
+ if (ret.Code != ResultCode.C_SUCCESS)
+ {
+ return false;
+ }
+ var accountModel = ret.Data;
+ if (accountModel == null)
+ {
+ return false;
+ }
+ var client = CreateHttpClient();
+ var map = new Dictionary(){
+ {"number",account },
+ {"password",pwd },
+ {"body","修改密码"+account },
+ };
+ LogHelper.Info(GetOpTitle("UpdateAccountPwd", account), map.ToJson());
+ try
+ {
+ var resp = await client.PostAsForm(this.UpdateUrl, map);
+ var content = await resp.Content.ReadAsStringAsync();
+
+ JObject jo = (JObject)JsonConvert.DeserializeObject(content);
+ var status = jo["status"].ToString();
+ if (status =="400")
+ {
+ return true;
+ }
+ else
+ {
+ LogHelper.Error(GetOpTitle("UpdateAccountPwd", account), content);
+ }
+ }
+ catch (Exception ex)
+ {
+ LogHelper.Error(GetOpTitle("UpdateAccountPwd", account), ex);
+ }
+ return false;
+ }
+ ///
+ /// 退款
+ ///
+ ///
+ ///
+ ///
+ public override async Task Refund(string account, string packageKey, int days)
+ {
+
+
+ var infoRet = await this.GetAccountInfo(account);
+ var id = infoRet.Data.Id;
+
+ //{"DefaultRequestHeaders":[{"Key":"hl","Value":["hl"]},{"Key":"Cookie","Value":["EtV1DHm0lJwaH9n4dhKUOIGSO8XKroVSRY7shrgFTJyzk3hANqLsVoiYAIzDR8M7"]},{"Key":"Authorization","Value":["Bearer EtV1DHm0lJwaH9n4dhKUOIGSO8XKroVSRY7shrgFTJyzk3hANqLsVoiYAIzDR8M7"]}],"BaseAddress":"http://xjip.hlapi.com/","Timeout":"00:01:40","MaxResponseContentBufferSize":2147483647}
+ var client = CreateHttpClient();
+ var get_token = client.DefaultRequestHeaders.GetCookies()[0].Cookies[0].Name;
+
+ HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://xjip.hlapi.com/api/number/refund");
+
+ req.Method = "DELETE";
+
+ req.ContentType = "application/x-www-form-urlencoded";
+ req.Headers.Add("Authorization", "Bearer " + get_token);
+
+ req.Timeout = 800;//请求超时时间
+
+ var postData = "id=" + id;
+
+ byte[] data = Encoding.UTF8.GetBytes(postData);
+
+ req.ContentLength = data.Length;
+
+ using (Stream reqStream = req.GetRequestStream())
+ {
+ reqStream.Write(data, 0, data.Length);
+
+ reqStream.Close();
+ }
+
+ HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
+
+ Stream stream = resp.GetResponseStream();
+
+ string result = "";
+ //获取响应内容
+ using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
+ {
+ result = reader.ReadToEnd();
+ }
+
+ return new ApiResult(1);
+
+
+
+
+
+ // var client = CreateHttpClient();
+
+
+ // // client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
+
+ // var infoRet = await this.GetAccountInfo(account);
+ // var id = infoRet.Data.Id;
+
+ // var map = new Dictionary(){
+ // {"id",id },
+ // };
+ // var title = GetOpTitle("Refund", account);
+ // LogHelper.Info(title, map.ToJson());
+ // try
+ // {
+ // var resp = await client.DeleteAsForm(this.RefundUrl, map);
+ // var content = await resp.Content.ReadAsStringAsync();
+ // content = System.Text.RegularExpressions.Regex.Unescape(content);
+
+ // JObject jo = (JObject)JsonConvert.DeserializeObject(content);
+ // var status = jo["status"].ToString();
+ // if (status =="400")
+ // {
+ // 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, "退款失败");
+ // }
+ }
+ ///
+ /// 是否在线
+ ///
+ ///
+ ///
+ ///
+ public override async Task>> OnLine(string account)
+ {
+
+ var client = CreateHttpClient();
+ var title = GetOpTitle("OnLine", account);
+
+ var info = "";
+ try
+ {
+ var url = this.OnlineUrl + account;
+ var resp = await client.GetAsync(url);
+ var content = await resp.Content.ReadAsStringAsync();
+
+ JObject jo = (JObject)JsonConvert.DeserializeObject(content);
+ var retData = new List();
+ foreach (var tr in jo)
+ {
+ JObject jsondata = (JObject)JsonConvert.DeserializeObject(tr.ToJson());
+
+ var trData = new OriginAccountOnlineModel
+ {
+ Account = account,
+ ServerIP = jsondata["area"].ToString(),
+ LoginTime = jsondata["time"].ToString(),
+ OnlineTime = jsondata["time"].ToString(),
+ LoginIP = "",
+ UpStream = "",
+ DownStream = "",
+ Id= "{number:\""+account+"\",session:\""+jsondata["session"]+"\"}",
+ };
+
+ retData.Add(trData);
+ }
+ return new ApiResult>(retData);
+ }
+ catch (Exception ex)
+ {
+ LogHelper.Error(title, ex.Message + "-->info:" + info);
+ return new ApiResult>(ResultCode.C_INVALID_ERROR, "查询失败");
+ }
+ }
+ ///
+ /// 踢号
+ ///
+ ///
+ ///
+ ///
+ public override async Task KillOut( string id)
+ {
+ var client = CreateHttpClient();
+ var title = GetOpTitle("KillOut", id);
+ var info = "";
+
+ JObject userinfo = (JObject)JsonConvert.DeserializeObject(id);
+
+ var map = new Dictionary(){
+ {"number",userinfo["number"].ToString() },
+ {"session",userinfo["session"].ToString() },
+ };
+
+ try
+ {
+ var url = this.KIllUrl;
+
+ var resp = await client.PostAsForm(this.RefundUrl, map);
+ var content = await resp.Content.ReadAsStringAsync();
+
+ JObject jo = (JObject)JsonConvert.DeserializeObject(content);
+ var status = jo["status"].ToString();
+ if (status =="400")
+ {
+ return true;
+ }
+ }
+ catch (Exception ex)
+ {
+ LogHelper.Error(title, ex.Message + "-->info:" + info);
+ }
+ return false;
+ }
+
+ ///
+ /// 是否存在
+ ///
+ ///
+ ///
+ public override async Task Exist(string account)
+ {
+ var ret = await this.GetAccountInfo(account);
+ if (ret.Code != ResultCode.C_SUCCESS)
+ {
+ return false;
+ }
+ return true;
+ }
+ }
+}
diff --git a/Services/Hncore.Pass.Vpn/Service/AgentClientBaseService.cs b/Services/Hncore.Pass.Vpn/Service/AgentClientBaseService.cs
index baaa79e..aef6c45 100644
--- a/Services/Hncore.Pass.Vpn/Service/AgentClientBaseService.cs
+++ b/Services/Hncore.Pass.Vpn/Service/AgentClientBaseService.cs
@@ -69,6 +69,7 @@ namespace Hncore.Pass.Vpn.Service
{
client.DefaultRequestHeaders.Remove("Cookie");
client.DefaultRequestHeaders.Add("Cookie", cookie);
+ client.DefaultRequestHeaders.Add("Authorization", "Bearer " + cookie);
}
public string GetCookie(HttpResponseMessage resp, string name)
{
diff --git a/Services/Hncore.Pass.Vpn/Service/AgentService.cs b/Services/Hncore.Pass.Vpn/Service/AgentService.cs
index 04f14fa..4432145 100644
--- a/Services/Hncore.Pass.Vpn/Service/AgentService.cs
+++ b/Services/Hncore.Pass.Vpn/Service/AgentService.cs
@@ -59,6 +59,8 @@ namespace Hncore.Pass.Vpn.Service
agent = new AgentClient7Service(m_HttpClientFactory) { ClientName = product.GroupNO };
if (product.GroupNO == "g8")
agent = new AgentClient8Service(m_HttpClientFactory) { ClientName = product.GroupNO };
+ if (product.GroupNO == "g9")
+ agent = new AgentClient9Service(m_HttpClientFactory) { ClientName = product.GroupNO };
agent.Product = product;
return agent;
}
@@ -145,8 +147,8 @@ namespace Hncore.Pass.Vpn.Service
account = accountInfo.Raw;
}
var ret = await agent.GetAccountInfo(account);
- if (ret.Code != ResultCode.C_SUCCESS) return new ApiResult(ResultCode.C_NOT_EXISTS_ERROR, "账号不存在");
- if (pwd.Has()&&ret.Data.Pwd != pwd)
+ if (ret.Code != ResultCode.C_SUCCESS && product.Id!=17&& product.Id!=13) return new ApiResult(ResultCode.C_NOT_EXISTS_ERROR, "账号不存在");
+ if (pwd.Has()&&ret.Data.Pwd != pwd && product.Id!=17&& product.Id!=13)
return new ApiResult(ResultCode.C_NOT_EXISTS_ERROR, "密码不正确");
return ret;
}
@@ -190,10 +192,6 @@ namespace Hncore.Pass.Vpn.Service
var agent = GetAgent(product);
agent.Init(product.BaseUrl, product.Token);
- Console.WriteLine("========================================================================");
- Console.WriteLine(packageId);
- Console.WriteLine(package.PackageType);
- Console.WriteLine("========================================================================");
if (package.PackageType == PackageType.Base)
{
var ret = await agent.NewAccount(package.OriginKey, account, pwd, connCount, accountType,payCount);