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;
|
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>();
|
|
|
|
|
|
|
|
|
|
var thread = TimerTask.NewTimer<MonitorThread>(60) as MonitorThread;
|
2022-12-05 06:52:19 +00:00
|
|
|
|
|
|
|
|
|
EventClient.DyyNoticeEvent += EventClient_DyyNoticeEvent;
|
|
|
|
|
//EventClient_DyyNoticeEvent(null, new DyyNoticeEvent()
|
|
|
|
|
//{
|
|
|
|
|
// Data = "{\"Id\":\"122522636742819840\",\"TaskId\":\"122522636742819840\",\"IsGoods\":true}"
|
|
|
|
|
//});
|
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
|
|
|
|
|
{
|
|
|
|
|
TimerTask.Close<MonitorThread>();
|
|
|
|
|
if (mainForm != null)
|
|
|
|
|
{
|
|
|
|
|
mainForm.CloseForm();
|
|
|
|
|
mainForm = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
this.OnLog(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-05 06:52:19 +00:00
|
|
|
|
private void EventClient_DyyNoticeEvent(object sender, Api.Framework.Events.DyyNoticeEvent e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var json = e.Data;
|
|
|
|
|
//{"Id":"122522636742819840","TaskId":"122522636742819840","IsGoods":true}
|
|
|
|
|
|
|
|
|
|
var jObj = JObject.Parse(json);
|
|
|
|
|
var taskId = jObj["TaskId"]?.Value<string>();
|
|
|
|
|
if (string.IsNullOrWhiteSpace(taskId))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HttpHelper http = new HttpHelper();
|
|
|
|
|
var html = http
|
|
|
|
|
.GetHtml(
|
|
|
|
|
$"http://goods.api.52cmg.cn/api/WechatMomentsGoods-WechatMoments/GetTaskData?taskId={taskId}")
|
|
|
|
|
.Html;
|
|
|
|
|
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,
|
|
|
|
|
comment.ItemData.ActivityId, out var zjyUrl, out var buyPassNoFrills); //阿里妈妈
|
|
|
|
|
|
|
|
|
|
////处理转链,替换变量
|
|
|
|
|
//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
|
|
|
|
|
|
|
|
|
|
MonitorThread._ExecuteSend(content, comments);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
LogHelper.GetSingleObj().Error("代运营处理", ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-20 03:10:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|