初始提交
This commit is contained in:
319
Services/Hncore.Pass.Vpn/Service/AgentClient5Service.cs
Normal file
319
Services/Hncore.Pass.Vpn/Service/AgentClient5Service.cs
Normal file
@@ -0,0 +1,319 @@
|
||||
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 System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
namespace Hncore.Pass.Vpn.Service
|
||||
{
|
||||
//先锋
|
||||
public class AgentClient5Service : 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/memberRefund/id/{0}.html";
|
||||
string UpdateUrl = "agent/memberUpdate/id/{0}.html";//agent/memberUpdate/id/1155709.html
|
||||
string OnlineUrl { get; set; } = "agent/radiusOnline.html?search=1&username=";
|
||||
string ClientOnlineUrl { get; set; } = "agent/clientOnline.html?search=1&username=";
|
||||
string KIllUrl { get; set; } = "";
|
||||
string KillUrlClient = "/agent/disConnect/sessionid/{0}.html";
|
||||
string KillUrl = "/agent/disConnect/radacctid/{0}.html";
|
||||
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/multiDelMember.html ";
|
||||
IHttpClientFactory m_HttpClientFactory;
|
||||
public AgentClient5Service(IHttpClientFactory httpClientFactory):base(httpClientFactory)
|
||||
{
|
||||
m_HttpClientFactory = httpClientFactory;
|
||||
}
|
||||
|
||||
/// <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 client = CreateHttpClient();
|
||||
var map = new Dictionary<string, string>(){
|
||||
{"taocanName",packageKey },
|
||||
{"username",account },
|
||||
{"password",pwd },
|
||||
{"bingfa",connCount.ToString()},
|
||||
{"type",accountType.ToString()}
|
||||
};
|
||||
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();
|
||||
if (content.Has() && content.IndexOf("{alert(\"成功\")") != -1)
|
||||
{
|
||||
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, "开户失败");
|
||||
}
|
||||
}
|
||||
/// <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 map = new Dictionary<string, string>(){
|
||||
{infoRet.Data.Id,infoRet.Data.Id },
|
||||
};
|
||||
var title = GetOpTitle("DeleteAccount", account);
|
||||
LogHelper.Info(title, account);
|
||||
try
|
||||
{
|
||||
var resp = await client.PostAsForm(this.DeleteUrl, map);
|
||||
var content = await resp.Content.ReadAsStringAsync();
|
||||
if (content.Has() && content.IndexOf("删除成功") != -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>
|
||||
/// <param name="pwd"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<bool> 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<string, string>(){
|
||||
{"username",account },
|
||||
{"password",pwd },
|
||||
{"maxOnline",ret.Data.ConnectCount },
|
||||
};
|
||||
LogHelper.Info(GetOpTitle("UpdateAccountPwd", account), map.ToJson());
|
||||
try
|
||||
{
|
||||
var url = string.Format(this.UpdateUrl, accountModel.Id);
|
||||
var resp = await client.PostAsForm(url, map);
|
||||
var content = await resp.Content.ReadAsStringAsync();
|
||||
if (content.Has() && content.IndexOf("更新成功") != -1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
LogHelper.Error(GetOpTitle("UpdateAccountPwd", account), content);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Error(GetOpTitle("UpdateAccountPwd", account), ex);
|
||||
}
|
||||
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)
|
||||
{
|
||||
var client = CreateHttpClient();
|
||||
var title = GetOpTitle("Refund", account);
|
||||
try
|
||||
{
|
||||
var accountInfo = await this.GetAccountInfo(account);
|
||||
if (accountInfo.Code != ResultCode.C_SUCCESS)
|
||||
{
|
||||
return new ApiResult(ResultCode.C_INVALID_ERROR, "退款失败");
|
||||
}
|
||||
var url = string.Format(this.RefundUrl, accountInfo.Data.Id);
|
||||
var resp = await client.GetAsync(url);
|
||||
var content = await resp.Content.ReadAsStringAsync();
|
||||
if (content.Has() && content.IndexOf("退款成功!") != -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>
|
||||
/// <returns></returns>
|
||||
public override async Task<ApiResult<List<OriginAccountOnlineModel>>> OnLine(string account)
|
||||
{
|
||||
//虚拟在线
|
||||
var onlines= await base.OnLine(account);
|
||||
|
||||
if (onlines.Code == ResultCode.C_SUCCESS && onlines.Data.Count > 0)
|
||||
return onlines;
|
||||
|
||||
var client = CreateHttpClient();
|
||||
var title = GetOpTitle("OnLine", account);
|
||||
var info = "";
|
||||
try
|
||||
{
|
||||
var url = this.ClientOnlineUrl + account;
|
||||
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();
|
||||
var retData = new List<OriginAccountOnlineModel>();
|
||||
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 new ApiResult<List<OriginAccountOnlineModel>>(retData);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Error(title, ex.Message + "-->info:" + info);
|
||||
return new ApiResult<List<OriginAccountOnlineModel>>(ResultCode.C_INVALID_ERROR, "查询失败");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 踢号
|
||||
/// </summary>
|
||||
/// <param name="productId"></param>
|
||||
/// <param name="account"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<bool> KillOut(string id)
|
||||
{
|
||||
var flag = await this.KillOutClient(id);
|
||||
|
||||
var client = CreateHttpClient();
|
||||
var title = GetOpTitle("KillOut", id);
|
||||
var info = "";
|
||||
try
|
||||
{
|
||||
var url = string.Format(this.KillUrl, id);
|
||||
var resp = await client.GetAsync(url);
|
||||
var content = await resp.Content.ReadAsStringAsync();
|
||||
if (content.Has() && content.IndexOf("断开消息已发送") != -1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Error(title, ex.Message + "-->info:" + info);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public async Task<bool> KillOutClient(string id)
|
||||
{
|
||||
var client = CreateHttpClient();
|
||||
var title = GetOpTitle("KillOutClient", id);
|
||||
var info = "";
|
||||
try
|
||||
{
|
||||
var url = string.Format(this.KillUrlClient, id);
|
||||
var resp = await client.GetAsync(url);
|
||||
var content = await resp.Content.ReadAsStringAsync();
|
||||
if (content.Has() && content.IndexOf("已经向客户端发送断开消息") != -1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Error(title, ex.Message + "-->info:" + info);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user