购买api
This commit is contained in:
@@ -321,6 +321,91 @@ namespace Hncore.Pass.Vpn.Controllers
|
||||
}
|
||||
|
||||
|
||||
//api接口,供新开测试使用
|
||||
[HttpPost,AllowAnonymous]
|
||||
public async Task<ApiResult> ApiCreateTestAccount([FromBody]CreateTestAccountRequest request)
|
||||
{
|
||||
if (request.Account.NotHas() || request.Pwd.NotHas())
|
||||
{
|
||||
return Error("账户和密码不能为空");
|
||||
}
|
||||
if (request.Account == request.Pwd)
|
||||
{
|
||||
return Error("账户和密码不能一致");
|
||||
}
|
||||
if (request.apikey.NotHas())
|
||||
{
|
||||
return Error("非法请求");
|
||||
}
|
||||
//通过apikey获取用户信息
|
||||
var userEntity = m_UserService.Query(m => m.apikey == request.apikey).FirstOrDefault();
|
||||
if (userEntity == null)
|
||||
{
|
||||
return Error("apikey不正确");
|
||||
}
|
||||
var userId = userEntity.Id;
|
||||
var packageEntity = await m_PackageService.GetById(request.PackageId);
|
||||
if (packageEntity==null|| packageEntity.Status==0)
|
||||
{
|
||||
return Error("套餐不存在");
|
||||
}
|
||||
if (packageEntity.IsTest == 0)
|
||||
{
|
||||
return Error("非测试套餐");
|
||||
}
|
||||
|
||||
var flag = await m_AccountService.CheckAccountExist(packageEntity.ProductId, new List<string> { request.Account });
|
||||
if (flag)
|
||||
{
|
||||
return Error("账号已经存在");
|
||||
}
|
||||
var restTimes = await m_AccountService.GetRestTestCount(userId);
|
||||
|
||||
var is_verify = await m_AccountService.GetUserStatus(userId);
|
||||
|
||||
if (restTimes <= 0)
|
||||
{
|
||||
return Error("没有测试次数了");
|
||||
}
|
||||
|
||||
if (is_verify == 0)
|
||||
{
|
||||
return Error("请点击前往实名认证");
|
||||
}
|
||||
|
||||
|
||||
var ret= await m_agentService.NewAccount(0, request.PackageId, request.Account, request.Pwd, accountType: 0);
|
||||
|
||||
if (ret.Code == ResultCode.C_SUCCESS)
|
||||
{
|
||||
var ProductEntity = await m_ProductService.GetById(packageEntity.ProductId);
|
||||
var accountEntity = new ProductAccountEntity()
|
||||
{
|
||||
Account = request.Account,
|
||||
AccountType = (int)AccountType.Test,
|
||||
ConnectCount = 1,
|
||||
StartTime = DateTime.Now,
|
||||
EndTime = DateTime.Now.AddHours(packageEntity.DayCount),
|
||||
PackageId = packageEntity.Id,
|
||||
PackageName = packageEntity.Name,
|
||||
ProductId = packageEntity.ProductId,
|
||||
ProductName = ProductEntity.Name,
|
||||
Pwd = request.Pwd,
|
||||
ChargeStatus = AccountChargeStatus.Normal,
|
||||
UserId = userEntity.Id,
|
||||
UserCode = userEntity.LoginCode,
|
||||
};
|
||||
await m_AccountService.Add(accountEntity);
|
||||
|
||||
//前边已经通过apikey获取到数据--故注释
|
||||
// var userEntity = await m_UserService.GetById(userId);
|
||||
userEntity.UseTestCount++;
|
||||
await m_UserService.Update(userEntity);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 是否在线
|
||||
/// </summary>
|
||||
|
||||
@@ -82,6 +82,7 @@ namespace Hncore.Pass.Vpn.Domain
|
||||
public string ManagerName { get; set; }
|
||||
public int is_verify { get; set; }
|
||||
public int agent_id {get; set;}
|
||||
public string apikey {get; set;}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ namespace Hncore.Pass.Vpn.Request.Product
|
||||
{
|
||||
public class CreateOrderRequest
|
||||
{
|
||||
public string apikey { get; set; }
|
||||
public OrderType OrderType { get; set; }
|
||||
|
||||
public int PackageId { get; set; }
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace Hncore.Pass.Vpn.Request.Product
|
||||
{
|
||||
public class CreateTestAccountRequest
|
||||
{
|
||||
public string apikey { get; set; }
|
||||
public int ProductId { get; set; }
|
||||
|
||||
public int PackageId { get; set; }
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
{
|
||||
public class UpdateAccountPwdRequest
|
||||
{
|
||||
public string apikey { get; set; }
|
||||
public int Id { get; set; }
|
||||
public string Account { get; set; }
|
||||
public string Pwd { get; set; }
|
||||
public string RePwd { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,6 +149,27 @@ namespace Hncore.Pass.Vpn.Service
|
||||
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())
|
||||
{
|
||||
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.Pwd;
|
||||
await this.Update(entity);
|
||||
return new ApiResult(1);
|
||||
}
|
||||
|
||||
|
||||
public async Task<List<ProductAccountEntity>> GetUserTestAccount(int userId)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user