2022-09-20 03:10:29 +00:00
|
|
|
|
using Api.Framework;
|
|
|
|
|
using Api.Framework.SDK;
|
|
|
|
|
using ProductClient.Properties;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
2022-12-05 06:52:19 +00:00
|
|
|
|
using System.Text.RegularExpressions;
|
2022-09-20 03:10:29 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2022-12-05 06:52:19 +00:00
|
|
|
|
using Api.Framework.Cps;
|
|
|
|
|
using Api.Framework.Enums;
|
|
|
|
|
using Api.Framework.Events;
|
|
|
|
|
using Api.Framework.Utils;
|
|
|
|
|
using Chat.Framework.WXSdk;
|
|
|
|
|
using CsharpHttpHelper;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
using ProductClient.Entitys;
|
|
|
|
|
using Chat.Framework.WXSdk.Implement;
|
|
|
|
|
using Api.Framework.Tools;
|
2023-04-06 01:07:55 +00:00
|
|
|
|
using UtilHelper;
|
2022-09-20 03:10:29 +00:00
|
|
|
|
|
|
|
|
|
namespace ProductClient
|
|
|
|
|
{
|
|
|
|
|
public class Class1 : Plugin
|
|
|
|
|
{
|
|
|
|
|
public Class1()
|
|
|
|
|
{
|
|
|
|
|
this.Name = "爆单-代运营";
|
|
|
|
|
this.Note = "专业的运营团队、代运营朋友圈、直播群!";
|
|
|
|
|
this.Logo = Resources.爆单;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 自定义变量
|
|
|
|
|
public static Config Config;
|
|
|
|
|
private MainForm mainForm = null;
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
public override void Start()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var session = ApiClient.GetSession();
|
|
|
|
|
#region 判断表是否存在,不存在创建表
|
|
|
|
|
//if (!session.TableExist<>())
|
|
|
|
|
//{
|
|
|
|
|
// session.CreateTable<>();
|
|
|
|
|
// session.AddIndex<>("");
|
|
|
|
|
//}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
//创建配置文件
|
|
|
|
|
Config = this.ReadConfig<Config>();
|
|
|
|
|
|
2022-12-05 06:52:19 +00:00
|
|
|
|
EventClient.DyyNoticeEvent += EventClient_DyyNoticeEvent;
|
2023-01-29 10:07:38 +00:00
|
|
|
|
|
2023-02-02 07:37:56 +00:00
|
|
|
|
var thread = TimerTask.NewTimer<MonitorThread>(60) as MonitorThread;
|
|
|
|
|
|
2022-12-10 02:09:10 +00:00
|
|
|
|
//EventClient_DyyNoticeEvent(null, new DyyNoticeEvent()
|
|
|
|
|
//{
|
2023-01-29 10:07:38 +00:00
|
|
|
|
// //Data = "{\"Id\":\"122522636742819840\",\"TaskId\":\"122522636742819840\",\"IsGoods\":true}"
|
|
|
|
|
// Data = "{\"TaskId\":\"142515582485397504\",\"CollectionSourceId\":\"129505086429724672\",\"IsGoods\":true}"
|
2022-12-10 02:09:10 +00:00
|
|
|
|
//});
|
2023-02-02 07:37:56 +00:00
|
|
|
|
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
thread.Sleep(1000 * 30);
|
|
|
|
|
MonitorThread.GetDyyCircleGoodsLastTask();
|
|
|
|
|
});
|
|
|
|
|
|
2022-09-20 03:10:29 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
this.OnLog(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void ShowForm()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (mainForm == null || mainForm.IsDisposed)
|
|
|
|
|
{
|
|
|
|
|
mainForm = new MainForm();
|
|
|
|
|
mainForm.Show();
|
|
|
|
|
}
|
|
|
|
|
mainForm.Activate();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
this.OnLog("执行时被" + ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Stop()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2022-12-07 04:01:44 +00:00
|
|
|
|
EventClient.DyyNoticeEvent -= EventClient_DyyNoticeEvent;
|
|
|
|
|
//TimerTask.Close<MonitorThread>();
|
2022-09-20 03:10:29 +00:00
|
|
|
|
if (mainForm != null)
|
|
|
|
|
{
|
|
|
|
|
mainForm.CloseForm();
|
|
|
|
|
mainForm = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
this.OnLog(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-07 04:01:44 +00:00
|
|
|
|
private static Dictionary<string, string> CacheDic = new Dictionary<string, string>();
|
|
|
|
|
|
2023-01-27 09:53:21 +00:00
|
|
|
|
private void EventClient_DyyNoticeEvent(object sender, DyyNoticeEvent e)
|
2022-12-05 06:52:19 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2022-12-07 04:01:44 +00:00
|
|
|
|
EventClient.OnEvent(this, $"代运营新动态:{e.Data}");
|
2022-12-05 06:52:19 +00:00
|
|
|
|
var json = e.Data;
|
|
|
|
|
//{"Id":"122522636742819840","TaskId":"122522636742819840","IsGoods":true}
|
|
|
|
|
|
2023-01-29 10:07:38 +00:00
|
|
|
|
//var json = "{\"TaskId\":\"142515582485397504\",\"CollectionSourceId\":\"129505086429724672\",\"IsGoods\":true}";
|
2023-01-27 09:53:21 +00:00
|
|
|
|
|
2023-04-06 01:07:55 +00:00
|
|
|
|
//{"Code":0,"Result":{"TaskId":"161068119245193216","CollectionSourceId":"129505086429724672","IsGoods":true}}
|
|
|
|
|
|
2022-12-05 06:52:19 +00:00
|
|
|
|
var jObj = JObject.Parse(json);
|
2023-04-06 01:07:55 +00:00
|
|
|
|
|
2022-12-05 06:52:19 +00:00
|
|
|
|
var taskId = jObj["TaskId"]?.Value<string>();
|
|
|
|
|
if (string.IsNullOrWhiteSpace(taskId))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-07 04:01:44 +00:00
|
|
|
|
if (CacheDic.ContainsKey(taskId))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-01-27 09:53:21 +00:00
|
|
|
|
|
|
|
|
|
//发送任务来源Id
|
|
|
|
|
var collectionSourceId = jObj["CollectionSourceId"]?.Value<string>();
|
2023-01-29 10:07:38 +00:00
|
|
|
|
|
|
|
|
|
if (Config.sourceId == null)
|
|
|
|
|
{
|
|
|
|
|
Config.sourceId = "129505086429724672";
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-27 09:53:21 +00:00
|
|
|
|
if (Config.sourceId != collectionSourceId)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CacheDic[taskId] = collectionSourceId;
|
2023-04-06 01:07:55 +00:00
|
|
|
|
//var appId = "86574351";
|
|
|
|
|
//var appSecret = "403dbc1a571bb3ba65edb799cce12080";
|
|
|
|
|
//var t = ZySignHelper.GetTimeStamp();
|
|
|
|
|
//var ver = "1.1";
|
|
|
|
|
//var uri = new Uri(
|
|
|
|
|
// $"http://goods.api.52cmg.cn/api/WechatMomentsGoods-WechatMoments/GetTaskData?taskId={taskId}");
|
|
|
|
|
|
|
|
|
|
//HttpHelper http = new HttpHelper();
|
|
|
|
|
//var item = http.GetItem(uri.ToString());
|
|
|
|
|
//item.Header["appid"] = appId;
|
|
|
|
|
//item.Header["t"] = t;
|
|
|
|
|
//item.Header["ver"] = ver;
|
|
|
|
|
//item.Header["sign"] = ZySignHelper.CreateSign(uri, "", appId, appSecret, t, ver);
|
|
|
|
|
//var html = http
|
|
|
|
|
// .GetHtml(item)
|
|
|
|
|
// .Html;
|
|
|
|
|
|
|
|
|
|
var html = CircleTaskHelper.GetSend($"http://goods.api.52cmg.cn/api/WechatMomentsGoods-WechatMoments/GetTaskData?taskId={taskId}");
|
2022-12-07 04:01:44 +00:00
|
|
|
|
|
2022-12-05 06:52:19 +00:00
|
|
|
|
var result = JsonConvert.DeserializeObject<DaiYunYingCircleTaskData>(html);
|
|
|
|
|
if (result == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception($"获取代运营朋友圈任务数据异常");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.Code != 0)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception($"获取代运营朋友圈任务数据异常,{result.Code}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.Result == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//是否商品
|
|
|
|
|
var isGoods = jObj["IsGoods"]?.Value<bool>() ?? false;
|
|
|
|
|
|
|
|
|
|
//发送的内容
|
|
|
|
|
var content = result.Result.OriginalXml;
|
|
|
|
|
|
|
|
|
|
//发送图片
|
|
|
|
|
var images = result.Result.MediaList.Select(f => f.Url).ToArray();
|
|
|
|
|
|
|
|
|
|
//评论数据
|
|
|
|
|
var commentList = result.Result.CommentList;
|
|
|
|
|
|
|
|
|
|
//中间页地址
|
|
|
|
|
string ZJYUrl = string.Empty;
|
|
|
|
|
|
|
|
|
|
////获取所有当前进程微信 并只获取个人微信
|
|
|
|
|
//var robotConnectionList = RobotWebSocketServer.GetConnectionAll().Where(f => f.RobotType == (int)RobotType.微信).ToList();
|
|
|
|
|
//foreach (var robotConnection in robotConnectionList)
|
|
|
|
|
//{
|
|
|
|
|
// FollowOfficial(robotConnection, content, commentList, images);
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//检测是否在线
|
|
|
|
|
var clients = Chat.Framework.ChatClient.WXClient.Values.ToList().Where(f =>
|
|
|
|
|
(f.WeixinType == WeixinType.Grpc微信 || f.WeixinType == WeixinType.Hook微信) &&
|
|
|
|
|
f.Status == WxStatus.在线)
|
|
|
|
|
.ToList();
|
|
|
|
|
if (clients.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Class1.Config.SignId = long.Parse(taskId);
|
|
|
|
|
Util.Save(Class1.Config);
|
|
|
|
|
|
|
|
|
|
//string convertLink = string.Empty; //转链后
|
|
|
|
|
//string compositeQRCode = string.Empty; //合成的二维码图片
|
|
|
|
|
|
|
|
|
|
//string quanUrl = string.Empty; //券链接
|
|
|
|
|
//string itemUrl = string.Empty; //商品连接
|
|
|
|
|
//var appendQrcode = false; //是否合成优惠券图片
|
|
|
|
|
//CpsType cps = CpsType.京东联盟;
|
|
|
|
|
|
|
|
|
|
#region 获取正文内容并删除正文中的地址
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(content))
|
|
|
|
|
{
|
|
|
|
|
EventClient.OnEvent(this, $"未检测到要转发的正文数据,操作终止");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//处理用户朋友圈中的地址信息(有就删除)
|
|
|
|
|
var reg = Regex.Match(content, @"(?<地址信息>\<location[^\<]+?\</location\>)");
|
|
|
|
|
if (reg.Success)
|
|
|
|
|
{
|
|
|
|
|
content = content.Replace(reg.Groups["地址信息"].Value, string.Empty);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
//是否为商品
|
|
|
|
|
//为商品获取去商品连接和优惠券链接
|
|
|
|
|
if (isGoods)
|
|
|
|
|
{
|
|
|
|
|
if (Class1.Config.Monitor_Interval != 0)
|
|
|
|
|
{
|
|
|
|
|
if (Class1.Config.LastSendTime == DateTime.MinValue ||
|
|
|
|
|
(Class1.Config.LastSendTime.AddMinutes(Class1.Config.Monitor_Interval) <= DateTime.Now))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//appendQrcode = message.ContainsKey("appendQrcode") && message["appendQrcode"].ToString().ToLower() == "true";
|
|
|
|
|
//if (message.ContainsKey("itemUrl"))//获取宝贝连接
|
|
|
|
|
// itemUrl = message["itemUrl"].ToString();
|
|
|
|
|
//if (message.ContainsKey("quanUrl"))//获取优惠券链接
|
|
|
|
|
// quanUrl = message["quanUrl"].ToString();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Class1.Config.LastSendTime = DateTime.MinValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//要发送评论
|
|
|
|
|
List<string> comments = new List<string>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 评语不为空,判断评语中是否包含变量
|
|
|
|
|
|
|
|
|
|
/*if (isGoods && ((!string.IsNullOrWhiteSpace(comment) && comment.Contains(Resources.BuyAddress)) || !string.IsNullOrWhiteSpace(comment)))*/
|
|
|
|
|
|
|
|
|
|
if (isGoods && commentList != null && commentList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
bool isTB = false;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
foreach (var comment in commentList)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (comment.ItemData != null)
|
|
|
|
|
{
|
|
|
|
|
if (comment.ItemData.LmType != LianMengType.淘宝联盟)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var tkl = MonitorThread.AlimamaConvertLink(comment.ItemData,
|
2023-01-30 06:04:32 +00:00
|
|
|
|
comment.ItemData.ActivityId, true, out var zjyUrl, out var buyPassNoFrills, out string compositeQRCode); //阿里妈妈
|
|
|
|
|
|
|
|
|
|
#region 朋友圈内容中追加图片
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(compositeQRCode))
|
|
|
|
|
{
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
sb.Append("<media>");
|
|
|
|
|
sb.Append("<id>" + Tools.GenerateRandomCode(20) + "</id>");
|
|
|
|
|
sb.Append("<type>2</type>");
|
|
|
|
|
sb.Append("<title></title>");
|
|
|
|
|
sb.Append("<description></description>");
|
|
|
|
|
sb.Append("<private>0</private>");
|
|
|
|
|
sb.Append("<url type=\"1\">[图片=" + compositeQRCode + "]</url>");
|
|
|
|
|
sb.Append("<thumb type=\"1\">[图片=" + compositeQRCode + "]</thumb>");
|
|
|
|
|
sb.Append("<size height=\"800.0\" width=\"800.0\" totalSize=\"0\"></size>");
|
|
|
|
|
sb.Append("</media>");
|
|
|
|
|
|
|
|
|
|
var index = content.IndexOf("</mediaList>");
|
|
|
|
|
if (index != -1)
|
|
|
|
|
{
|
|
|
|
|
content = content.Insert(index, sb.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
2022-12-05 06:52:19 +00:00
|
|
|
|
|
|
|
|
|
////处理转链,替换变量
|
|
|
|
|
//if (isTB == true && !Class1.Config.isPyTkl && comment.Contains(Resources.BuyAddress))
|
|
|
|
|
//{
|
|
|
|
|
// convertLink = ZJYUrl;
|
|
|
|
|
//}
|
|
|
|
|
//comment = comment.Replace(Resources.BuyAddress, convertLink)
|
|
|
|
|
// .Replace(Resources.TKLBuyAddress, address);
|
|
|
|
|
|
|
|
|
|
var commentTmp = comment.Comment.Replace("[购买口令]", tkl)
|
|
|
|
|
.Replace("[推广连接]", buyPassNoFrills)
|
|
|
|
|
.Replace("[购买地址]", zjyUrl)
|
|
|
|
|
.Replace("[购买中间页地址]", zjyUrl);
|
|
|
|
|
comments.Add(commentTmp);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
comments.Add(comment.Comment);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isTB = true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2022-12-10 02:09:10 +00:00
|
|
|
|
MonitorThread._ExecuteSend(content, comments, isGoods, taskId);
|
2022-12-05 06:52:19 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
LogHelper.GetSingleObj().Error("代运营处理", ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-20 03:10:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|