using Api.Framework; using Api.Framework.Enums; using Api.Framework.Model; using Api.Framework.SDK; using Api.Framework.Tools; using Chat.Framework.WXSdk.IPAD; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows.Forms; using TBAppraisalTools.Forms; using TBAppraisalTools.Properties; namespace TBAppraisalTools { public class Class1 : Plugin { public Class1() { this.Logo = Resources.评价工具; this.Name = Resources.PluginName; this.Note = Resources.PluginNote; } #region 自定义变量 private MainForm mainForm = null; public static Config Config = null; #endregion public override void Start() { try { this.SDK.ReciveIMEvent += SDK_ReciveIMEvent; this.SDK.WXReiceveFriendMsgEvent += SDK_WXReiceveFriendMsgEvent; Config = this.ReadConfig(); //TimerTask.NewTimer(2 * 60); //创建线程 - 淘宝Cookies更新的线程 2分钟 } catch (Exception ex) { this.OnLog(ex.Message); } } private void SDK_WXReiceveFriendMsgEvent(object sender, Chat.Framework.WXSdk.Events.WXReiceveFriendMsg e) { throw new NotImplementedException(); } TbAnalysis tbAnalysis = new TbAnalysis(); private void SDK_ReciveIMEvent(object sender, ReciveIMEvent e) { try { var evt = e.Event as Chat.Framework.WXSdk.Events.WXReiceveFriendMsg; if (evt.IsRobot) { var reg = Regex.Match(e.Message, Config.PointOperation);//查询指令是否正常 if (reg.Success) { var point = double.Parse(reg.Groups["积分"].Value); var session = ApiClient.GetSession(); bool state = false; if (Config.Point_RechargeType != Enums.RechargeType.余额) { var passinfo = session.FindWeixinpassword(e.RobotInfo.id); if (passinfo != null && !string.IsNullOrEmpty(passinfo.password)) { var ipad = sender as Chat.Framework.WXSdk.Implement.WXClientImpl_IPAD; var flag = ipad.SendPay(e.Username, "评价助手 - 积分奖励", (int)(point * 100), passinfo.password, 1, Config.Point_RechargeType == Enums.RechargeType.红包 ? PayType.红包 : PayType.转账, passinfo.GetBank()); if (string.IsNullOrEmpty(flag)) { e.SendMessage(Config.PointRechargeSuccess.Replace("[积分金额]", point.ToString())); return; } } else this.OnLog("微信支付推荐人奖励失败:未设置支付密码.奖励以积分形式充值"); if (!state) { if (session.ChangePoint(PointType.其他奖励, point, e.GetMemberinfo(true), "评价助手 - 积分奖励")) e.SendMessage(Config.PointRechargeSuccess.Replace("[奖励积分]", point.ToString()).Replace("[剩余积分]", e.GetMemberinfo(true).cur_point.ToString())); else e.SendMessage(Config.PointRechargeError.Replace("[奖励积分]", point.ToString()).Replace("[剩余积分]", e.GetMemberinfo(true).cur_point.ToString())); } } else { if (session.ChangePoint(PointType.其他奖励, point, e.GetMemberinfo(true), "评价助手 - 积分奖励")) e.SendMessage(Config.PointRechargeSuccess.Replace("[奖励积分]", point.ToString()).Replace("[剩余积分]", e.GetMemberinfo(true).cur_point.ToString())); else e.SendMessage(Config.PointRechargeError.Replace("[奖励积分]", point.ToString()).Replace("[剩余积分]", e.GetMemberinfo(true).cur_point.ToString())); } return; } } var analysis = new TBHelper.TbAnalysis(); var itemid = analysis.FindItemIdByUrlAndTklAndMkl(e.Message); if (!string.IsNullOrEmpty(itemid)) { e.SendMessage(Config.SearchingTip); if (!Directory.Exists(TbTools.CACHEPATH)) Directory.CreateDirectory(TbTools.CACHEPATH); if (!Directory.Exists(TbTools.OTHERSICOPATH)) Directory.CreateDirectory(TbTools.OTHERSICOPATH); #region 通过淘宝id获取宝贝的信息 var tb = tbAnalysis.FindTbBaseInfo(itemid); if (tb != null) { //var cookies = TbTools.RandomTbCookies(); //if (string.IsNullOrEmpty(cookies)) throw new Exception("没有有效的淘宝Cookies该功能无法使用,请先登录"); var savePath = Config.TbItemSavePath; if (string.IsNullOrEmpty(savePath)) throw new Exception("解析以后保存路径为空,请先设置保存路径"); var dateNode = DateTime.Today.ToString("yyyyMMdd"); //当天保存的目录名称 var itemNode = $"{DateTime.Now.ToString("HHmmss")}_{itemid}"; //保存宝贝的目录名称 savePath = $"{savePath}\\{dateNode}";//解析的目录路径以当天日期 var itemSavePath = $"{savePath}\\{itemNode}";//宝贝解析后图片等信息最终保存目录 if (!Directory.Exists(itemSavePath)) Directory.CreateDirectory(itemSavePath); var couponImage = tbAnalysis.GenerateCouponImage(tb); //生成优惠券图片 var tags = tbAnalysis.FindTagsByItemId(tb.ItemId); //获取宝贝的标签 var tagStr = tags == null ? string.Empty : string.Join(",", tags.Select(f => f.tag).ToArray()); //将标签名保存在数组中,用于拼接后传入评语中 var comments = tbAnalysis.FindWebappCommentInfos(tb.ItemId, Config.AnalyzePage); //移动端 获取评语、图片 if (comments != null && comments.Count == 0) comments = tbAnalysis.FindPcCommentInfos(tb.ItemId, tb.SellerId, Config.AnalyzePage); //PC端 获取评语、图片 if (comments != null && comments.Count != 0) { var putImageNum = Config.PUTImage; //要多少几张GIF图片 var Gifpics = new List(); List commentstrb = new List(); if (File.Exists(TbTools.ABDUCTIONICO)) Gifpics.Add(TbTools.ABDUCTIONICO); foreach (var item in comments) { if (Gifpics.Count <= putImageNum) //获取用户需要的图片数量 { if (item.pics.Count != 0) { foreach (var pic in item.pics) { try { var tempPic = TbTools.RandomFile(); Tools.DownloadImage(pic, tempPic); if (Gifpics.Count < putImageNum) Gifpics.Add(tempPic); else break; } catch (Exception ex) { this.OnLog("将网络图片转成本地图片:" + ex.Message); } } } } commentstrb.Add(item.rateContent); //将评价内容保存保存在集合中 } string content = TbTools.GetCommentContents(commentstrb); //截取的评论信息(要让客户评论的评语) if (!string.IsNullOrWhiteSpace(tagStr)) content = tagStr + content; //如果存在标签,将标签拼接在一起,追加到评语最前面 File.WriteAllText($"{itemSavePath}\\text.txt", content); tbAnalysis.FindGifsBySrcPic(Gifpics, couponImage, itemSavePath, itemid); if (Directory.Exists(itemSavePath) && Directory.GetFiles(itemSavePath).Length != 0) e.SendMessage(Config.AnalysisSuccess.Replace("[追加参数]", $"?y={dateNode}&gid={itemNode}")); else e.SendMessage(Config.AnalysisError); } else e.SendMessage("获取不到评价数据,有可能该宝贝没有评价数据"); } #endregion } } catch (Exception ex) { this.OnLog(ex.Message); } } public override void ShowForm() { try { if (mainForm == null || mainForm.IsDisposed) { mainForm = new MainForm(); mainForm.Show(); } mainForm.TopMost = true; mainForm.TopMost = false; } catch (Exception ex) { this.OnLog(ex.Message); } } public override void Stop() { try { TimerTask.Close(); Util.Save(Config); if (mainForm != null) { mainForm.CloseForm(); mainForm = null; } } catch (Exception ex) { this.OnLog(ex.Message); } } } }