115 lines
4.1 KiB
C#
115 lines
4.1 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Threading;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using CsharpHttpHelper;
|
|||
|
using Newtonsoft.Json;
|
|||
|
using PCRobot.PCWechat;
|
|||
|
using PCRobot.PCWechat.Enterprise;
|
|||
|
using PCRobot.PCWechat.Routine;
|
|||
|
using PCRobot.Utils;
|
|||
|
|
|||
|
namespace PCRobot
|
|||
|
{
|
|||
|
public class LuDogService
|
|||
|
{
|
|||
|
private IniHelper Config;
|
|||
|
public LuDogService()
|
|||
|
{
|
|||
|
var fileName = HttpExtend.MapFile("机器人信息.ini", "Config");
|
|||
|
Config = new IniHelper(fileName);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public void Handle(WechatUser user)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
Task.Run(() =>
|
|||
|
{
|
|||
|
Thread.Sleep(new Random(Guid.NewGuid().GetHashCode()).Next(500, 6000));
|
|||
|
if (string.IsNullOrWhiteSpace(Config.GetValue("数据", "账号")))
|
|||
|
{
|
|||
|
Config.SetValue("数据", "账号", JsonConvert.SerializeObject(new List<string>()));
|
|||
|
}
|
|||
|
|
|||
|
var json = Config.GetValue("数据", "账号");
|
|||
|
List<string> list;
|
|||
|
try
|
|||
|
{
|
|||
|
list = JsonConvert.DeserializeObject<List<string>>(json);
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
list = new List<string>();
|
|||
|
}
|
|||
|
|
|||
|
if (list.Contains(user.Wxid))
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
var userlist = new List<UserRobotUpLoad.CustomerLinkInput>();
|
|||
|
|
|||
|
var client = WechatClient.GetApi(user);
|
|||
|
if (client is Wechat_Xiaoxie_QY qyHook)
|
|||
|
{
|
|||
|
var firends = qyHook.GetExternalFirends().Result;
|
|||
|
if (firends == null || firends.Count <= 0)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
foreach (var firend in firends)
|
|||
|
{
|
|||
|
userlist.Add(new UserRobotUpLoad.CustomerLinkInput()
|
|||
|
{
|
|||
|
UserName = firend.Value.username,
|
|||
|
HeadUrl = firend.Value.avatar,
|
|||
|
NickName = firend.Value.realname,
|
|||
|
Remark = firend.Value.remark,
|
|||
|
RobotName = user.Wxid,
|
|||
|
RobotType = 2,
|
|||
|
CreateTime = DateTime.Now
|
|||
|
});
|
|||
|
}
|
|||
|
}
|
|||
|
else if (client is Wechat_Xiaoxie hook)
|
|||
|
{
|
|||
|
var firends = hook.GetFriendInfos().Result;
|
|||
|
if (firends == null || firends.Count <= 0)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
foreach (var firend in firends)
|
|||
|
{
|
|||
|
userlist.Add(new UserRobotUpLoad.CustomerLinkInput()
|
|||
|
{
|
|||
|
UserName = firend.Value.wxid,
|
|||
|
HeadUrl = firend.Value.avatar,
|
|||
|
NickName = firend.Value.nickname,
|
|||
|
Remark = firend.Value.remark,
|
|||
|
RobotName = user.Wxid,
|
|||
|
RobotType = 2,
|
|||
|
CreateTime = DateTime.Now
|
|||
|
});
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (userlist.Count > 0)
|
|||
|
{
|
|||
|
var result = UserRobotUpLoad.CustomerLink_UpLoadLink(userlist);
|
|||
|
if (result.Ok)
|
|||
|
{
|
|||
|
list.Add(user.Wxid);
|
|||
|
Config.SetValue("数据", "账号", JsonConvert.SerializeObject(list));
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{ }
|
|||
|
}
|
|||
|
}
|
|||
|
}
|