132 lines
4.1 KiB
C#
132 lines
4.1 KiB
C#
|
using Api.Framework.Model;
|
|||
|
using Api.Framework.Utils;
|
|||
|
using CsharpHttpHelper;
|
|||
|
using System;
|
|||
|
using System.Collections.Concurrent;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using System.Web;
|
|||
|
using Api.Framework.SDK;
|
|||
|
|
|||
|
namespace Api.Framework.Tools
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 云黑命大类
|
|||
|
/// </summary>
|
|||
|
public class CloudBlack
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 黑名单所属平台类型
|
|||
|
/// </summary>
|
|||
|
public enum BlackType : int
|
|||
|
{
|
|||
|
wechat = 0
|
|||
|
}
|
|||
|
public class BlackResult
|
|||
|
{
|
|||
|
public int Code { get; set; }
|
|||
|
public object Data { get; set; }
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 查询用户是否黑名单
|
|||
|
/// </summary>
|
|||
|
/// <param name="member">用户对象</param>
|
|||
|
/// <returns></returns>
|
|||
|
public fl_blackuser QueryBlack(fl_member_info member)
|
|||
|
{
|
|||
|
return QueryBlack(member.username, member.robot_type);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 判断用户是否为黑名单
|
|||
|
/// </summary>
|
|||
|
/// <param name="username">用户账号</param>
|
|||
|
/// <returns></returns>
|
|||
|
public fl_blackuser QueryBlack(string username, ChatType robot_type)
|
|||
|
{
|
|||
|
if (string.IsNullOrWhiteSpace(username))
|
|||
|
return null;
|
|||
|
try
|
|||
|
{
|
|||
|
var session = ApiClient.GetSession();
|
|||
|
var black = session.FindSingle<fl_blackuser>("select * from fl_blackuser where username = @username and usertype = @usertype", new { username = username, usertype = robot_type });
|
|||
|
if (black != null && black.isdel == false && black.iscloud)
|
|||
|
return black;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
LogHelper.GetSingleObj().Debug("检测云黑名单", $"{username} - {robot_type},{ex.Message} - {ex.StackTrace}");
|
|||
|
}
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 删除用户黑名单
|
|||
|
/// </summary>
|
|||
|
/// <param name="member">用户对象</param>
|
|||
|
/// <returns></returns>
|
|||
|
public ServiceResult RemoveBlack(fl_member_info member)
|
|||
|
{
|
|||
|
var res = YZCloudApiHelper.RemoveBlacklist(new List<RemoveBlacklistInput>()
|
|||
|
{
|
|||
|
new RemoveBlacklistInput()
|
|||
|
{
|
|||
|
Username = member.username,
|
|||
|
Type = GetUserType(member.robot_type),
|
|||
|
UserToken = HttpUtility.UrlEncode(Grant.Framework.GrantClient.Get().accounts.username, Encoding.UTF8)
|
|||
|
}
|
|||
|
});
|
|||
|
return res;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 插入黑名单
|
|||
|
/// </summary>
|
|||
|
/// <param name="member">用户对象</param>
|
|||
|
/// <param name="remark">备注</param>
|
|||
|
/// <returns></returns>
|
|||
|
public ServiceResult InsertBlack(fl_member_info member, string remark)
|
|||
|
{
|
|||
|
var res = YZCloudApiHelper.AddUserBlacklist(new List<SetBlacklistInput>()
|
|||
|
{
|
|||
|
new SetBlacklistInput()
|
|||
|
{
|
|||
|
AddDateTime = DateTime.Now,
|
|||
|
Avatar = member.headurl,
|
|||
|
Remark = remark,
|
|||
|
Type = GetUserType(member.robot_type),
|
|||
|
UserToken = HttpUtility.UrlEncode(Grant.Framework.GrantClient.Get().accounts.username, Encoding.UTF8),
|
|||
|
UserName = member.username,
|
|||
|
UserNick =member.usernick
|
|||
|
}
|
|||
|
});
|
|||
|
if (!res.Ok)
|
|||
|
{
|
|||
|
//throw new Exception(res.Message);
|
|||
|
}
|
|||
|
return res;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
private int GetUserType(ChatType userType)
|
|||
|
{
|
|||
|
switch (userType)
|
|||
|
{
|
|||
|
case ChatType.微信:
|
|||
|
return 0;
|
|||
|
case ChatType.企业微信:
|
|||
|
return 2;
|
|||
|
case ChatType.QQ:
|
|||
|
return 1;
|
|||
|
default:
|
|||
|
return 0;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|