忽略dll文件git

This commit is contained in:
“wanyongkang”
2023-07-29 10:19:42 +08:00
parent 7f97317bcc
commit b562aba2b1
3868 changed files with 63608 additions and 385427 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,430 +1,430 @@
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;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
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)
{
if(packageKey == "free"){
return await NewTestAccount(packageKey, account, pwd, 1, accountType, 1);
}
var secretId = "626B6170693231";
var secretKey = "6b3fdfc206841f44c6609bf19c182a6a";
var url = "http://bkapi.pptp.biz/userapi/?secretId="+secretId+"&secretKey="+secretKey+"&type=adduser&user="+account+"&pass="+pwd+"&serverid="+packageKey+"&logincount="+connCount.ToString()+"&phone=17719092232&cardname=万永康&cardno=410325199810129916";
var client = CreateHttpClient();
var resp = await client.GetAsync(url);
var content = await resp.Content.ReadAsStringAsync();
JObject jo = (JObject)JsonConvert.DeserializeObject(content);
var status = jo["code"].ToString();
if (status =="1")
{
return new ApiResult(ResultCode.C_SUCCESS);
}
return new ApiResult(ResultCode.C_INVALID_ERROR, "开户失败");
}
/// <summary>
/// 新开
/// </summary>
/// <param name="packageId"></param>
/// <param name="account"></param>
/// <param name="pwd"></param>
/// <returns></returns>
public async Task<ApiResult> NewTestAccount(string packageKey, string account, string pwd, int connCount = 1, int accountType = 1, int payCount = 1)
{
var secretId = "626B6170693231";
var secretKey = "6b3fdfc206841f44c6609bf19c182a6a";
var url = "http://bkapi.pptp.biz/userapi3/?secretId="+secretId+"&secretKey="+secretKey+"&type=addtestuser&user="+account+"&password="+pwd+"&username3=admin01&phone=17719092232&cardname=万永康&cardno=410325199810129916";
var client = CreateHttpClient();
var resp = await client.GetAsync(url);
var content = await resp.Content.ReadAsStringAsync();
JObject jo = (JObject)JsonConvert.DeserializeObject(content);
var status = jo["code"].ToString();
Console.WriteLine("==================================================");
Console.WriteLine(jo);
Console.WriteLine("==================================================");
if (status =="1")
{
return new ApiResult(ResultCode.C_SUCCESS);
}
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 secretId = "626B6170693231";
var secretKey = "6b3fdfc206841f44c6609bf19c182a6a";
var url = "http://bkapi.pptp.biz/userapi/?secretId="+secretId+"&secretKey="+secretKey+"&type=buy&user="+account+"&serverid="+packageKey+"&logincount="+connCount.ToString()+"&phone=17719092232&cardname=万永康&cardno=410325199810129916";
var client = CreateHttpClient();
var resp = await client.GetAsync(url);
var content = await resp.Content.ReadAsStringAsync();
JObject jo = (JObject)JsonConvert.DeserializeObject(content);
var status = jo["code"].ToString();
if (status =="1")
{
return new ApiResult(1);
}
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>
/// <returns></returns>
public override async Task<ApiResult<OriginAccountModel>> GetAccountInfo(string account,bool isTest=false)
{
var secretId = "626B6170693231";
var secretKey = "6b3fdfc206841f44c6609bf19c182a6a";
var url = "http://bkapi.pptp.biz/userapi/?secretId="+secretId+"&secretKey="+secretKey+"&type=getuserinfo&user="+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["code"].ToString();
Console.WriteLine("---------------------------------------------------------------");
Console.WriteLine(jo);
Console.WriteLine("---------------------------------------------------------------");
if (status =="1")
{
var trData = new OriginAccountModel
{
Account = account,
Pwd = "",
AccountType = "",
Package = "",
RegistTime = "",
EndTime = jo["expiretime"].ToString(),
RestTime = "",
ConnectCount = jo["logincount"].ToString(),
Amount = "",
IsActive = "",
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)
{
var secretId = "626B6170693231";
var secretKey = "6b3fdfc206841f44c6609bf19c182a6a";
var url = "http://bkapi.pptp.biz/userapi/?secretId="+secretId+"&secretKey="+secretKey+"&type=setuser&user="+account+"&&new_pwd="+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["code"].ToString();
if (status =="1")
{
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)
{
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 secretId = "626B6170693231";
var secretKey = "6b3fdfc206841f44c6609bf19c182a6a";
var url = "http://bkapi.pptp.biz/userapi3/?secretId="+secretId+"&secretKey="+secretKey+"&type=get_user_onlinelog&user="+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["code"].ToString();
var retData = new List<OriginAccountOnlineModel>();
if (status =="1")
{
if(jo.ContainsKey("data")){
foreach (var tr in jo["data"])
{
JObject jsondata = (JObject)JsonConvert.DeserializeObject(tr.ToJson());
var trData = new OriginAccountOnlineModel
{
Account = account,
ServerIP = jsondata["server_ip"].ToString(),
LoginTime = "",
OnlineTime = jsondata["online_time"].ToString(),
LoginIP = jsondata["client_ip"].ToString(),
UpStream = "",
DownStream = "",
Id = "user="+account+"-address="+jsondata["address"].ToString()+"-server_ip="+jsondata["server_ip"].ToString(),
};
retData.Add(trData);
}
}
return new ApiResult<List<OriginAccountOnlineModel>>(retData);
} else {
return new ApiResult<List<OriginAccountOnlineModel>>(retData);
}
}
/// <summary>
/// 踢号
/// </summary>
/// <param name="productId"></param>
/// <param name="account"></param>
/// <returns></returns>
public override async Task<bool> KillOut(string id)
{
var ids = "";
if(id.Contains("-")){
string[] arrStr = id.Split('-');
ids = arrStr[0]+"&"+arrStr[1]+"&"+arrStr[2];
}
var secretId = "626B6170693231";
var secretKey = "6b3fdfc206841f44c6609bf19c182a6a";
var url = "http://bkapi.pptp.biz/userapi3/?secretId="+secretId+"&secretKey="+secretKey+"&type=user_online_offline&"+ids;
var client = CreateHttpClient();
var resp = await client.GetAsync(url);
var content = await resp.Content.ReadAsStringAsync();
JObject jo = (JObject)JsonConvert.DeserializeObject(content);
var status = jo["code"].ToString();
if (status =="1")
{
return true;
}
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;
}
public override async Task<bool> Exist(string account)
{
var secretId = "626B6170693231";
var secretKey = "6b3fdfc206841f44c6609bf19c182a6a";
var url = "http://bkapi.pptp.biz/userapi3/?secretId="+secretId+"&secretKey="+secretKey+"&type=getuserlenNum&user="+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["code"].ToString();
Console.WriteLine("================test==================================");
Console.WriteLine(jo);
Console.WriteLine("==================================================");
if (status =="1")
{
return false;
}
return true;
}
}
}
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;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
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)
{
if(packageKey == "free"){
return await NewTestAccount(packageKey, account, pwd, 1, accountType, 1);
}
var secretId = "626B6170693231";
var secretKey = "6b3fdfc206841f44c6609bf19c182a6a";
var url = "http://bkapi.pptp.biz/userapi/?secretId="+secretId+"&secretKey="+secretKey+"&type=adduser&user="+account+"&pass="+pwd+"&serverid="+packageKey+"&logincount="+connCount.ToString()+"&phone=17719092232&cardname=万永康&cardno=410325199810129916";
var client = CreateHttpClient();
var resp = await client.GetAsync(url);
var content = await resp.Content.ReadAsStringAsync();
JObject jo = (JObject)JsonConvert.DeserializeObject(content);
var status = jo["code"].ToString();
if (status =="1")
{
return new ApiResult(ResultCode.C_SUCCESS);
}
return new ApiResult(ResultCode.C_INVALID_ERROR, "开户失败");
}
/// <summary>
/// 新开
/// </summary>
/// <param name="packageId"></param>
/// <param name="account"></param>
/// <param name="pwd"></param>
/// <returns></returns>
public async Task<ApiResult> NewTestAccount(string packageKey, string account, string pwd, int connCount = 1, int accountType = 1, int payCount = 1)
{
var secretId = "626B6170693231";
var secretKey = "6b3fdfc206841f44c6609bf19c182a6a";
var url = "http://bkapi.pptp.biz/userapi3/?secretId="+secretId+"&secretKey="+secretKey+"&type=addtestuser&user="+account+"&password="+pwd+"&username3=admin01&phone=17719092232&cardname=万永康&cardno=410325199810129916";
var client = CreateHttpClient();
var resp = await client.GetAsync(url);
var content = await resp.Content.ReadAsStringAsync();
JObject jo = (JObject)JsonConvert.DeserializeObject(content);
var status = jo["code"].ToString();
Console.WriteLine("==================================================");
Console.WriteLine(jo);
Console.WriteLine("==================================================");
if (status =="1")
{
return new ApiResult(ResultCode.C_SUCCESS);
}
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 secretId = "626B6170693231";
var secretKey = "6b3fdfc206841f44c6609bf19c182a6a";
var url = "http://bkapi.pptp.biz/userapi/?secretId="+secretId+"&secretKey="+secretKey+"&type=buy&user="+account+"&serverid="+packageKey+"&logincount="+connCount.ToString()+"&phone=17719092232&cardname=万永康&cardno=410325199810129916";
var client = CreateHttpClient();
var resp = await client.GetAsync(url);
var content = await resp.Content.ReadAsStringAsync();
JObject jo = (JObject)JsonConvert.DeserializeObject(content);
var status = jo["code"].ToString();
if (status =="1")
{
return new ApiResult(1);
}
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>
/// <returns></returns>
public override async Task<ApiResult<OriginAccountModel>> GetAccountInfo(string account,bool isTest=false)
{
var secretId = "626B6170693231";
var secretKey = "6b3fdfc206841f44c6609bf19c182a6a";
var url = "http://bkapi.pptp.biz/userapi/?secretId="+secretId+"&secretKey="+secretKey+"&type=getuserinfo&user="+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["code"].ToString();
Console.WriteLine("---------------------------------------------------------------");
Console.WriteLine(jo);
Console.WriteLine("---------------------------------------------------------------");
if (status =="1")
{
var trData = new OriginAccountModel
{
Account = account,
Pwd = "",
AccountType = "",
Package = "",
RegistTime = "",
EndTime = jo["expiretime"].ToString(),
RestTime = "",
ConnectCount = jo["logincount"].ToString(),
Amount = "",
IsActive = "",
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)
{
var secretId = "626B6170693231";
var secretKey = "6b3fdfc206841f44c6609bf19c182a6a";
var url = "http://bkapi.pptp.biz/userapi/?secretId="+secretId+"&secretKey="+secretKey+"&type=setuser&user="+account+"&&new_pwd="+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["code"].ToString();
if (status =="1")
{
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)
{
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 secretId = "626B6170693231";
var secretKey = "6b3fdfc206841f44c6609bf19c182a6a";
var url = "http://bkapi.pptp.biz/userapi3/?secretId="+secretId+"&secretKey="+secretKey+"&type=get_user_onlinelog&user="+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["code"].ToString();
var retData = new List<OriginAccountOnlineModel>();
if (status =="1")
{
if(jo.ContainsKey("data")){
foreach (var tr in jo["data"])
{
JObject jsondata = (JObject)JsonConvert.DeserializeObject(tr.ToJson());
var trData = new OriginAccountOnlineModel
{
Account = account,
ServerIP = jsondata["server_ip"].ToString(),
LoginTime = "",
OnlineTime = jsondata["online_time"].ToString(),
LoginIP = jsondata["client_ip"].ToString(),
UpStream = "",
DownStream = "",
Id = "user="+account+"-address="+jsondata["address"].ToString()+"-server_ip="+jsondata["server_ip"].ToString(),
};
retData.Add(trData);
}
}
return new ApiResult<List<OriginAccountOnlineModel>>(retData);
} else {
return new ApiResult<List<OriginAccountOnlineModel>>(retData);
}
}
/// <summary>
/// 踢号
/// </summary>
/// <param name="productId"></param>
/// <param name="account"></param>
/// <returns></returns>
public override async Task<bool> KillOut(string id)
{
var ids = "";
if(id.Contains("-")){
string[] arrStr = id.Split('-');
ids = arrStr[0]+"&"+arrStr[1]+"&"+arrStr[2];
}
var secretId = "626B6170693231";
var secretKey = "6b3fdfc206841f44c6609bf19c182a6a";
var url = "http://bkapi.pptp.biz/userapi3/?secretId="+secretId+"&secretKey="+secretKey+"&type=user_online_offline&"+ids;
var client = CreateHttpClient();
var resp = await client.GetAsync(url);
var content = await resp.Content.ReadAsStringAsync();
JObject jo = (JObject)JsonConvert.DeserializeObject(content);
var status = jo["code"].ToString();
if (status =="1")
{
return true;
}
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;
}
public override async Task<bool> Exist(string account)
{
var secretId = "626B6170693231";
var secretKey = "6b3fdfc206841f44c6609bf19c182a6a";
var url = "http://bkapi.pptp.biz/userapi3/?secretId="+secretId+"&secretKey="+secretKey+"&type=getuserlenNum&user="+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["code"].ToString();
Console.WriteLine("================test==================================");
Console.WriteLine(jo);
Console.WriteLine("==================================================");
if (status =="1")
{
return false;
}
return true;
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,246 +1,246 @@
using Hncore.Infrastructure.Service;
using Hncore.Pass.Vpn.Domain;
using Hncore.Pass.Vpn.Request.Product;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Hncore.Infrastructure.Extension;
using Hncore.Infrastructure.WebApi;
using System.Diagnostics;
using System.IO;
using System.Net;
using Microsoft.EntityFrameworkCore;
using Hncore.Pass.Vpn.Model;
namespace Hncore.Pass.Vpn.Service
{
public abstract class AgentClientBaseService
{
protected string BaseUrl { get; set; }
protected string Token { get; set; }
string LoginUrl { get; set; }
string LoginCodeUrl { get; set; }
string RefrushTokenUrl { get; set; }
string SingleAddUrl { get; set; }
string SingleReAddUrl { get; set; }
string MuiltAddUrl { get; set; }
string RefundUrl { get; set; }
string OnlineUrl { get; set; }
string KIllUrl { get; set; }
string UpdateUrl { get; set; }
public string ClientName { get; set; }
public string Raw { get; set; }
IHttpClientFactory m_HttpClientFactory;
public AgentClientBaseService(IHttpClientFactory httpClientFactory)
{
m_HttpClientFactory = httpClientFactory;
}
public ProductEntity Product { get; set; }
public void Init(string BaseUrl,string Token)
{
this.BaseUrl = BaseUrl;
this.Token = Token;
}
public virtual string GetOpTitle(string op,string account)
{
return $"{this.ClientName}_{op}_{account}";
}
protected virtual HttpClient CreateHttpClient(bool autoCooke = true)
{
var client = m_HttpClientFactory.CreateClient("agentClient");
client.BaseAddress = new System.Uri(this.BaseUrl);
if (this.Token.Has()&& autoCooke)
{
AddCookie(client, this.Token);
}
return client;
}
public virtual string MD5(string password) {
byte[] textBytes = System.Text.Encoding.Default.GetBytes(password);
try {
System.Security.Cryptography.MD5CryptoServiceProvider cryptHandler;
cryptHandler = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] hash = cryptHandler.ComputeHash (textBytes);
string ret = "";
foreach (byte a in hash) {
if (a<16)
ret += "0" + a.ToString ("x");
else
ret += a.ToString ("x");
}
return ret ;
}
catch {
throw;
}
}
protected virtual void AddCookie(HttpClient client, string cookie)
{
client.DefaultRequestHeaders.Remove("Cookie");
client.DefaultRequestHeaders.Add("Cookie", cookie);
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + cookie);
}
public string GetCookie(HttpResponseMessage resp, string name)
{
if (resp.Headers.TryGetValues("Set-Cookie", out IEnumerable<string> cookies))
{
foreach (var cookie in cookies)
{
var ret = cookie.Split(";").FirstOrDefault(m => m.IndexOf(name) != -1);
if (ret.Has())
return ret;
}
}
return "";
}
public string GetCookies(HttpResponseMessage resp)
{
if (resp.Headers.TryGetValues("Set-Cookie", out IEnumerable<string> cookies))
{
return string.Join(";", cookies);
}
return "";
}
protected string GetCookieValue(string cookies, string name)
{
foreach (var item in cookies.Split(";"))
{
var token = item.Split("=");
if (token.Length == 2 && token[0] == name)
{
return token[1];
}
}
return "";
}
public virtual async Task<int> RefrushStatus()
{
return 0;
}
public virtual async Task<(byte[], string)> GetCode()
{
return (null, "");
}
public virtual async Task<ApiResult> Login(AgentLoginRequest request)
{
return new ApiResult();
}
public virtual 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 virtual async Task<ApiResult> NewAccount(string packageKey, string account,string pwd,int connCount=1,int accountType=1, int payCount = 1)
{
return new ApiResult();
}
public virtual async Task<ApiResult> NewMuiltAccount(string packageKey, string account, string pwd, int connCount = 1, int accountType = 1, int startNum = 0, int endNum = 1)
{
return new ApiResult();
}
/// <summary>
/// 续费
/// </summary>
/// <param name="productId"></param>
/// <param name="account"></param>
/// <param name="pwd"></param>
/// <returns></returns>
public virtual async Task<ApiResult> NewReAccount(string packageKey,string account,int connCount, int payCount = 1)
{
return new ApiResult();
}
/// <summary>
/// 删除账号
/// </summary>
/// <param name="productId"></param>
/// <param name="account"></param>
/// <returns></returns>
public virtual async Task<bool> DeleteAccount(string account)
{
return true;
}
/// <summary>
/// 得到账号信息
/// </summary>
/// <param name="productId"></param>
/// <param name="account"></param>
/// <returns></returns>
public virtual async Task<ApiResult<OriginAccountModel>> GetAccountInfo(string account, bool isTest = false)
{
return new ApiResult<OriginAccountModel>();
}
/// <summary>
/// 修改账号密码
/// </summary>
/// <param name="productId"></param>
/// <param name="account"></param>
/// <param name="pwd"></param>
/// <returns></returns>
public virtual async Task<bool> UpdateAccountPwd(string account,string pwd)
{
return true;
}
/// <summary>
/// 退款
/// </summary>
/// <param name="packageId"></param>
/// <param name="account"></param>
/// <returns></returns>
public virtual async Task<ApiResult> Refund(string account, string packageKey, int days)
{
return new ApiResult();
}
/// <summary>
/// 是否在线
/// </summary>
/// <param name="productId"></param>
/// <param name="account"></param>
/// <returns></returns>
public virtual async Task<ApiResult<List<OriginAccountOnlineModel>>> OnLine(string account)
{
return new ApiResult<List<OriginAccountOnlineModel>>();
}
/// <summary>
/// 踢号
/// </summary>
/// <param name="productId"></param>
/// <param name="account"></param>
/// <returns></returns>
public virtual async Task<bool> KillOut(string account)
{
return true;
}
/// <summary>
/// 是否存在
/// </summary>
/// <param name="account"></param>
/// <returns></returns>
public virtual async Task<bool> Exist(string account)
{
return true;
}
}
}
using Hncore.Infrastructure.Service;
using Hncore.Pass.Vpn.Domain;
using Hncore.Pass.Vpn.Request.Product;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Hncore.Infrastructure.Extension;
using Hncore.Infrastructure.WebApi;
using System.Diagnostics;
using System.IO;
using System.Net;
using Microsoft.EntityFrameworkCore;
using Hncore.Pass.Vpn.Model;
namespace Hncore.Pass.Vpn.Service
{
public abstract class AgentClientBaseService
{
protected string BaseUrl { get; set; }
protected string Token { get; set; }
string LoginUrl { get; set; }
string LoginCodeUrl { get; set; }
string RefrushTokenUrl { get; set; }
string SingleAddUrl { get; set; }
string SingleReAddUrl { get; set; }
string MuiltAddUrl { get; set; }
string RefundUrl { get; set; }
string OnlineUrl { get; set; }
string KIllUrl { get; set; }
string UpdateUrl { get; set; }
public string ClientName { get; set; }
public string Raw { get; set; }
IHttpClientFactory m_HttpClientFactory;
public AgentClientBaseService(IHttpClientFactory httpClientFactory)
{
m_HttpClientFactory = httpClientFactory;
}
public ProductEntity Product { get; set; }
public void Init(string BaseUrl,string Token)
{
this.BaseUrl = BaseUrl;
this.Token = Token;
}
public virtual string GetOpTitle(string op,string account)
{
return $"{this.ClientName}_{op}_{account}";
}
protected virtual HttpClient CreateHttpClient(bool autoCooke = true)
{
var client = m_HttpClientFactory.CreateClient("agentClient");
client.BaseAddress = new System.Uri(this.BaseUrl);
if (this.Token.Has()&& autoCooke)
{
AddCookie(client, this.Token);
}
return client;
}
public virtual string MD5(string password) {
byte[] textBytes = System.Text.Encoding.Default.GetBytes(password);
try {
System.Security.Cryptography.MD5CryptoServiceProvider cryptHandler;
cryptHandler = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] hash = cryptHandler.ComputeHash (textBytes);
string ret = "";
foreach (byte a in hash) {
if (a<16)
ret += "0" + a.ToString ("x");
else
ret += a.ToString ("x");
}
return ret ;
}
catch {
throw;
}
}
protected virtual void AddCookie(HttpClient client, string cookie)
{
client.DefaultRequestHeaders.Remove("Cookie");
client.DefaultRequestHeaders.Add("Cookie", cookie);
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + cookie);
}
public string GetCookie(HttpResponseMessage resp, string name)
{
if (resp.Headers.TryGetValues("Set-Cookie", out IEnumerable<string> cookies))
{
foreach (var cookie in cookies)
{
var ret = cookie.Split(";").FirstOrDefault(m => m.IndexOf(name) != -1);
if (ret.Has())
return ret;
}
}
return "";
}
public string GetCookies(HttpResponseMessage resp)
{
if (resp.Headers.TryGetValues("Set-Cookie", out IEnumerable<string> cookies))
{
return string.Join(";", cookies);
}
return "";
}
protected string GetCookieValue(string cookies, string name)
{
foreach (var item in cookies.Split(";"))
{
var token = item.Split("=");
if (token.Length == 2 && token[0] == name)
{
return token[1];
}
}
return "";
}
public virtual async Task<int> RefrushStatus()
{
return 0;
}
public virtual async Task<(byte[], string)> GetCode()
{
return (null, "");
}
public virtual async Task<ApiResult> Login(AgentLoginRequest request)
{
return new ApiResult();
}
public virtual 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 virtual async Task<ApiResult> NewAccount(string packageKey, string account,string pwd,int connCount=1,int accountType=1, int payCount = 1)
{
return new ApiResult();
}
public virtual async Task<ApiResult> NewMuiltAccount(string packageKey, string account, string pwd, int connCount = 1, int accountType = 1, int startNum = 0, int endNum = 1)
{
return new ApiResult();
}
/// <summary>
/// 续费
/// </summary>
/// <param name="productId"></param>
/// <param name="account"></param>
/// <param name="pwd"></param>
/// <returns></returns>
public virtual async Task<ApiResult> NewReAccount(string packageKey,string account,int connCount, int payCount = 1)
{
return new ApiResult();
}
/// <summary>
/// 删除账号
/// </summary>
/// <param name="productId"></param>
/// <param name="account"></param>
/// <returns></returns>
public virtual async Task<bool> DeleteAccount(string account)
{
return true;
}
/// <summary>
/// 得到账号信息
/// </summary>
/// <param name="productId"></param>
/// <param name="account"></param>
/// <returns></returns>
public virtual async Task<ApiResult<OriginAccountModel>> GetAccountInfo(string account, bool isTest = false)
{
return new ApiResult<OriginAccountModel>();
}
/// <summary>
/// 修改账号密码
/// </summary>
/// <param name="productId"></param>
/// <param name="account"></param>
/// <param name="pwd"></param>
/// <returns></returns>
public virtual async Task<bool> UpdateAccountPwd(string account,string pwd)
{
return true;
}
/// <summary>
/// 退款
/// </summary>
/// <param name="packageId"></param>
/// <param name="account"></param>
/// <returns></returns>
public virtual async Task<ApiResult> Refund(string account, string packageKey, int days)
{
return new ApiResult();
}
/// <summary>
/// 是否在线
/// </summary>
/// <param name="productId"></param>
/// <param name="account"></param>
/// <returns></returns>
public virtual async Task<ApiResult<List<OriginAccountOnlineModel>>> OnLine(string account)
{
return new ApiResult<List<OriginAccountOnlineModel>>();
}
/// <summary>
/// 踢号
/// </summary>
/// <param name="productId"></param>
/// <param name="account"></param>
/// <returns></returns>
public virtual async Task<bool> KillOut(string account)
{
return true;
}
/// <summary>
/// 是否存在
/// </summary>
/// <param name="account"></param>
/// <returns></returns>
public virtual async Task<bool> Exist(string account)
{
return true;
}
}
}

View File

@@ -1,21 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
namespace Hncore.Pass.Vpn.Service
{
public class AgentClientLogHandler : DelegatingHandler
{
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
if (request.Headers.Contains("hl"))
{
Console.WriteLine(request.RequestUri.ToString());
}
return base.SendAsync(request, cancellationToken);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
namespace Hncore.Pass.Vpn.Service
{
public class AgentClientLogHandler : DelegatingHandler
{
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
if (request.Headers.Contains("hl"))
{
Console.WriteLine(request.RequestUri.ToString());
}
return base.SendAsync(request, cancellationToken);
}
}
}

View File

@@ -1,442 +1,442 @@
using Hncore.Infrastructure.Common;
using Hncore.Infrastructure.Extension;
using Hncore.Infrastructure.Service;
using Hncore.Infrastructure.WebApi;
using Hncore.Pass.Vpn.Domain;
using Hncore.Pass.Vpn.Model;
using Hncore.Pass.Vpn.Request.Product;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
namespace Hncore.Pass.Vpn.Service
{
public class AgentService:IFindService
{
CourseContext m_DbContext;
IHttpClientFactory m_HttpClientFactory;
protected ProductService m_ProductService;
protected ProductPackageService m_ProductPackageService;
protected ProductPackageUnitService m_ProductPackageUnitService;
protected ProductEntity m_Product;
protected ProductAccountChargeService m_AccountChargeService;
protected Dictionary<string,AgentClientBaseService> m_MapAgentClient=new Dictionary<string, AgentClientBaseService>();
public AgentService(ProductService _ProductService
, ProductPackageService _ProductPackageService
, ProductPackageUnitService _ProductPackageUnitService
, ProductAccountChargeService _AccountChargeService
, IHttpClientFactory httpClientFactory
, CourseContext _DbContext)
{
m_HttpClientFactory = httpClientFactory;
m_ProductService = _ProductService;
m_ProductPackageService = _ProductPackageService;
m_ProductPackageUnitService = _ProductPackageUnitService;
m_AccountChargeService = _AccountChargeService;
m_DbContext = _DbContext;
}
protected AgentClientBaseService _AgentClient;
private AgentClientBaseService GetAgent(ProductEntity product)
{
AgentClientBaseService agent=null;
if (product.GroupNO == "g1")
agent = new AgentClient1Service(m_HttpClientFactory) { ClientName=product.GroupNO};
if (product.GroupNO == "g2")
agent = new AgentClient2Service(m_HttpClientFactory) { ClientName = product.GroupNO };
if (product.GroupNO == "g3")
agent = new AgentClient3Service(m_HttpClientFactory) { ClientName = product.GroupNO };
if (product.GroupNO == "g4")
agent = new AgentClient4Service(m_HttpClientFactory) { ClientName = product.GroupNO };
if (product.GroupNO == "g5")
agent = new AgentClient5Service(m_HttpClientFactory) { ClientName = product.GroupNO };
if (product.GroupNO == "g6")
agent = new AgentClient6Service(m_HttpClientFactory) { ClientName = product.GroupNO };
if (product.GroupNO == "g7")
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 };
if (product.GroupNO == "g10")
agent = new AgentClient10Service(m_HttpClientFactory) { ClientName = product.GroupNO };
if (product.GroupNO == "g11")
agent = new AgentClient11Service(m_HttpClientFactory) { ClientName = product.GroupNO };
if (product.GroupNO == "g12")
agent = new AgentClient12Service(m_HttpClientFactory) { ClientName = product.GroupNO };
if (product.GroupNO == "g13")
agent = new AgentClient13Service(m_HttpClientFactory) { ClientName = product.GroupNO };
if (product.GroupNO == "g14")
agent = new AgentClient14Service(m_HttpClientFactory) { ClientName = product.GroupNO };
if (product.GroupNO == "g15")
agent = new AgentClient15Service(m_HttpClientFactory) { ClientName = product.GroupNO };
if (product.GroupNO == "g16")
agent = new AgentClient16Service(m_HttpClientFactory) { ClientName = product.GroupNO };
if (product.GroupNO == "g17")
agent = new AgentClient17Service(m_HttpClientFactory) { ClientName = product.GroupNO };
if (product.GroupNO == "g18")
agent = new AgentClient18Service(m_HttpClientFactory) { ClientName = product.GroupNO };
if (product.GroupNO == "g19")
agent = new AgentClient19Service(m_HttpClientFactory) { ClientName = product.GroupNO };
agent.Product = product;
return agent;
}
public async Task RefrushAllStatus()
{
var products = await m_ProductService.Query(false).OrderBy(m=>m.Sort).ToListAsync();
await products.ForEachAsync(async m =>
{
// if (m.GroupNO == "g6")
await RefrushStatus(m);
});
}
public virtual async Task RefrushStatus(ProductEntity product)
{
var agent = GetAgent(product);
agent.Init(product.BaseUrl, product.Token);
int status = await agent.RefrushStatus();
if (product.Status != status)
{
product.UpdateTime = DateTime.Now;
product.Status = status;
await m_ProductService.Update(product);
}
if (product.Status == 0)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"{product.Name}:离线");
Console.ResetColor();
}
}
public virtual async Task<(byte[], string)> GetCode(int productId)
{
var product = await m_ProductService.GetById(productId);
var agent = GetAgent(product);
agent.Init(product.BaseUrl, product.Token);
return await agent.GetCode();
}
public virtual async Task<ApiResult> Login(AgentLoginRequest request)
{
var product = await m_ProductService.GetById(request.ProductId);
product.Token = request.Key;
var agent = GetAgent(product);
agent.Init(product.BaseUrl, product.Token);
request.Account = product.Account;
request.Pwd = product.Pwd;
var ret = await agent.Login(request);
if (ret.Code == ResultCode.C_SUCCESS)
{
product.Status = 1;
product.Token = ret.Data.ToString();
await m_ProductService.Update(product);
}
return ret;
}
public virtual async Task<ApiResult<List<OriginAccountModel>>> GetOriginAccounts(List<ProductAccountEntity> accountList)
{
var retList = new List<OriginAccountModel>();
foreach (var item in accountList)
{
var product = await m_ProductService.GetById(item.ProductId);
var agent = GetAgent(product);
agent.Init(product.BaseUrl, product.Token);
var account = item.Account;
// if (product.GroupNO == "g7") account = item.Raw;
var ret = await agent.GetAccountInfo(account);
if (ret.Code == ResultCode.C_SUCCESS)
retList.Add(ret.Data as OriginAccountModel);
}
return new ApiResult<List<OriginAccountModel>>(retList);
}
public virtual async Task<ApiResult<OriginAccountModel>> GetOriginAccountInfo(int productId, string account, string pwd = "")
{
var product = await m_ProductService.GetById(productId);
var agent = GetAgent(product);
agent.Init(product.BaseUrl, product.Token);
// if (product.GroupNO == "g7")
// {
// var accountInfo = await GetProductAccount(productId, account);
// if (accountInfo != null && accountInfo.Raw.Has())
// account = accountInfo.Raw;
// }
var ret = await agent.GetAccountInfo(account);
if (ret.Code != ResultCode.C_SUCCESS && product.Id!=17&& product.Id!=13) return new ApiResult<OriginAccountModel>(ResultCode.C_NOT_EXISTS_ERROR, "账号不存在");
if (pwd.Has()&&ret.Data.Pwd != pwd && product.Id!=17&& product.Id!=13)
return new ApiResult<OriginAccountModel>(ResultCode.C_NOT_EXISTS_ERROR, "密码不正确");
return ret;
}
public virtual async Task<List<OriginAccountModel>> GetOriginAccountInfo(int productId, List<string> accounts)
{
var list = new List<OriginAccountModel>();
var product = await m_ProductService.GetById(productId);
var agent = GetAgent(product);
agent.Init(product.BaseUrl, product.Token);
foreach (var item in accounts)
{
var account = item;
// if (product.GroupNO == "g7")
// {
// var accountInfo = await GetProductAccount(productId, item);
// if (accountInfo != null && accountInfo.Raw.Has())
// account = accountInfo.Raw;
// }
var ret = await agent.GetAccountInfo(account);
if (ret.Code == ResultCode.C_SUCCESS)
{
list.Add(ret.Data);
}
}
return list;
}
/// <summary>
/// 新开
/// </summary>
/// <param name="packageId"></param>
/// <param name="account"></param>
/// <param name="pwd"></param>
/// <returns></returns>
public virtual async Task<ApiResult> NewAccount(int orderId, int packageId, string account, string pwd, int connCount = 1, int accountType = 1,int payCount = 1)
{
ApiResult flagResult = new ApiResult(ResultCode.C_SUCCESS);
var package = await m_ProductPackageService.GetById(packageId);
var product = await m_ProductService.GetById(package.ProductId);
var agent = GetAgent(product);
agent.Init(product.BaseUrl, product.Token);
if (package.PackageType == PackageType.Base)
{
var ret = await agent.NewAccount(package.OriginKey, account, pwd, connCount, accountType,payCount);
//var ret = new ApiResult(ResultCode.C_INVALID_ERROR);
var status = ret.Code == ResultCode.C_SUCCESS ? ChargeStatus.Ok : ChargeStatus.Faild;
await m_AccountChargeService.RecordNew(package, orderId, product.GroupNO, account, pwd, accountType, connCount, status);
return ret;
}
else
{
var basePackages = await m_ProductPackageService.GetBasePackages(packageId);
var firstPackage = basePackages.FirstOrDefault();
basePackages.Remove(firstPackage);
if (firstPackage.Count > 1)
{
firstPackage.Count--;
basePackages.Insert(0, firstPackage);
}
var ret = await agent.NewAccount(firstPackage.Package.OriginKey, account, pwd, connCount, accountType,payCount);
//var ret = new ApiResult(ResultCode.C_INVALID_ERROR);
var status = ret.Code == ResultCode.C_SUCCESS ? ChargeStatus.Ok : ChargeStatus.Faild;
await m_AccountChargeService.RecordNew(firstPackage.Package, orderId, product.GroupNO, account, pwd, accountType, connCount, status);
if (ret.Code != ResultCode.C_SUCCESS)
flagResult = ret;
foreach (var item in basePackages)
{
for (var j = 0; j < item.Count; j++)
{
ret = await agent.NewReAccount(item.Package.OriginKey, account, connCount);
// ret = new ApiResult(ResultCode.C_INVALID_ERROR);
status = ret.Code == ResultCode.C_SUCCESS ? ChargeStatus.Ok : ChargeStatus.Faild;
await m_AccountChargeService.RecordReNew(item.Package, orderId, product.GroupNO, account, connCount, status);
if (ret.Code != ResultCode.C_SUCCESS)
flagResult = ret;
}
}
return flagResult;
}
}
/// <summary>
/// 续费
/// </summary>
/// <param name="productId"></param>
/// <param name="account"></param>
/// <param name="pwd"></param>
/// <returns></returns>
public virtual async Task<ApiResult> ReNewAccount(int orderId, int packageId, string account, int connCount,int payCount = 1)
{
var package = await m_ProductPackageService.GetById(packageId);
var product = await m_ProductService.GetById(package.ProductId);
// if (product.GroupNO == "g7")
// {
// var accountInfo = await GetProductAccount(package.ProductId, account);
// if (accountInfo != null && accountInfo.Raw.Has())
// account = accountInfo.Raw;
// }
var agent = GetAgent(product);
agent.Init(product.BaseUrl, product.Token);
ApiResult flagResult = new ApiResult(ResultCode.C_SUCCESS);
if (package.PackageType == PackageType.Base)
{
var ret = await agent.NewReAccount(package.OriginKey, account, connCount,payCount);
// var ret = new ApiResult(ResultCode.C_INVALID_ERROR);
var status = ret.Code == ResultCode.C_SUCCESS ? ChargeStatus.Ok : ChargeStatus.Faild;
await m_AccountChargeService.RecordReNew(package, orderId, product.GroupNO, account, connCount, status);
return ret;
}
else
{
var basePackages = await m_ProductPackageService.GetBasePackages(packageId);
foreach (var basePackage in basePackages)
{
for (var j = 0; j < basePackage.Count; j++)
{
var ret = await agent.NewReAccount(basePackage.Package.OriginKey, account, connCount,payCount);
//var ret = new ApiResult(ResultCode.C_INVALID_ERROR);
var status = ret.Code == ResultCode.C_SUCCESS ? ChargeStatus.Ok : ChargeStatus.Faild;
await m_AccountChargeService.RecordReNew(basePackage.Package, orderId, product.GroupNO, account, connCount, status);
if (status == ChargeStatus.Faild) flagResult = ret;
}
}
return flagResult;
}
}
/// <summary>
/// 删除账号
/// </summary>
/// <param name="productId"></param>
/// <param name="account"></param>
/// <returns></returns>
public virtual bool DeleteAccount(int productId, string account)
{
return true;
}
/// <summary>
/// 修改账号密码
/// </summary>
/// <param name="productId"></param>
/// <param name="account"></param>
/// <param name="pwd"></param>
/// <returns></returns>
public virtual async Task<bool> UpdateAccountPwd(int productId, string account, string pwd)
{
var product = await m_ProductService.GetById(productId);
var agent = GetAgent(product);
agent.Init(product.BaseUrl, product.Token);
// if (product.GroupNO == "g7")
// {
// var accountInfo = await GetProductAccount(productId, account);
// if (accountInfo != null && accountInfo.Raw.Has())
// agent.Raw = accountInfo.Raw;
// }
return await agent.UpdateAccountPwd(account, pwd);
}
/// <summary>
/// 退款
/// </summary>
/// <param name="packageId"></param>
/// <param name="account"></param>
/// <returns></returns>
public virtual async Task<ApiResult> Refund(ProductPackageEntity package, ProductAccountEntity accountInfo)
{
var product = await m_ProductService.GetById(package.ProductId);
var agent = GetAgent(product);
agent.Init(product.BaseUrl, product.Token);
var account = accountInfo.Account;
// if (product.GroupNO == "g7")
// {
// if (accountInfo != null && accountInfo.Raw.Has())
// account = accountInfo.Raw;
// }
var flag = await agent.Refund(account, package.OriginKey, accountInfo.RestDay);
return flag;
}
/// <summary>
/// 是否在线
/// </summary>
/// <param name="productId"></param>
/// <param name="account"></param>
/// <returns></returns>
public virtual async Task<ApiResult<List<OriginAccountOnlineModel>>> OnLine(int productId, string account)
{
var product = await m_ProductService.GetById(productId);
var agent = GetAgent(product);
agent.Init(product.BaseUrl, product.Token);
return await agent.OnLine(account);
}
/// <summary>
/// 踢号
/// </summary>
/// <param name="productId"></param>
/// <param name="account"></param>
/// <returns></returns>
public virtual async Task<bool> KillOut(int productId, string id)
{
var product = await m_ProductService.GetById(productId);
var agent = GetAgent(product);
agent.Init(product.BaseUrl, product.Token);
return await agent.KillOut(id);
}
/// <summary>
/// 是否存在
/// </summary>
/// <param name="account"></param>
/// <returns></returns>
public async Task<bool> Exist(int productId, string account)
{
var product = await m_ProductService.GetById(productId);
var agent = GetAgent(product);
agent.Init(product.BaseUrl, product.Token);
return await agent.Exist(account);
}
public async Task FaildTry()
{
var records = await m_AccountChargeService.GetFaildRecord();
foreach (var chargeEntity in records)
{
if (chargeEntity.Status != ChargeStatus.Faild)
{
continue;
}
if (chargeEntity.TryTimes > 3)
{
chargeEntity.Status = ChargeStatus.Outtime;
chargeEntity.UpdateTime = DateTime.Now;
await m_AccountChargeService.Update(chargeEntity);
continue;
}
var product = await m_ProductService.GetById(chargeEntity.ProductId);
var agent = GetAgent(product);
agent.Init(product.BaseUrl, product.Token);
if (chargeEntity.OperationType == ChargeOperationType.New)
{
var ret = await agent.NewAccount(chargeEntity.PackageOriginKey, chargeEntity.Account, chargeEntity.Pwd, chargeEntity.ConnectCount, chargeEntity.AccountType);
var status = ret.Code == ResultCode.C_SUCCESS ? ChargeStatus.Ok : ChargeStatus.Faild;
chargeEntity.Status = status;
chargeEntity.TryTimes++;
chargeEntity.UpdateTime = DateTime.Now;
await m_AccountChargeService.Update(chargeEntity);
}else if(chargeEntity.OperationType == ChargeOperationType.ReNew)
{
var ret = await agent.NewReAccount(chargeEntity.PackageOriginKey, chargeEntity.Account, chargeEntity.ConnectCount);
// var ret = new ApiResult(ResultCode.C_INVALID_ERROR);
var status = ret.Code == ResultCode.C_SUCCESS ? ChargeStatus.Ok : ChargeStatus.Faild;
chargeEntity.Status = status;
chargeEntity.TryTimes++;
chargeEntity.UpdateTime = DateTime.Now;
await m_AccountChargeService.Update(chargeEntity);
}
}
}
protected async Task<ProductAccountEntity> GetProductAccount(int productId, string account)
{
return await m_DbContext.Set<ProductAccountEntity>().FirstOrDefaultAsync(m => m.ProductId == productId && m.Account == account);
}
}
}
using Hncore.Infrastructure.Common;
using Hncore.Infrastructure.Extension;
using Hncore.Infrastructure.Service;
using Hncore.Infrastructure.WebApi;
using Hncore.Pass.Vpn.Domain;
using Hncore.Pass.Vpn.Model;
using Hncore.Pass.Vpn.Request.Product;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
namespace Hncore.Pass.Vpn.Service
{
public class AgentService:IFindService
{
CourseContext m_DbContext;
IHttpClientFactory m_HttpClientFactory;
protected ProductService m_ProductService;
protected ProductPackageService m_ProductPackageService;
protected ProductPackageUnitService m_ProductPackageUnitService;
protected ProductEntity m_Product;
protected ProductAccountChargeService m_AccountChargeService;
protected Dictionary<string,AgentClientBaseService> m_MapAgentClient=new Dictionary<string, AgentClientBaseService>();
public AgentService(ProductService _ProductService
, ProductPackageService _ProductPackageService
, ProductPackageUnitService _ProductPackageUnitService
, ProductAccountChargeService _AccountChargeService
, IHttpClientFactory httpClientFactory
, CourseContext _DbContext)
{
m_HttpClientFactory = httpClientFactory;
m_ProductService = _ProductService;
m_ProductPackageService = _ProductPackageService;
m_ProductPackageUnitService = _ProductPackageUnitService;
m_AccountChargeService = _AccountChargeService;
m_DbContext = _DbContext;
}
protected AgentClientBaseService _AgentClient;
private AgentClientBaseService GetAgent(ProductEntity product)
{
AgentClientBaseService agent=null;
if (product.GroupNO == "g1")
agent = new AgentClient1Service(m_HttpClientFactory) { ClientName=product.GroupNO};
if (product.GroupNO == "g2")
agent = new AgentClient2Service(m_HttpClientFactory) { ClientName = product.GroupNO };
if (product.GroupNO == "g3")
agent = new AgentClient3Service(m_HttpClientFactory) { ClientName = product.GroupNO };
if (product.GroupNO == "g4")
agent = new AgentClient4Service(m_HttpClientFactory) { ClientName = product.GroupNO };
if (product.GroupNO == "g5")
agent = new AgentClient5Service(m_HttpClientFactory) { ClientName = product.GroupNO };
if (product.GroupNO == "g6")
agent = new AgentClient6Service(m_HttpClientFactory) { ClientName = product.GroupNO };
if (product.GroupNO == "g7")
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 };
if (product.GroupNO == "g10")
agent = new AgentClient10Service(m_HttpClientFactory) { ClientName = product.GroupNO };
if (product.GroupNO == "g11")
agent = new AgentClient11Service(m_HttpClientFactory) { ClientName = product.GroupNO };
if (product.GroupNO == "g12")
agent = new AgentClient12Service(m_HttpClientFactory) { ClientName = product.GroupNO };
if (product.GroupNO == "g13")
agent = new AgentClient13Service(m_HttpClientFactory) { ClientName = product.GroupNO };
if (product.GroupNO == "g14")
agent = new AgentClient14Service(m_HttpClientFactory) { ClientName = product.GroupNO };
if (product.GroupNO == "g15")
agent = new AgentClient15Service(m_HttpClientFactory) { ClientName = product.GroupNO };
if (product.GroupNO == "g16")
agent = new AgentClient16Service(m_HttpClientFactory) { ClientName = product.GroupNO };
if (product.GroupNO == "g17")
agent = new AgentClient17Service(m_HttpClientFactory) { ClientName = product.GroupNO };
if (product.GroupNO == "g18")
agent = new AgentClient18Service(m_HttpClientFactory) { ClientName = product.GroupNO };
if (product.GroupNO == "g19")
agent = new AgentClient19Service(m_HttpClientFactory) { ClientName = product.GroupNO };
agent.Product = product;
return agent;
}
public async Task RefrushAllStatus()
{
var products = await m_ProductService.Query(false).OrderBy(m=>m.Sort).ToListAsync();
await products.ForEachAsync(async m =>
{
// if (m.GroupNO == "g6")
await RefrushStatus(m);
});
}
public virtual async Task RefrushStatus(ProductEntity product)
{
var agent = GetAgent(product);
agent.Init(product.BaseUrl, product.Token);
int status = await agent.RefrushStatus();
if (product.Status != status)
{
product.UpdateTime = DateTime.Now;
product.Status = status;
await m_ProductService.Update(product);
}
if (product.Status == 0)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"{product.Name}:离线");
Console.ResetColor();
}
}
public virtual async Task<(byte[], string)> GetCode(int productId)
{
var product = await m_ProductService.GetById(productId);
var agent = GetAgent(product);
agent.Init(product.BaseUrl, product.Token);
return await agent.GetCode();
}
public virtual async Task<ApiResult> Login(AgentLoginRequest request)
{
var product = await m_ProductService.GetById(request.ProductId);
product.Token = request.Key;
var agent = GetAgent(product);
agent.Init(product.BaseUrl, product.Token);
request.Account = product.Account;
request.Pwd = product.Pwd;
var ret = await agent.Login(request);
if (ret.Code == ResultCode.C_SUCCESS)
{
product.Status = 1;
product.Token = ret.Data.ToString();
await m_ProductService.Update(product);
}
return ret;
}
public virtual async Task<ApiResult<List<OriginAccountModel>>> GetOriginAccounts(List<ProductAccountEntity> accountList)
{
var retList = new List<OriginAccountModel>();
foreach (var item in accountList)
{
var product = await m_ProductService.GetById(item.ProductId);
var agent = GetAgent(product);
agent.Init(product.BaseUrl, product.Token);
var account = item.Account;
// if (product.GroupNO == "g7") account = item.Raw;
var ret = await agent.GetAccountInfo(account);
if (ret.Code == ResultCode.C_SUCCESS)
retList.Add(ret.Data as OriginAccountModel);
}
return new ApiResult<List<OriginAccountModel>>(retList);
}
public virtual async Task<ApiResult<OriginAccountModel>> GetOriginAccountInfo(int productId, string account, string pwd = "")
{
var product = await m_ProductService.GetById(productId);
var agent = GetAgent(product);
agent.Init(product.BaseUrl, product.Token);
// if (product.GroupNO == "g7")
// {
// var accountInfo = await GetProductAccount(productId, account);
// if (accountInfo != null && accountInfo.Raw.Has())
// account = accountInfo.Raw;
// }
var ret = await agent.GetAccountInfo(account);
if (ret.Code != ResultCode.C_SUCCESS && product.Id!=17&& product.Id!=13) return new ApiResult<OriginAccountModel>(ResultCode.C_NOT_EXISTS_ERROR, "账号不存在");
if (pwd.Has()&&ret.Data.Pwd != pwd && product.Id!=17&& product.Id!=13)
return new ApiResult<OriginAccountModel>(ResultCode.C_NOT_EXISTS_ERROR, "密码不正确");
return ret;
}
public virtual async Task<List<OriginAccountModel>> GetOriginAccountInfo(int productId, List<string> accounts)
{
var list = new List<OriginAccountModel>();
var product = await m_ProductService.GetById(productId);
var agent = GetAgent(product);
agent.Init(product.BaseUrl, product.Token);
foreach (var item in accounts)
{
var account = item;
// if (product.GroupNO == "g7")
// {
// var accountInfo = await GetProductAccount(productId, item);
// if (accountInfo != null && accountInfo.Raw.Has())
// account = accountInfo.Raw;
// }
var ret = await agent.GetAccountInfo(account);
if (ret.Code == ResultCode.C_SUCCESS)
{
list.Add(ret.Data);
}
}
return list;
}
/// <summary>
/// 新开
/// </summary>
/// <param name="packageId"></param>
/// <param name="account"></param>
/// <param name="pwd"></param>
/// <returns></returns>
public virtual async Task<ApiResult> NewAccount(int orderId, int packageId, string account, string pwd, int connCount = 1, int accountType = 1,int payCount = 1)
{
ApiResult flagResult = new ApiResult(ResultCode.C_SUCCESS);
var package = await m_ProductPackageService.GetById(packageId);
var product = await m_ProductService.GetById(package.ProductId);
var agent = GetAgent(product);
agent.Init(product.BaseUrl, product.Token);
if (package.PackageType == PackageType.Base)
{
var ret = await agent.NewAccount(package.OriginKey, account, pwd, connCount, accountType,payCount);
//var ret = new ApiResult(ResultCode.C_INVALID_ERROR);
var status = ret.Code == ResultCode.C_SUCCESS ? ChargeStatus.Ok : ChargeStatus.Faild;
await m_AccountChargeService.RecordNew(package, orderId, product.GroupNO, account, pwd, accountType, connCount, status);
return ret;
}
else
{
var basePackages = await m_ProductPackageService.GetBasePackages(packageId);
var firstPackage = basePackages.FirstOrDefault();
basePackages.Remove(firstPackage);
if (firstPackage.Count > 1)
{
firstPackage.Count--;
basePackages.Insert(0, firstPackage);
}
var ret = await agent.NewAccount(firstPackage.Package.OriginKey, account, pwd, connCount, accountType,payCount);
//var ret = new ApiResult(ResultCode.C_INVALID_ERROR);
var status = ret.Code == ResultCode.C_SUCCESS ? ChargeStatus.Ok : ChargeStatus.Faild;
await m_AccountChargeService.RecordNew(firstPackage.Package, orderId, product.GroupNO, account, pwd, accountType, connCount, status);
if (ret.Code != ResultCode.C_SUCCESS)
flagResult = ret;
foreach (var item in basePackages)
{
for (var j = 0; j < item.Count; j++)
{
ret = await agent.NewReAccount(item.Package.OriginKey, account, connCount);
// ret = new ApiResult(ResultCode.C_INVALID_ERROR);
status = ret.Code == ResultCode.C_SUCCESS ? ChargeStatus.Ok : ChargeStatus.Faild;
await m_AccountChargeService.RecordReNew(item.Package, orderId, product.GroupNO, account, connCount, status);
if (ret.Code != ResultCode.C_SUCCESS)
flagResult = ret;
}
}
return flagResult;
}
}
/// <summary>
/// 续费
/// </summary>
/// <param name="productId"></param>
/// <param name="account"></param>
/// <param name="pwd"></param>
/// <returns></returns>
public virtual async Task<ApiResult> ReNewAccount(int orderId, int packageId, string account, int connCount,int payCount = 1)
{
var package = await m_ProductPackageService.GetById(packageId);
var product = await m_ProductService.GetById(package.ProductId);
// if (product.GroupNO == "g7")
// {
// var accountInfo = await GetProductAccount(package.ProductId, account);
// if (accountInfo != null && accountInfo.Raw.Has())
// account = accountInfo.Raw;
// }
var agent = GetAgent(product);
agent.Init(product.BaseUrl, product.Token);
ApiResult flagResult = new ApiResult(ResultCode.C_SUCCESS);
if (package.PackageType == PackageType.Base)
{
var ret = await agent.NewReAccount(package.OriginKey, account, connCount,payCount);
// var ret = new ApiResult(ResultCode.C_INVALID_ERROR);
var status = ret.Code == ResultCode.C_SUCCESS ? ChargeStatus.Ok : ChargeStatus.Faild;
await m_AccountChargeService.RecordReNew(package, orderId, product.GroupNO, account, connCount, status);
return ret;
}
else
{
var basePackages = await m_ProductPackageService.GetBasePackages(packageId);
foreach (var basePackage in basePackages)
{
for (var j = 0; j < basePackage.Count; j++)
{
var ret = await agent.NewReAccount(basePackage.Package.OriginKey, account, connCount,payCount);
//var ret = new ApiResult(ResultCode.C_INVALID_ERROR);
var status = ret.Code == ResultCode.C_SUCCESS ? ChargeStatus.Ok : ChargeStatus.Faild;
await m_AccountChargeService.RecordReNew(basePackage.Package, orderId, product.GroupNO, account, connCount, status);
if (status == ChargeStatus.Faild) flagResult = ret;
}
}
return flagResult;
}
}
/// <summary>
/// 删除账号
/// </summary>
/// <param name="productId"></param>
/// <param name="account"></param>
/// <returns></returns>
public virtual bool DeleteAccount(int productId, string account)
{
return true;
}
/// <summary>
/// 修改账号密码
/// </summary>
/// <param name="productId"></param>
/// <param name="account"></param>
/// <param name="pwd"></param>
/// <returns></returns>
public virtual async Task<bool> UpdateAccountPwd(int productId, string account, string pwd)
{
var product = await m_ProductService.GetById(productId);
var agent = GetAgent(product);
agent.Init(product.BaseUrl, product.Token);
// if (product.GroupNO == "g7")
// {
// var accountInfo = await GetProductAccount(productId, account);
// if (accountInfo != null && accountInfo.Raw.Has())
// agent.Raw = accountInfo.Raw;
// }
return await agent.UpdateAccountPwd(account, pwd);
}
/// <summary>
/// 退款
/// </summary>
/// <param name="packageId"></param>
/// <param name="account"></param>
/// <returns></returns>
public virtual async Task<ApiResult> Refund(ProductPackageEntity package, ProductAccountEntity accountInfo)
{
var product = await m_ProductService.GetById(package.ProductId);
var agent = GetAgent(product);
agent.Init(product.BaseUrl, product.Token);
var account = accountInfo.Account;
// if (product.GroupNO == "g7")
// {
// if (accountInfo != null && accountInfo.Raw.Has())
// account = accountInfo.Raw;
// }
var flag = await agent.Refund(account, package.OriginKey, accountInfo.RestDay);
return flag;
}
/// <summary>
/// 是否在线
/// </summary>
/// <param name="productId"></param>
/// <param name="account"></param>
/// <returns></returns>
public virtual async Task<ApiResult<List<OriginAccountOnlineModel>>> OnLine(int productId, string account)
{
var product = await m_ProductService.GetById(productId);
var agent = GetAgent(product);
agent.Init(product.BaseUrl, product.Token);
return await agent.OnLine(account);
}
/// <summary>
/// 踢号
/// </summary>
/// <param name="productId"></param>
/// <param name="account"></param>
/// <returns></returns>
public virtual async Task<bool> KillOut(int productId, string id)
{
var product = await m_ProductService.GetById(productId);
var agent = GetAgent(product);
agent.Init(product.BaseUrl, product.Token);
return await agent.KillOut(id);
}
/// <summary>
/// 是否存在
/// </summary>
/// <param name="account"></param>
/// <returns></returns>
public async Task<bool> Exist(int productId, string account)
{
var product = await m_ProductService.GetById(productId);
var agent = GetAgent(product);
agent.Init(product.BaseUrl, product.Token);
return await agent.Exist(account);
}
public async Task FaildTry()
{
var records = await m_AccountChargeService.GetFaildRecord();
foreach (var chargeEntity in records)
{
if (chargeEntity.Status != ChargeStatus.Faild)
{
continue;
}
if (chargeEntity.TryTimes > 3)
{
chargeEntity.Status = ChargeStatus.Outtime;
chargeEntity.UpdateTime = DateTime.Now;
await m_AccountChargeService.Update(chargeEntity);
continue;
}
var product = await m_ProductService.GetById(chargeEntity.ProductId);
var agent = GetAgent(product);
agent.Init(product.BaseUrl, product.Token);
if (chargeEntity.OperationType == ChargeOperationType.New)
{
var ret = await agent.NewAccount(chargeEntity.PackageOriginKey, chargeEntity.Account, chargeEntity.Pwd, chargeEntity.ConnectCount, chargeEntity.AccountType);
var status = ret.Code == ResultCode.C_SUCCESS ? ChargeStatus.Ok : ChargeStatus.Faild;
chargeEntity.Status = status;
chargeEntity.TryTimes++;
chargeEntity.UpdateTime = DateTime.Now;
await m_AccountChargeService.Update(chargeEntity);
}else if(chargeEntity.OperationType == ChargeOperationType.ReNew)
{
var ret = await agent.NewReAccount(chargeEntity.PackageOriginKey, chargeEntity.Account, chargeEntity.ConnectCount);
// var ret = new ApiResult(ResultCode.C_INVALID_ERROR);
var status = ret.Code == ResultCode.C_SUCCESS ? ChargeStatus.Ok : ChargeStatus.Faild;
chargeEntity.Status = status;
chargeEntity.TryTimes++;
chargeEntity.UpdateTime = DateTime.Now;
await m_AccountChargeService.Update(chargeEntity);
}
}
}
protected async Task<ProductAccountEntity> GetProductAccount(int productId, string account)
{
return await m_DbContext.Set<ProductAccountEntity>().FirstOrDefaultAsync(m => m.ProductId == productId && m.Account == account);
}
}
}

View File

@@ -1,25 +1,25 @@
using Hncore.Infrastructure.Service;
using Hncore.Pass.Vpn.Domain;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Hncore.Pass.Vpn.Service
{
public partial class ArticleService : ServiceBase<ArticleEntity>, IFindService
{
CourseContext m_DbContext;
public ArticleService(CourseContext dbContext, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
{
m_DbContext = dbContext;
}
public async Task<List<ArticleEntity>> GetTop(int top, ArticleCatalog catalog)
{
return await this.Query(m => m.CatalogId == catalog).OrderByDescending(m => m.Id).Take(top).ToListAsync();
}
}
}
using Hncore.Infrastructure.Service;
using Hncore.Pass.Vpn.Domain;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Hncore.Pass.Vpn.Service
{
public partial class ArticleService : ServiceBase<ArticleEntity>, IFindService
{
CourseContext m_DbContext;
public ArticleService(CourseContext dbContext, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
{
m_DbContext = dbContext;
}
public async Task<List<ArticleEntity>> GetTop(int top, ArticleCatalog catalog)
{
return await this.Query(m => m.CatalogId == catalog).OrderByDescending(m => m.Id).Take(top).ToListAsync();
}
}
}

View File

@@ -1,96 +1,96 @@
using Hncore.Infrastructure.Service;
using Hncore.Pass.Vpn.Domain;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Hncore.Pass.Vpn.Service
{
public partial class ProductAccountChargeService : ServiceBase<ProductAccountChargeEntity>, IFindService
{
CourseContext m_DbContext;
public ProductAccountChargeService(CourseContext dbContext
, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
{
m_DbContext = dbContext;
}
/// <summary>
/// 记录新开操作
/// </summary>
/// <param name="package"></param>
/// <param name="orderId"></param>
/// <param name="gid"></param>
/// <param name="account"></param>
/// <param name="pwd"></param>
/// <param name="accountType"></param>
/// <param name="connCount"></param>
/// <param name="chargeStatus"></param>
/// <returns></returns>
public async Task RecordNew(ProductPackageEntity package, int orderId, string gid, string account, string pwd, int accountType, int connCount, ChargeStatus chargeStatus = ChargeStatus.Ok)
{
var chargeEntity = new ProductAccountChargeEntity()
{
Account = account,
AccountType = accountType,
ConnectCount = connCount,
OperationType = ChargeOperationType.New,
OrderId = orderId,
PackageId = package.Id,
PackageOriginKey = package.OriginKey,
ProductGroup = gid,
ProductId = package.ProductId,
Pwd = pwd,
Status = chargeStatus,
TryTimes = 1,
};
await this.Add(chargeEntity);
}
/// <summary>
/// 记录续费操作
/// </summary>
/// <param name="package"></param>
/// <param name="orderId"></param>
/// <param name="gid"></param>
/// <param name="account"></param>
/// <param name="pwd"></param>
/// <param name="accountType"></param>
/// <param name="connCount"></param>
/// <param name="chargeStatus"></param>
/// <returns></returns>
public async Task RecordReNew(ProductPackageEntity package, int orderId, string gid, string account, int connCount, ChargeStatus chargeStatus = ChargeStatus.Ok)
{
var chargeEntity = new ProductAccountChargeEntity()
{
Account = account,
AccountType =0,
ConnectCount = connCount,
OperationType = ChargeOperationType.ReNew,
OrderId = orderId,
PackageId = package.Id,
PackageOriginKey = package.OriginKey,
ProductGroup = gid,
ProductId = package.ProductId,
Pwd = "",
Status = chargeStatus,
TryTimes = 1,
};
await this.Add(chargeEntity);
}
public async Task<List<ProductAccountChargeEntity>> GetFaildRecord(int maxTryTimes = 3, int maxTop = 100)
{
var query = this.Query(m => m.Status == ChargeStatus.Faild
&& m.TryTimes <= maxTryTimes
&& (DateTime.Now - m.CreateTime).Minutes <= 10);
return await query.OrderBy(m => m.Id)
.Take(maxTop)
.ToListAsync();
}
}
}
using Hncore.Infrastructure.Service;
using Hncore.Pass.Vpn.Domain;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Hncore.Pass.Vpn.Service
{
public partial class ProductAccountChargeService : ServiceBase<ProductAccountChargeEntity>, IFindService
{
CourseContext m_DbContext;
public ProductAccountChargeService(CourseContext dbContext
, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
{
m_DbContext = dbContext;
}
/// <summary>
/// 记录新开操作
/// </summary>
/// <param name="package"></param>
/// <param name="orderId"></param>
/// <param name="gid"></param>
/// <param name="account"></param>
/// <param name="pwd"></param>
/// <param name="accountType"></param>
/// <param name="connCount"></param>
/// <param name="chargeStatus"></param>
/// <returns></returns>
public async Task RecordNew(ProductPackageEntity package, int orderId, string gid, string account, string pwd, int accountType, int connCount, ChargeStatus chargeStatus = ChargeStatus.Ok)
{
var chargeEntity = new ProductAccountChargeEntity()
{
Account = account,
AccountType = accountType,
ConnectCount = connCount,
OperationType = ChargeOperationType.New,
OrderId = orderId,
PackageId = package.Id,
PackageOriginKey = package.OriginKey,
ProductGroup = gid,
ProductId = package.ProductId,
Pwd = pwd,
Status = chargeStatus,
TryTimes = 1,
};
await this.Add(chargeEntity);
}
/// <summary>
/// 记录续费操作
/// </summary>
/// <param name="package"></param>
/// <param name="orderId"></param>
/// <param name="gid"></param>
/// <param name="account"></param>
/// <param name="pwd"></param>
/// <param name="accountType"></param>
/// <param name="connCount"></param>
/// <param name="chargeStatus"></param>
/// <returns></returns>
public async Task RecordReNew(ProductPackageEntity package, int orderId, string gid, string account, int connCount, ChargeStatus chargeStatus = ChargeStatus.Ok)
{
var chargeEntity = new ProductAccountChargeEntity()
{
Account = account,
AccountType =0,
ConnectCount = connCount,
OperationType = ChargeOperationType.ReNew,
OrderId = orderId,
PackageId = package.Id,
PackageOriginKey = package.OriginKey,
ProductGroup = gid,
ProductId = package.ProductId,
Pwd = "",
Status = chargeStatus,
TryTimes = 1,
};
await this.Add(chargeEntity);
}
public async Task<List<ProductAccountChargeEntity>> GetFaildRecord(int maxTryTimes = 3, int maxTop = 100)
{
var query = this.Query(m => m.Status == ChargeStatus.Faild
&& m.TryTimes <= maxTryTimes
&& (DateTime.Now - m.CreateTime).Minutes <= 10);
return await query.OrderBy(m => m.Id)
.Take(maxTop)
.ToListAsync();
}
}
}

View File

@@ -1,197 +1,197 @@
using HHncore.Pass.Vpn.Request.Product;
using Hncore.Infrastructure.Common;
using Hncore.Infrastructure.Extension;
using Hncore.Infrastructure.Service;
using Hncore.Infrastructure.WebApi;
using Hncore.Pass.Vpn.Domain;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Hncore.Infrastructure.EntitiesExtension;
using Hncore.Infrastructure.EF;
namespace Hncore.Pass.Vpn.Service
{
public partial class ProductAccountService : ServiceBase<ProductAccountEntity>, IFindService
{
CourseContext m_DbContext;
private IConfiguration m_Configuration;
public AgentService m_AgentService;
private UserService m_UserService;
public ProductAccountService(CourseContext dbContext
, AgentService _AgentService
, UserService _UserService
, IConfiguration _Configuration
, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
{
m_DbContext = dbContext;
m_AgentService = _AgentService;
m_Configuration = _Configuration;
m_UserService = _UserService;
}
public async Task<bool> CheckAccountExist(int productId, List<string> accouts)
{
var flag = this.Exist(m => accouts.Contains(m.Account) && m.DeleteTag == 0);
if (flag)
{
return true;
}
foreach (var item in accouts)
{
var ret = await m_AgentService.Exist(productId, item);
await Task.Delay(50);
if (ret == true)
return true;
}
return false;
}
//检查参加活动账号是否已经存在
public async Task<bool> CheckMonthAccountExist(string account)
{
var flag = this.Exist(m => m.Account == account && m.PackageId == 86);
if (flag)
{
return true;
}
return false;
}
public bool CheckUserAccountExist(int product, List<string> accouts, int userId)
{
return this.Exist(m => accouts.Contains(m.Account) && m.UserId == userId);
}
public async Task<ProductAccountEntity> GetAccountInfo(string accout, int userId)
{
return await this.Query(true).FirstOrDefaultAsync(m => m.Account == accout && m.UserId == userId && m.DeleteTag == 0);
}
public async Task<List<ProductAccountEntity>> GetAccounts(string accouts,int userId=0)
{
var alist = accouts.Split(",");
return await this.Query(m =>(userId==0||m.UserId== userId)&& alist.Contains(m.Account)&&m.DeleteTag==0).ToListAsync();
}
public async Task<ProductAccountEntity> GetAccountInfo(string accout)
{
return await this.Query(true).FirstOrDefaultAsync(m => m.Account == accout);
}
public async Task<ProductAccountEntity> GetAccountInfo(int packageId,string accout)
{
return await this.Query(true).FirstOrDefaultAsync(m =>m.PackageId== packageId&& m.Account == accout);
}
public async Task<ProductAccountEntity> GetProductAccountInfo(int productId, string accout)
{
return await this.Query(true).FirstOrDefaultAsync(m => m.ProductId == productId && m.Account == accout && m.DeleteTag == 0);
}
/// <summary>
/// day 0已过期1天
/// </summary>
/// <param name="day"></param>
/// <returns></returns>
public async Task<List<ProductAccountEntity>> GetExpireingAccounts_bak(int day)
{
Expression<Func<ProductAccountEntity, bool>> expr = m => 1 == 1;
if (day == 0)
{
expr = expr.And(m => m.EndTime.Value < DateTime.Now);
}
else
{
var startTime = DateTime.Now.Begin().AddDays(day);
var EndTime = DateTime.Now.End().AddDays(day);
expr = expr.And(m => m.EndTime >= startTime && m.EndTime <= EndTime);
}
return await this.Query(expr,true).ToListAsync();
}
public async Task<List<ProductAccountEntity>> GetExpireingAccounts(int day)
{
var sql = $"select * from product_account where DATEDIFF(EndTime,now())={day}";
return this.m_DbContext.SqlQuery<ProductAccountEntity>(sql);
}
//主要是用来定时执行的
public async Task<List<ProductAccountEntity>> GetExpireingAccountsTime(int day)
{
var sql = $"select * from product_account WHERE DATEDIFF(EndTime,now())={day} AND `PackageName` NOT LIKE '天卡' AND `PackageName` NOT LIKE '测试卡' GROUP BY UserId";
// var sql = $"select * from product_account where DATEDIFF(EndTime,now())={day} AND PackageName!='测试卡' AND PackageName!='天卡' GROUP BY UserId";
return this.m_DbContext.SqlQuery<ProductAccountEntity>(sql);
}
public async Task<ApiResult> UpdateAccountPwd(UpdateAccountPwdRequest request)
{
var entity = await this.GetById(request.Id);
if (entity == null)
{
return new ApiResult(ResultCode.C_INVALID_ERROR, "账号不存在");
}
if (request.Pwd.NotHas())
{
return new ApiResult(ResultCode.C_INVALID_ERROR, "密码不能为空");
}
var agentRet = await m_AgentService.UpdateAccountPwd(entity.ProductId.Value, entity.Account, request.Pwd);
if (!agentRet)
{
return new ApiResult(ResultCode.C_INVALID_ERROR, "远程更新失败");
}
entity.Pwd = request.Pwd;
await this.Update(entity);
return new ApiResult(1);
}
public async Task<ApiResult> ApiUpdateAccountPwd(UpdateAccountPwdRequest request,int userid)
{
var entity = await this.Query(m => m.Account == request.Account && m.Pwd == request.Pwd && m.DeleteTag == 0 && m.UserId == userid).FirstOrDefaultAsync();
if (entity == null)
{
return new ApiResult(ResultCode.C_INVALID_ERROR, "账号不存在");
}
if (request.Pwd.NotHas()&&request.RePwd.NotHas())
{
return new ApiResult(ResultCode.C_INVALID_ERROR, "密码不能为空");
}
var agentRet = await m_AgentService.UpdateAccountPwd(entity.ProductId.Value, entity.Account, request.RePwd);
if (!agentRet)
{
return new ApiResult(ResultCode.C_INVALID_ERROR, "远程更新失败");
}
entity.Pwd = request.RePwd;
await this.Update(entity);
return new ApiResult(1);
}
public async Task<List<ProductAccountEntity>> GetUserTestAccount(int userId)
{
return await this.Query(m => m.UserId == userId && m.AccountType == (int)AccountType.Test).ToListAsync();
}
public async Task<int> GetRestTestCount(int userId)
{
var userInfo = await m_UserService.GetById(userId);
var restTimes = Convert.ToInt32(m_Configuration["TestCountLimit"]);
if (userInfo.TestCountLimit > 0) restTimes = userInfo.TestCountLimit.Value;
restTimes = restTimes - userInfo.UseTestCount.Value;
restTimes = restTimes < 0 ? 0 : restTimes;
return restTimes;
}
//获取是否实名认证
public async Task<int> GetUserStatus(int userId)
{
var userInfo = await m_UserService.GetById(userId);
var flag = userInfo.is_verify;
return flag;
}
}
}
using HHncore.Pass.Vpn.Request.Product;
using Hncore.Infrastructure.Common;
using Hncore.Infrastructure.Extension;
using Hncore.Infrastructure.Service;
using Hncore.Infrastructure.WebApi;
using Hncore.Pass.Vpn.Domain;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Hncore.Infrastructure.EntitiesExtension;
using Hncore.Infrastructure.EF;
namespace Hncore.Pass.Vpn.Service
{
public partial class ProductAccountService : ServiceBase<ProductAccountEntity>, IFindService
{
CourseContext m_DbContext;
private IConfiguration m_Configuration;
public AgentService m_AgentService;
private UserService m_UserService;
public ProductAccountService(CourseContext dbContext
, AgentService _AgentService
, UserService _UserService
, IConfiguration _Configuration
, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
{
m_DbContext = dbContext;
m_AgentService = _AgentService;
m_Configuration = _Configuration;
m_UserService = _UserService;
}
public async Task<bool> CheckAccountExist(int productId, List<string> accouts)
{
var flag = this.Exist(m => accouts.Contains(m.Account) && m.DeleteTag == 0);
if (flag)
{
return true;
}
foreach (var item in accouts)
{
var ret = await m_AgentService.Exist(productId, item);
await Task.Delay(50);
if (ret == true)
return true;
}
return false;
}
//检查参加活动账号是否已经存在
public async Task<bool> CheckMonthAccountExist(string account)
{
var flag = this.Exist(m => m.Account == account && m.PackageId == 86);
if (flag)
{
return true;
}
return false;
}
public bool CheckUserAccountExist(int product, List<string> accouts, int userId)
{
return this.Exist(m => accouts.Contains(m.Account) && m.UserId == userId);
}
public async Task<ProductAccountEntity> GetAccountInfo(string accout, int userId)
{
return await this.Query(true).FirstOrDefaultAsync(m => m.Account == accout && m.UserId == userId && m.DeleteTag == 0);
}
public async Task<List<ProductAccountEntity>> GetAccounts(string accouts,int userId=0)
{
var alist = accouts.Split(",");
return await this.Query(m =>(userId==0||m.UserId== userId)&& alist.Contains(m.Account)&&m.DeleteTag==0).ToListAsync();
}
public async Task<ProductAccountEntity> GetAccountInfo(string accout)
{
return await this.Query(true).FirstOrDefaultAsync(m => m.Account == accout);
}
public async Task<ProductAccountEntity> GetAccountInfo(int packageId,string accout)
{
return await this.Query(true).FirstOrDefaultAsync(m =>m.PackageId== packageId&& m.Account == accout);
}
public async Task<ProductAccountEntity> GetProductAccountInfo(int productId, string accout)
{
return await this.Query(true).FirstOrDefaultAsync(m => m.ProductId == productId && m.Account == accout && m.DeleteTag == 0);
}
/// <summary>
/// day 0已过期1天
/// </summary>
/// <param name="day"></param>
/// <returns></returns>
public async Task<List<ProductAccountEntity>> GetExpireingAccounts_bak(int day)
{
Expression<Func<ProductAccountEntity, bool>> expr = m => 1 == 1;
if (day == 0)
{
expr = expr.And(m => m.EndTime.Value < DateTime.Now);
}
else
{
var startTime = DateTime.Now.Begin().AddDays(day);
var EndTime = DateTime.Now.End().AddDays(day);
expr = expr.And(m => m.EndTime >= startTime && m.EndTime <= EndTime);
}
return await this.Query(expr,true).ToListAsync();
}
public async Task<List<ProductAccountEntity>> GetExpireingAccounts(int day)
{
var sql = $"select * from product_account where DATEDIFF(EndTime,now())={day}";
return this.m_DbContext.SqlQuery<ProductAccountEntity>(sql);
}
//主要是用来定时执行的
public async Task<List<ProductAccountEntity>> GetExpireingAccountsTime(int day)
{
var sql = $"select * from product_account WHERE DATEDIFF(EndTime,now())={day} AND `PackageName` NOT LIKE '天卡' AND `PackageName` NOT LIKE '测试卡' GROUP BY UserId";
// var sql = $"select * from product_account where DATEDIFF(EndTime,now())={day} AND PackageName!='测试卡' AND PackageName!='天卡' GROUP BY UserId";
return this.m_DbContext.SqlQuery<ProductAccountEntity>(sql);
}
public async Task<ApiResult> UpdateAccountPwd(UpdateAccountPwdRequest request)
{
var entity = await this.GetById(request.Id);
if (entity == null)
{
return new ApiResult(ResultCode.C_INVALID_ERROR, "账号不存在");
}
if (request.Pwd.NotHas())
{
return new ApiResult(ResultCode.C_INVALID_ERROR, "密码不能为空");
}
var agentRet = await m_AgentService.UpdateAccountPwd(entity.ProductId.Value, entity.Account, request.Pwd);
if (!agentRet)
{
return new ApiResult(ResultCode.C_INVALID_ERROR, "远程更新失败");
}
entity.Pwd = request.Pwd;
await this.Update(entity);
return new ApiResult(1);
}
public async Task<ApiResult> ApiUpdateAccountPwd(UpdateAccountPwdRequest request,int userid)
{
var entity = await this.Query(m => m.Account == request.Account && m.Pwd == request.Pwd && m.DeleteTag == 0 && m.UserId == userid).FirstOrDefaultAsync();
if (entity == null)
{
return new ApiResult(ResultCode.C_INVALID_ERROR, "账号不存在");
}
if (request.Pwd.NotHas()&&request.RePwd.NotHas())
{
return new ApiResult(ResultCode.C_INVALID_ERROR, "密码不能为空");
}
var agentRet = await m_AgentService.UpdateAccountPwd(entity.ProductId.Value, entity.Account, request.RePwd);
if (!agentRet)
{
return new ApiResult(ResultCode.C_INVALID_ERROR, "远程更新失败");
}
entity.Pwd = request.RePwd;
await this.Update(entity);
return new ApiResult(1);
}
public async Task<List<ProductAccountEntity>> GetUserTestAccount(int userId)
{
return await this.Query(m => m.UserId == userId && m.AccountType == (int)AccountType.Test).ToListAsync();
}
public async Task<int> GetRestTestCount(int userId)
{
var userInfo = await m_UserService.GetById(userId);
var restTimes = Convert.ToInt32(m_Configuration["TestCountLimit"]);
if (userInfo.TestCountLimit > 0) restTimes = userInfo.TestCountLimit.Value;
restTimes = restTimes - userInfo.UseTestCount.Value;
restTimes = restTimes < 0 ? 0 : restTimes;
return restTimes;
}
//获取是否实名认证
public async Task<int> GetUserStatus(int userId)
{
var userInfo = await m_UserService.GetById(userId);
var flag = userInfo.is_verify;
return flag;
}
}
}

View File

@@ -1,63 +1,63 @@
using Hncore.Infrastructure.Service;
using Hncore.Infrastructure.WebApi;
using Hncore.Pass.Vpn.Domain;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Hncore.Pass.Vpn.Service
{
public partial class ProductOrderItemService : ServiceBase<ProductOrderItemEntity>, IFindService
{
CourseContext m_DbContext;
public ProductOrderItemService(CourseContext dbContext
, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
{
m_DbContext = dbContext;
}
public async Task<List<ProductOrderItemEntity>> CreateOrderItems(ProductOrderEntity orderEntity,string pwd)
{
List<ProductOrderItemEntity> items = new List<ProductOrderItemEntity>();
var accounts = orderEntity.Accounts.Split(',').ToList();
accounts.ForEach(m =>
{
var item = new ProductOrderItemEntity()
{
ConnectCount = orderEntity.ConnectCount,
DayPrice = orderEntity.DayPrice.Value,
DayCount=orderEntity.DayCount,
OrderId = orderEntity.Id,
OrderNo = orderEntity.OrderNo,
OrderState = orderEntity.OrderState,
OrderType = orderEntity.OrderType,
PackageId = orderEntity.PackageId,
PackageName = orderEntity.PackageName,
PayState = orderEntity.PayState,
PayType = orderEntity.PayType,
Account = m,
ProductId = orderEntity.ProductId,
ProductName = orderEntity.ProductName,
TenantId = orderEntity.TenantId,
UserId = orderEntity.UserId,
UserName = orderEntity.UserName,
AccountPwd = pwd
};
items.Add(item);
});
await this.Adds(items);
return items;
}
public async Task<ProductOrderItemEntity> GetLastByAccount(string account)
{
var orderItem = await this.Query(m => m.Account == account && m.OrderState == OrderStatus.Complete)
.OrderByDescending(m => m.Id)
.FirstOrDefaultAsync();
return orderItem;
}
}
}
using Hncore.Infrastructure.Service;
using Hncore.Infrastructure.WebApi;
using Hncore.Pass.Vpn.Domain;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Hncore.Pass.Vpn.Service
{
public partial class ProductOrderItemService : ServiceBase<ProductOrderItemEntity>, IFindService
{
CourseContext m_DbContext;
public ProductOrderItemService(CourseContext dbContext
, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
{
m_DbContext = dbContext;
}
public async Task<List<ProductOrderItemEntity>> CreateOrderItems(ProductOrderEntity orderEntity,string pwd)
{
List<ProductOrderItemEntity> items = new List<ProductOrderItemEntity>();
var accounts = orderEntity.Accounts.Split(',').ToList();
accounts.ForEach(m =>
{
var item = new ProductOrderItemEntity()
{
ConnectCount = orderEntity.ConnectCount,
DayPrice = orderEntity.DayPrice.Value,
DayCount=orderEntity.DayCount,
OrderId = orderEntity.Id,
OrderNo = orderEntity.OrderNo,
OrderState = orderEntity.OrderState,
OrderType = orderEntity.OrderType,
PackageId = orderEntity.PackageId,
PackageName = orderEntity.PackageName,
PayState = orderEntity.PayState,
PayType = orderEntity.PayType,
Account = m,
ProductId = orderEntity.ProductId,
ProductName = orderEntity.ProductName,
TenantId = orderEntity.TenantId,
UserId = orderEntity.UserId,
UserName = orderEntity.UserName,
AccountPwd = pwd
};
items.Add(item);
});
await this.Adds(items);
return items;
}
public async Task<ProductOrderItemEntity> GetLastByAccount(string account)
{
var orderItem = await this.Query(m => m.Account == account && m.OrderState == OrderStatus.Complete)
.OrderByDescending(m => m.Id)
.FirstOrDefaultAsync();
return orderItem;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,34 +1,34 @@
using Hncore.Infrastructure.Service;
using Hncore.Pass.Vpn.Domain;
using Hncore.Pass.Vpn.Model;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Hncore.Pass.Vpn.Service
{
public partial class ProductPackageService : ServiceBase<ProductPackageEntity>, IFindService
{
CourseContext m_DbContext;
ProductPackageUnitService m_ProductPackageUnitService;
public ProductPackageService(CourseContext dbContext
, ProductPackageUnitService _ProductPackageUnitService
, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
{
m_DbContext = dbContext;
this.m_ProductPackageUnitService = _ProductPackageUnitService;
}
public async Task<List<PackageUnitItemModel>> GetBasePackages(int packageId)
{
var packageUnits = m_ProductPackageUnitService.Query(m => m.PackageId == packageId);
var query = from packageUnit in packageUnits
join package in this.Query(true) on packageUnit.BasePackageId equals package.Id
select new PackageUnitItemModel { Count = packageUnit.Count, Package = package };
return await query.ToListAsync();
}
}
}
using Hncore.Infrastructure.Service;
using Hncore.Pass.Vpn.Domain;
using Hncore.Pass.Vpn.Model;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Hncore.Pass.Vpn.Service
{
public partial class ProductPackageService : ServiceBase<ProductPackageEntity>, IFindService
{
CourseContext m_DbContext;
ProductPackageUnitService m_ProductPackageUnitService;
public ProductPackageService(CourseContext dbContext
, ProductPackageUnitService _ProductPackageUnitService
, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
{
m_DbContext = dbContext;
this.m_ProductPackageUnitService = _ProductPackageUnitService;
}
public async Task<List<PackageUnitItemModel>> GetBasePackages(int packageId)
{
var packageUnits = m_ProductPackageUnitService.Query(m => m.PackageId == packageId);
var query = from packageUnit in packageUnits
join package in this.Query(true) on packageUnit.BasePackageId equals package.Id
select new PackageUnitItemModel { Count = packageUnit.Count, Package = package };
return await query.ToListAsync();
}
}
}

View File

@@ -1,15 +1,15 @@
using Hncore.Infrastructure.Service;
using Hncore.Pass.Vpn.Domain;
using Microsoft.AspNetCore.Http;
namespace Hncore.Pass.Vpn.Service
{
public partial class ProductPackageUnitService : ServiceBase<ProductPackageUnitEntity>, IFindService
{
CourseContext m_DbContext;
public ProductPackageUnitService(CourseContext dbContext, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
{
m_DbContext = dbContext;
}
}
}
using Hncore.Infrastructure.Service;
using Hncore.Pass.Vpn.Domain;
using Microsoft.AspNetCore.Http;
namespace Hncore.Pass.Vpn.Service
{
public partial class ProductPackageUnitService : ServiceBase<ProductPackageUnitEntity>, IFindService
{
CourseContext m_DbContext;
public ProductPackageUnitService(CourseContext dbContext, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
{
m_DbContext = dbContext;
}
}
}

View File

@@ -1,54 +1,54 @@
using Hncore.Infrastructure.Service;
using Hncore.Pass.Vpn.Domain;
using Hncore.Pass.Vpn.Response.Product;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Threading.Tasks;
using Hncore.Infrastructure.Extension;
using System.Linq;
namespace Hncore.Pass.Vpn.Service
{
public partial class ProductPriceDiscountService : ServiceBase<ProductPriceDiscountEntity>, IFindService
{
CourseContext m_DbContext;
ProductService m_ProductService;
ProductPackageService m_ProductPackageService;
public ProductPriceDiscountService(CourseContext dbContext
, ProductService _ProductService
, ProductPackageService _ProductPackageService
, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
{
m_DbContext = dbContext;
m_ProductService = _ProductService;
m_ProductPackageService = _ProductPackageService;
}
public async Task<List<ProductWithPriceDiscountResponse>> GetPriceDiscount(int schemeId)
{
var products = await m_ProductService.Query(true).OrderBy(m=>m.Sort).ToListAsync();
var packages = m_ProductPackageService.Query(true);
var priceDiscount = this.Query(m => m.SchemeId == schemeId);
var ret = from pakcage in packages
join uDiscount in priceDiscount on pakcage.Id equals uDiscount.PackageId into temp
from uDiscount in temp.DefaultIfEmpty()
select new PackagePriceDiscount()
{
Package = pakcage,
PriceDiscount = uDiscount ?? new ProductPriceDiscountEntity()
};
var packgesPrice = await ret.ToListAsync();
List<ProductWithPriceDiscountResponse> respList = new List<ProductWithPriceDiscountResponse>();
products.ForEach(p =>
{
var resp = new ProductWithPriceDiscountResponse();
resp.Product = p.MapTo<ProductResponse>();
resp.PackageDiscounts = packgesPrice.Where(m => m.Package.ProductId == p.Id).ToList();
respList.Add(resp);
});
return respList;
}
}
}
using Hncore.Infrastructure.Service;
using Hncore.Pass.Vpn.Domain;
using Hncore.Pass.Vpn.Response.Product;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Threading.Tasks;
using Hncore.Infrastructure.Extension;
using System.Linq;
namespace Hncore.Pass.Vpn.Service
{
public partial class ProductPriceDiscountService : ServiceBase<ProductPriceDiscountEntity>, IFindService
{
CourseContext m_DbContext;
ProductService m_ProductService;
ProductPackageService m_ProductPackageService;
public ProductPriceDiscountService(CourseContext dbContext
, ProductService _ProductService
, ProductPackageService _ProductPackageService
, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
{
m_DbContext = dbContext;
m_ProductService = _ProductService;
m_ProductPackageService = _ProductPackageService;
}
public async Task<List<ProductWithPriceDiscountResponse>> GetPriceDiscount(int schemeId)
{
var products = await m_ProductService.Query(true).OrderBy(m=>m.Sort).ToListAsync();
var packages = m_ProductPackageService.Query(true);
var priceDiscount = this.Query(m => m.SchemeId == schemeId);
var ret = from pakcage in packages
join uDiscount in priceDiscount on pakcage.Id equals uDiscount.PackageId into temp
from uDiscount in temp.DefaultIfEmpty()
select new PackagePriceDiscount()
{
Package = pakcage,
PriceDiscount = uDiscount ?? new ProductPriceDiscountEntity()
};
var packgesPrice = await ret.ToListAsync();
List<ProductWithPriceDiscountResponse> respList = new List<ProductWithPriceDiscountResponse>();
products.ForEach(p =>
{
var resp = new ProductWithPriceDiscountResponse();
resp.Product = p.MapTo<ProductResponse>();
resp.PackageDiscounts = packgesPrice.Where(m => m.Package.ProductId == p.Id).ToList();
respList.Add(resp);
});
return respList;
}
}
}

View File

@@ -1,15 +1,15 @@
using Hncore.Infrastructure.Service;
using Hncore.Pass.Vpn.Domain;
using Microsoft.AspNetCore.Http;
namespace Hncore.Pass.Vpn.Service
{
public partial class ProductPriceSchemeService : ServiceBase<ProductPriceSchemeEntity>, IFindService
{
CourseContext m_DbContext;
public ProductPriceSchemeService(CourseContext dbContext, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
{
m_DbContext = dbContext;
}
}
}
using Hncore.Infrastructure.Service;
using Hncore.Pass.Vpn.Domain;
using Microsoft.AspNetCore.Http;
namespace Hncore.Pass.Vpn.Service
{
public partial class ProductPriceSchemeService : ServiceBase<ProductPriceSchemeEntity>, IFindService
{
CourseContext m_DbContext;
public ProductPriceSchemeService(CourseContext dbContext, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
{
m_DbContext = dbContext;
}
}
}

View File

@@ -1,15 +1,15 @@
using Hncore.Infrastructure.Service;
using Hncore.Pass.Vpn.Domain;
using Microsoft.AspNetCore.Http;
namespace Hncore.Pass.Vpn.Service
{
public partial class ProductRouteService : ServiceBase<ProductRouteEntity>, IFindService
{
CourseContext m_DbContext;
public ProductRouteService(CourseContext dbContext, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
{
m_DbContext = dbContext;
}
}
}
using Hncore.Infrastructure.Service;
using Hncore.Pass.Vpn.Domain;
using Microsoft.AspNetCore.Http;
namespace Hncore.Pass.Vpn.Service
{
public partial class ProductRouteService : ServiceBase<ProductRouteEntity>, IFindService
{
CourseContext m_DbContext;
public ProductRouteService(CourseContext dbContext, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
{
m_DbContext = dbContext;
}
}
}

View File

@@ -1,78 +1,78 @@
using Hncore.Infrastructure.Extension;
using Hncore.Infrastructure.Service;
using Hncore.Pass.Vpn.Domain;
using Hncore.Pass.Vpn.Response.Product;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Hncore.Pass.Vpn.Service
{
public partial class ProductService : ServiceBase<ProductEntity>, IFindService
{
private static readonly string m_ProductCacheKey = "Product:{0}";
CourseContext m_DbContext;
ProductPackageService m_ProductPackageService;
public ProductService(CourseContext dbContext, ProductPackageService _ProductPackageService, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
{
m_DbContext = dbContext;
m_ProductPackageService = _ProductPackageService;
}
public async override Task<ProductEntity> GetById(object id)
{
return await base.GetById(id);
string key = string.Format(m_ProductCacheKey, id);
var cacheData = await RedisHelper.GetAsync<ProductEntity>(key);
if (cacheData == null)
{
cacheData = await base.GetById(id);
if (cacheData != null)
await RedisHelper.SetAsync(key, cacheData, 60 * 30);
}
return cacheData;
}
public async override Task<bool> Update(ProductEntity entity, bool autoSave = true)
{
string key = string.Format(m_ProductCacheKey, entity.Id);
await RedisHelper.SetAsync(key, entity, 60 * 30);
return await base.Update(entity, autoSave);
}
public async Task<List<ProductWithPackageResponse>> ProductWithPackage(int online=1)
{
var products = await this.Query(m => m.Sort != 1000).OrderBy(m=>m.Sort).Where(m=>m.OnLine==online).ToListAsync();
var packages = await m_ProductPackageService.Query(true).ToListAsync();
List<ProductWithPackageResponse> respList = new List<ProductWithPackageResponse>();
products.ForEach(p =>
{
var resp = new ProductWithPackageResponse();
resp.Product = p.MapTo<ProductResponse>();
resp.Packages = packages.Where(m => m.ProductId == p.Id).ToList();
respList.Add(resp);
});
return respList;
}
public async Task<ProductWithPackageResponse> GetOneProductWithPackage(int productId)
{
var product = await this.GetById(productId);
var packages = await m_ProductPackageService.Query(m => m.ProductId == productId).ToListAsync();
List<ProductWithPackageResponse> respList = new List<ProductWithPackageResponse>();
var resp = new ProductWithPackageResponse();
resp.Product = product.MapTo<ProductResponse>();
resp.Packages = packages;
return resp;
}
}
}
using Hncore.Infrastructure.Extension;
using Hncore.Infrastructure.Service;
using Hncore.Pass.Vpn.Domain;
using Hncore.Pass.Vpn.Response.Product;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Hncore.Pass.Vpn.Service
{
public partial class ProductService : ServiceBase<ProductEntity>, IFindService
{
private static readonly string m_ProductCacheKey = "Product:{0}";
CourseContext m_DbContext;
ProductPackageService m_ProductPackageService;
public ProductService(CourseContext dbContext, ProductPackageService _ProductPackageService, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
{
m_DbContext = dbContext;
m_ProductPackageService = _ProductPackageService;
}
public async override Task<ProductEntity> GetById(object id)
{
return await base.GetById(id);
string key = string.Format(m_ProductCacheKey, id);
var cacheData = await RedisHelper.GetAsync<ProductEntity>(key);
if (cacheData == null)
{
cacheData = await base.GetById(id);
if (cacheData != null)
await RedisHelper.SetAsync(key, cacheData, 60 * 30);
}
return cacheData;
}
public async override Task<bool> Update(ProductEntity entity, bool autoSave = true)
{
string key = string.Format(m_ProductCacheKey, entity.Id);
await RedisHelper.SetAsync(key, entity, 60 * 30);
return await base.Update(entity, autoSave);
}
public async Task<List<ProductWithPackageResponse>> ProductWithPackage(int online=1)
{
var products = await this.Query(m => m.Sort != 1000).OrderBy(m=>m.Sort).Where(m=>m.OnLine==online).ToListAsync();
var packages = await m_ProductPackageService.Query(true).ToListAsync();
List<ProductWithPackageResponse> respList = new List<ProductWithPackageResponse>();
products.ForEach(p =>
{
var resp = new ProductWithPackageResponse();
resp.Product = p.MapTo<ProductResponse>();
resp.Packages = packages.Where(m => m.ProductId == p.Id).ToList();
respList.Add(resp);
});
return respList;
}
public async Task<ProductWithPackageResponse> GetOneProductWithPackage(int productId)
{
var product = await this.GetById(productId);
var packages = await m_ProductPackageService.Query(m => m.ProductId == productId).ToListAsync();
List<ProductWithPackageResponse> respList = new List<ProductWithPackageResponse>();
var resp = new ProductWithPackageResponse();
resp.Product = product.MapTo<ProductResponse>();
resp.Packages = packages;
return resp;
}
}
}

View File

@@ -1,68 +1,68 @@
using Hncore.Infrastructure.Extension;
using Hncore.Infrastructure.Service;
using Hncore.Pass.Vpn.Domain;
using Hncore.Pass.Vpn.Response.Product;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Hncore.Pass.Vpn.Service
{
public partial class ProductUserPriceService : ServiceBase<ProductUserPriceEntity>, IFindService
{
CourseContext m_DbContext;
ProductService m_ProductService;
ProductPackageService m_ProductPackageService;
public ProductUserPriceService(ProductPackageService m_ProductPackageService
, ProductService m_ProductService
,CourseContext dbContext, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
{
m_DbContext = dbContext;
this.m_ProductPackageService = m_ProductPackageService;
this.m_ProductService = m_ProductService;
}
public async Task<List<ProductWithPackageUserPriceResponse>> GetPackageUserPrice(int userId)
{
var products = await m_ProductService.Query( m=>m.OnLine == 1).OrderBy(m=>m.Sort).ToListAsync();
var packages = m_ProductPackageService.Query(true);
var userPrice = this.Query(m => m.UserId == userId);
var ret = from pakcage in packages
join uPrice in userPrice on pakcage.Id equals uPrice.PackageId into temp
from uPrice in temp.DefaultIfEmpty()
select new PackageUserPriceResponse()
{
Package = pakcage,
UserPrice = uPrice ?? new ProductUserPriceEntity() { RefundDayPrice= products.FirstOrDefault(m=>m.Id==pakcage.ProductId).RefundDayPrice, UserPrice=pakcage.Price }
};
var packgesPrice = await ret.ToListAsync();
List<ProductWithPackageUserPriceResponse> respList = new List<ProductWithPackageUserPriceResponse>();
products.ForEach(p =>
{
var resp = new ProductWithPackageUserPriceResponse();
resp.Product = p.MapTo<ProductResponse>();
resp.PackageUserPrices = packgesPrice.Where(m => m.Package.ProductId == p.Id).ToList();
respList.Add(resp);
});
return respList;
}
public async Task<List<ProductUserPriceEntity>> GetProductUserPrice(int product,int userId)
{
return this.Query(m => m.ProductId == product && m.UserId == userId && m.Status == 1).ToList();
}
public async Task<List<ProductUserPriceEntity>> GetProductUserPrice(int userId)
{
return this.Query(m => m.UserId == userId && m.Status == 1).ToList();
}
public async Task<ProductUserPriceEntity> GetPackageUserPrice(int packageId, int userId)
{
return this.Query(m => m.PackageId == packageId && m.UserId == userId&& m.Status==1).FirstOrDefault();
}
}
}
using Hncore.Infrastructure.Extension;
using Hncore.Infrastructure.Service;
using Hncore.Pass.Vpn.Domain;
using Hncore.Pass.Vpn.Response.Product;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Hncore.Pass.Vpn.Service
{
public partial class ProductUserPriceService : ServiceBase<ProductUserPriceEntity>, IFindService
{
CourseContext m_DbContext;
ProductService m_ProductService;
ProductPackageService m_ProductPackageService;
public ProductUserPriceService(ProductPackageService m_ProductPackageService
, ProductService m_ProductService
,CourseContext dbContext, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
{
m_DbContext = dbContext;
this.m_ProductPackageService = m_ProductPackageService;
this.m_ProductService = m_ProductService;
}
public async Task<List<ProductWithPackageUserPriceResponse>> GetPackageUserPrice(int userId)
{
var products = await m_ProductService.Query( m=>m.OnLine == 1).OrderBy(m=>m.Sort).ToListAsync();
var packages = m_ProductPackageService.Query(true);
var userPrice = this.Query(m => m.UserId == userId);
var ret = from pakcage in packages
join uPrice in userPrice on pakcage.Id equals uPrice.PackageId into temp
from uPrice in temp.DefaultIfEmpty()
select new PackageUserPriceResponse()
{
Package = pakcage,
UserPrice = uPrice ?? new ProductUserPriceEntity() { RefundDayPrice= products.FirstOrDefault(m=>m.Id==pakcage.ProductId).RefundDayPrice, UserPrice=pakcage.Price }
};
var packgesPrice = await ret.ToListAsync();
List<ProductWithPackageUserPriceResponse> respList = new List<ProductWithPackageUserPriceResponse>();
products.ForEach(p =>
{
var resp = new ProductWithPackageUserPriceResponse();
resp.Product = p.MapTo<ProductResponse>();
resp.PackageUserPrices = packgesPrice.Where(m => m.Package.ProductId == p.Id).ToList();
respList.Add(resp);
});
return respList;
}
public async Task<List<ProductUserPriceEntity>> GetProductUserPrice(int product,int userId)
{
return this.Query(m => m.ProductId == product && m.UserId == userId && m.Status == 1).ToList();
}
public async Task<List<ProductUserPriceEntity>> GetProductUserPrice(int userId)
{
return this.Query(m => m.UserId == userId && m.Status == 1).ToList();
}
public async Task<ProductUserPriceEntity> GetPackageUserPrice(int packageId, int userId)
{
return this.Query(m => m.PackageId == packageId && m.UserId == userId&& m.Status==1).FirstOrDefault();
}
}
}

View File

@@ -1,30 +1,30 @@
using Hncore.Infrastructure.Service;
using Hncore.Infrastructure.WebApi;
using Hncore.Pass.Vpn.Domain;
using Hncore.Pass.Vpn.Request.Product;
using Microsoft.AspNetCore.Http;
using System.Threading.Tasks;
using Hncore.Infrastructure.Extension;
using System;
using Hncore.Infrastructure.Common;
using System.Collections.Generic;
using Hncore.Pass.BaseInfo.Models;
using Microsoft.EntityFrameworkCore;
namespace Hncore.Pass.Vpn.Service
{
public class UserService : ServiceBase<UserEntity>, IFindService
{
CourseContext m_DbContext;
public UserService(CourseContext dbContext
,IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
{
m_DbContext = dbContext;
}
public async Task<List<UserEntity>> GetByIds(List<int> userids)
{
return await this.Query(m => userids.Contains(m.Id)).ToListAsync();
}
}
using Hncore.Infrastructure.Service;
using Hncore.Infrastructure.WebApi;
using Hncore.Pass.Vpn.Domain;
using Hncore.Pass.Vpn.Request.Product;
using Microsoft.AspNetCore.Http;
using System.Threading.Tasks;
using Hncore.Infrastructure.Extension;
using System;
using Hncore.Infrastructure.Common;
using System.Collections.Generic;
using Hncore.Pass.BaseInfo.Models;
using Microsoft.EntityFrameworkCore;
namespace Hncore.Pass.Vpn.Service
{
public class UserService : ServiceBase<UserEntity>, IFindService
{
CourseContext m_DbContext;
public UserService(CourseContext dbContext
,IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
{
m_DbContext = dbContext;
}
public async Task<List<UserEntity>> GetByIds(List<int> userids)
{
return await this.Query(m => userids.Contains(m.Id)).ToListAsync();
}
}
}

View File

@@ -1,49 +1,49 @@
using Hncore.Infrastructure.Service;
using Hncore.Pass.Vpn.Domain;
using Hncore.Wx.Open;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using System.Threading.Tasks;
namespace Hncore.Pass.Vpn.Service
{
public partial class WxAppService : ServiceBase<WxAppEntity>
{
public WxAppService(CourseContext dbContext, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
{
}
public async Task SaveAppInfo(GetAuthorizerInfoResponse info, int tenantId, int storeId)
{
var wxAppInfo = await this.Query(true).FirstOrDefaultAsync(m => m.TenantId == tenantId
&& m.Appid == info.authorization_info.authorizer_appid
&& m.DeleteTag == 0);
var wxAuthInfoNew = new WxAppEntity()
{
TenantId = tenantId,
StoreId = storeId,
Appid = info.authorization_info.authorizer_appid,
HeadImg = info.authorizer_info.head_img,
NickName = info.authorizer_info.nick_name,
PrincipalName = info.authorizer_info.principal_name,
UserName = info.authorizer_info.user_name,
Bussinessinfo = info.authorizer_info.signature,
AuthorizerState = 0,
RefreshToken = info.authorization_info.authorizer_refresh_token,
ExpiresIn = info.authorization_info.expires_in,
};
if (wxAppInfo == null)
{
await this.Add(wxAuthInfoNew);
}
else
{
wxAuthInfoNew.Id = wxAppInfo.Id;
await this.Update(wxAuthInfoNew);
}
}
}
using Hncore.Infrastructure.Service;
using Hncore.Pass.Vpn.Domain;
using Hncore.Wx.Open;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using System.Threading.Tasks;
namespace Hncore.Pass.Vpn.Service
{
public partial class WxAppService : ServiceBase<WxAppEntity>
{
public WxAppService(CourseContext dbContext, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
{
}
public async Task SaveAppInfo(GetAuthorizerInfoResponse info, int tenantId, int storeId)
{
var wxAppInfo = await this.Query(true).FirstOrDefaultAsync(m => m.TenantId == tenantId
&& m.Appid == info.authorization_info.authorizer_appid
&& m.DeleteTag == 0);
var wxAuthInfoNew = new WxAppEntity()
{
TenantId = tenantId,
StoreId = storeId,
Appid = info.authorization_info.authorizer_appid,
HeadImg = info.authorizer_info.head_img,
NickName = info.authorizer_info.nick_name,
PrincipalName = info.authorizer_info.principal_name,
UserName = info.authorizer_info.user_name,
Bussinessinfo = info.authorizer_info.signature,
AuthorizerState = 0,
RefreshToken = info.authorization_info.authorizer_refresh_token,
ExpiresIn = info.authorization_info.expires_in,
};
if (wxAppInfo == null)
{
await this.Add(wxAuthInfoNew);
}
else
{
wxAuthInfoNew.Id = wxAppInfo.Id;
await this.Update(wxAuthInfoNew);
}
}
}
}

View File

@@ -1,34 +1,34 @@
using Hncore.Infrastructure.Service;
using Hncore.Pass.Vpn.Domain;
using Hncore.Wx.Open;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Hncore.Pass.Vpn.Service
{
public partial class WxAppUserService : ServiceBase<WxAppUserEntity>
{
WxAppService m_WxAppService;
public WxAppUserService(WxAppService _WxAppService, CourseContext dbContext, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
{
m_WxAppService = _WxAppService;
}
public async Task<List<WxAppUserEntity>> GetWxUsers(List<int> UserId)
{
return await this.Query(m => UserId.Contains(m.UserId)).ToListAsync();
}
public async Task<WxAppUserEntity> GetWxUser(string appId, int userId)
{
return await this.Query(m => m.Appid == appId && m.UserId == userId).FirstOrDefaultAsync();
}
public async Task<WxAppUserEntity> GetWxUser(string appId, string openId)
{
return await this.Query(m => m.Appid == appId && m.Openid == openId).FirstOrDefaultAsync();
}
}
using Hncore.Infrastructure.Service;
using Hncore.Pass.Vpn.Domain;
using Hncore.Wx.Open;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Hncore.Pass.Vpn.Service
{
public partial class WxAppUserService : ServiceBase<WxAppUserEntity>
{
WxAppService m_WxAppService;
public WxAppUserService(WxAppService _WxAppService, CourseContext dbContext, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
{
m_WxAppService = _WxAppService;
}
public async Task<List<WxAppUserEntity>> GetWxUsers(List<int> UserId)
{
return await this.Query(m => UserId.Contains(m.UserId)).ToListAsync();
}
public async Task<WxAppUserEntity> GetWxUser(string appId, int userId)
{
return await this.Query(m => m.Appid == appId && m.UserId == userId).FirstOrDefaultAsync();
}
public async Task<WxAppUserEntity> GetWxUser(string appId, string openId)
{
return await this.Query(m => m.Appid == appId && m.Openid == openId).FirstOrDefaultAsync();
}
}
}