old_flsystem/应用/ProductClient/Class1.cs

316 lines
11 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Api.Framework;
using Api.Framework.SDK;
using ProductClient.Properties;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
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;
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;
EventClient.DyyNoticeEvent += EventClient_DyyNoticeEvent;
//EventClient_DyyNoticeEvent(null, new DyyNoticeEvent()
//{
// Data = "{\"Id\":\"122522636742819840\",\"TaskId\":\"122522636742819840\",\"IsGoods\":true}"
//});
}
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
{
EventClient.DyyNoticeEvent -= EventClient_DyyNoticeEvent;
//TimerTask.Close<MonitorThread>();
if (mainForm != null)
{
mainForm.CloseForm();
mainForm = null;
}
}
catch (Exception ex)
{
this.OnLog(ex.Message);
}
}
private static Dictionary<string, string> CacheDic = new Dictionary<string, string>();
private void EventClient_DyyNoticeEvent(object sender, DyyNoticeEvent e)
{
try
{
EventClient.OnEvent(this, $"代运营新动态:{e.Data}");
var json = e.Data;
//{"Id":"122522636742819840","TaskId":"122522636742819840","IsGoods":true}
//var json = "{\"TaskId\":\"133038429393911808\",\"CollectionSourceId\":\"129505086429724672\",\"IsGoods\":true}";
var jObj = JObject.Parse(json);
var taskId = jObj["TaskId"]?.Value<string>();
if (string.IsNullOrWhiteSpace(taskId))
{
return;
}
if (CacheDic.ContainsKey(taskId))
{
return;
}
//发送任务来源Id
var collectionSourceId = jObj["CollectionSourceId"]?.Value<string>();
if (Config.sourceId != collectionSourceId)
{
return;
}
CacheDic[taskId] = collectionSourceId;
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, isGoods, taskId);
}
catch (Exception ex)
{
LogHelper.GetSingleObj().Error("代运营处理", ex.Message);
}
}
}
}