old_flsystem/应用/Weixin.CircleTools/MainForm.cs

947 lines
45 KiB
C#
Raw Normal View History

2022-09-20 03:10:29 +00:00
using Api.Framework;
using Api.Framework.Cps;
using Api.Framework.Enums;
using Api.Framework.Model;
using Api.Framework.SDK;
using Api.Framework.Tools;
using Chat.Framework.WXSdk;
using Chat.Framework.WXSdk.Implement;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using UI.Framework.Controls;
using UI.Framework.Forms;
using Weixin.CircleTools;
using Weixin.CircleTools.Entitys;
using Weixin.CircleTools.Properties;
using static Api.Framework.ApiClient;
using static CircleFriendsTools.Enums;
using ChooseType = CircleFriendsTools.Enums.ChooseType;
namespace CircleFriendsTools
{
public partial class MainForm : BaseForm
{
public MainForm()
{
InitializeComponent();
this.Text = Resources.MainFormTitle;
}
public void CloseForm()
{
try
{
if (!this.IsDisposed)
{
this.Invoke(new Action(delegate
{
this.Close();
this.Dispose();
}));
}
}
catch (Exception ex)
{
ShowError(ex);
}
}
private void MainForm_Load(object sender, EventArgs e)
{
try
{
#region
pageControl1.Bind((page, size) =>
{
var session = ApiClient.GetSession();
var parm = session.NewParamMap();
parm.setPageParamters(page, size);
var result = session.FindPage<fl_plugin_circletools_taskinfos>("select * from fl_plugin_circletools_taskinfos", parm);
return new PageControl.SerchResult() { Result = result.DataList, Total = result.Total };
}, gridControl1, 40, true, true);
label1.Visible = gridView1.RowCount == 0;
#endregion
#region
foreach (TransmitStyleType item in Enum.GetValues(typeof(TransmitStyleType)))
{
this.comboBoxEdit1.Properties.Items.Add(item.ToString());
}
this.comboBoxEdit1.SelectedIndex = (int)Class1.Config.TransmitStyle;
this.textEdit4.Text = Class1.Config.LocationContent;
this.textEdit5.Text = Class1.Config.GatherPoiCrowd;
this.textEdit1.Text = Class1.Config.MonitorCrowd;
this.numericUpDown1.Value = Class1.Config.MonitorIntervalTime;
this.textEdit2.Text = Class1.Config.CustomWebApi;
this.buttonCheck2.Checked = Class1.Config.AutoPraise;
this.numericUpDown2.Value = Class1.Config.AutoPraiseInterval;
this.numericUpDown3.Value = Class1.Config.CustomWebApiIntervalTime;
this.buttonCheck1.Checked = linkLabel3.Enabled = Class1.Config.AutoTurn;
this.checkBox1.Checked = Class1.Config.Turn_Obstinate;
this.memoEdit6.Text = Class1.Config.AppendComment;
var adzone = ApiClient.GetSession().FindAdzoneInfos().FirstOrDefault(f => f.custom_type == Resources.NonautomaticSoftwareType && f.alliance_id == (int)CpsType.);
if (adzone != null)
textBox1.Text = adzone.adzone_name;
#endregion
#region enum的值加载到列表中
var clients = Chat.Framework.ChatClient.WXClient;
foreach (var client in clients.Values)
{
if ((client.WeixinType == WeixinType.Grpc微信 || client.WeixinType == WeixinType.Hook微信) && client.Status == WxStatus.线)
{
if (Class1.Config.send_usernames.Select(f => f.Trim()).Contains(client.WeixinHao.Trim()))
checkedComboBoxEdit_UsernameType.Properties.Items.Add(client.WeixinHao, client.User.Nick.ToString(), CheckState.Checked, true);
else
checkedComboBoxEdit_UsernameType.Properties.Items.Add(client.WeixinHao, client.User.Nick.ToString(), CheckState.Unchecked, true);
if (Class1.Config.manually_send_usernames.Contains(client.WeixinHao.Trim()))
checkedComboBoxEdit1.Properties.Items.Add(client.WeixinHao, client.User.Nick.ToString(), CheckState.Checked, true);
else
checkedComboBoxEdit1.Properties.Items.Add(client.WeixinHao, client.User.Nick.ToString(), CheckState.Unchecked, true);
if (Class1.Config.transpond_send_usernames.Contains(client.WeixinHao.Trim()))
checkedComboBoxEdit2.Properties.Items.Add(client.WeixinHao, client.User.Nick.ToString(), CheckState.Checked, true);
else
checkedComboBoxEdit2.Properties.Items.Add(client.WeixinHao, client.User.Nick.ToString(), CheckState.Unchecked, true);
}
}
#endregion
comboBox1.SelectedIndex = (int)Class1.Config.qrImage;
ShowContentModel();
}
catch (Exception ex)
{
ShowError(ex);
}
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
try
{
if (!string.IsNullOrWhiteSpace(textEdit2.Text) && !Regex.IsMatch(textEdit2.Text.Replace("&amp;", "&"), CsharpHttpHelper.HttpExtend.REGEX_GETURL, RegexOptions.IgnoreCase))
{
if (MessageBox.Show("系统监听的链接不合法,是否继续保存?", "系统提示", MessageBoxButtons.YesNo) == DialogResult.No)
e.Cancel = true;
else
textEdit2.Text = string.Empty;
}
Class1.Config.send_usernames = checkedComboBoxEdit_UsernameType.Properties.GetCheckedItems().ToString().Replace(", ", ",").Replace(" ,", ",").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(f => f.Trim()).ToList();
Class1.Config.manually_send_usernames = checkedComboBoxEdit1.Properties.GetCheckedItems().ToString().Replace(", ", ",").Replace(" ,", ",").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(f => f.Trim()).ToList();
Class1.Config.transpond_send_usernames = checkedComboBoxEdit2.Properties.GetCheckedItems().ToString().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(f => f.Trim()).ToList();
if (!e.Cancel)
{
tokenSource.Cancel();
Class1.Config.TransmitStyle = (TransmitStyleType)Enum.ToObject(typeof(TransmitStyleType), comboBoxEdit1.SelectedIndex);
Class1.Config.LocationContent = textEdit4.Text;
Class1.Config.GatherPoiCrowd = textEdit5.Text;
Class1.Config.MonitorCrowd = textEdit1.Text.Trim();
Class1.Config.MonitorIntervalTime = (int)numericUpDown1.Value;
Class1.Config.CustomWebApi = textEdit2.Text.Trim();
Class1.Config.AutoPraise = buttonCheck2.Checked;
Class1.Config.AutoPraiseInterval = (int)numericUpDown2.Value;
Class1.Config.CustomWebApiIntervalTime = (int)numericUpDown3.Value;
Class1.Config.AutoTurn = buttonCheck1.Checked;
Class1.Config.Turn_Obstinate = checkBox1.Checked;
Class1.Config.qrImage = (QrImageType)comboBox1.SelectedIndex;
Class1.Config.AppendComment = memoEdit6.Text;
Api.Framework.Tools.Util.Save(Class1.Config); //保存配置文件
}
}
catch (Exception ex)
{
ShowError(ex);
e.Cancel = true;
}
}
/// <summary>
/// 检测新账号
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void simpleButton1_Click(object sender, EventArgs e)
{
try
{
if (!string.IsNullOrWhiteSpace(textEdit1.Text))
{
var form = new XtraForm1(textEdit1.Text.Trim());
form.ShowDialog();
}
else ShowError("用户账号为空,不支持检测");
}
catch (Exception ex)
{
ShowError(ex);
}
}
private CancellationTokenSource tokenSource = new CancellationTokenSource();
private void simpleButton2_Click(object sender, EventArgs e)
{
this.simpleButton2.Enabled = false;
try
{
if (string.IsNullOrWhiteSpace(checkedComboBoxEdit1.Text)) throw new Exception("选择要发送的微信");
if (!string.IsNullOrWhiteSpace(memoEdit1.Text))
{
if (!Regex.IsMatch(memoEdit1.Text, @"\[图片=([^]]*)\]"))
{
ShowError($"推送内容中至少添加一张图片.");
return;
}
var clients = Chat.Framework.ChatClient.WXClient;
var usernames = checkedComboBoxEdit1.Properties.GetCheckedItems().ToString().Replace(", ", ",").Replace(" ,", ",").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(f => f.Trim()).ToList();
var t1 = Task.Run(() =>
{
Parallel.ForEach(clients.Values, item =>
{
try
{
if ((item.WeixinType == WeixinType.Grpc微信 || item.WeixinType == WeixinType.Hook微信) && item.Status == WxStatus.线 && usernames.Contains(item.WeixinHao.Trim()))
{
var json = item.SendCircle(memoEdit1.Text);
if (!string.IsNullOrWhiteSpace(memoEdit2.Text))
{
var reg = Regex.Match(json, @"<id>(?<id>\d{15,})</id>");//获取返回的朋友圈id
if (reg.Success) item.SendCircleComment(item.User.Username, reg.Groups["id"].Value, memoEdit2.Text.Trim());
}
}
}
catch (Exception ex)
{
EventClient.OnEvent(this, $"{ex.Message}");
}
});
}, tokenSource.Token);
t1.ContinueWith(f =>
{
this.Invoke(new Action(() =>
{
this.simpleButton2.Enabled = true;
if (!this.IsDisposed) ShowSuccess("推送发送成功");
}));
}, tokenSource.Token);
}
else
if (!this.IsDisposed) ShowError($"推送内容不能为空.");
}
catch (Exception ex)
{
this.simpleButton2.Enabled = true;
if (!this.IsDisposed) ShowError(ex);
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
var sendTask = new SendTaskForm();
if (sendTask.ShowDialog() == DialogResult.OK)
{
pageControl1.GotoPage(1);
label1.Visible = gridView1.RowCount == 0;
ApiClient.GetSession().FindTaskInfosTempGroups(true);
}
}
catch (Exception ex)
{
ShowError(ex);
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
var selectRows = gridView1.GetSelectedRows();
if (selectRows.Length > 0)
{
var id = int.Parse(gridView1.GetRowCellValue(selectRows[0], "id").ToString());
var task_name = gridView1.GetRowCellValue(selectRows[0], "task_name").ToString();
var task_working_day = gridView1.GetRowCellValue(selectRows[0], "task_working_day").ToString();
var task_time = gridView1.GetRowCellValue(selectRows[0], "task_time").ToString();
var task_sendtext = gridView1.GetRowCellValue(selectRows[0], "task_sendtext").ToString();
var task_comment = string.Empty;
if (gridView1.GetRowCellValue(selectRows[0], "task_comment") != null)
task_comment = (gridView1.GetRowCellValue(selectRows[0], "task_comment").ToString());
var is_circulate = (gridView1.GetRowCellValue(selectRows[0], "is_circulate").ToString());
var robotnames = (gridView1.GetRowCellValue(selectRows[0], "robotnames").ToString());
var sendTask = new SendTaskForm(new fl_plugin_circletools_taskinfos() { id = id, task_name = task_name, task_working_day = task_working_day, task_time = task_time, task_sendtext = task_sendtext, is_circulate = is_circulate == "是" ? ChooseType. : ChooseType., task_comment = task_comment, robotnames = robotnames });
if (sendTask.ShowDialog() == DialogResult.OK)
{
pageControl1.GotoPage(1);
label1.Visible = gridView1.RowCount == 0;
ApiClient.GetSession().FindTaskInfosTempGroups(true);
}
}
}
catch (Exception ex)
{
ShowError(ex);
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
var selectRows = gridView1.GetSelectedRows();
if (selectRows.Length > 0)
{
var id = long.Parse(gridView1.GetRowCellValue(selectRows[0], "id").ToString());
var session = ApiClient.GetSession();
session.ExcuteSQL("delete from fl_plugin_circletools_taskinfos where id = @id", new { id = id });
pageControl1.GotoPage(1);
label1.Visible = gridView1.RowCount == 0;
ApiClient.GetSession().FindTaskInfosTempGroups(true);
}
}
catch (Exception ex)
{
ShowError(ex);
}
}
private void simpleButton3_Click(object sender, EventArgs e)
{
try
{
var tgwForm = new SetTGWForm();
tgwForm.ShowDialog();
}
catch (Exception ex)
{
ShowError(ex);
}
}
private void buttonCheck1_Click(object sender, EventArgs e)
{
this.linkLabel3.Enabled = buttonCheck1.Checked;
}
private void comboBoxEdit1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBoxEdit1.SelectedIndex == 1)
labelControl15.Enabled = buttonCheck1.Checked = linkLabel3.Enabled = buttonCheck1.Enabled = true;
else
labelControl15.Enabled = buttonCheck1.Checked = linkLabel3.Enabled = buttonCheck1.Enabled = false;
}
private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
try
{
var tgwForm = new SetTGWForm();
tgwForm.ShowDialog();
var session = ApiClient.GetSession();
session.FindAdzoneInfos(true);
}
catch (Exception ex)
{
ShowError(ex);
}
}
private void linkLabel4_MouseHover(object sender, EventArgs e)
{
toolTip_Text.AutoPopDelay = 10000;
toolTip_Text.InitialDelay = 500;
toolTip_Text.ReshowDelay = 500;
toolTip_Text.ShowAlways = true;
toolTip_Text.SetToolTip(this.linkLabel4, @"您可以从""发单群""、""选品网站""
广");
}
private void linkLabel6_MouseHover(object sender, EventArgs e)
{
toolTip_Pic.AutoPopDelay = 10000;
toolTip_Pic.InitialDelay = 500;
toolTip_Pic.ReshowDelay = 500;
toolTip_Pic.ShowAlways = true;
toolTip_Pic.SetToolTip(this.linkLabel6, @"不填写图片, 程序会自动检测默认图片。
,");
}
private void linkLabel5_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
try
{
var tgwObj = CpsClient.SelectTuiguangwei(CpsType.);
if (tgwObj != null)
{
var tgw = tgwObj as Tuiguangwei;
var session = ApiClient.GetSession();
var adzone = session.FindAdzoneInfos().FirstOrDefault(f => f.alliance_id == (int)CpsType. && f.custom_type == Resources.NonautomaticSoftwareType);
if (adzone != null)//数据库中存在的情况
{
adzone.adzone_pid_cps_name = tgw.Member.username;
adzone.adzone_pid = tgw.Pid;
adzone.adzone_name = tgw.Name;
session.SaveOrUpdate(adzone);
}
else
{
//session.BeginTransaction();
try
{
adzone = new fl_adzone_info()
{
custom_type = Resources.NonautomaticSoftwareType, //自定义类型
adzone_name = tgw.Name, //推广位名称
adzone_pid = tgw.Pid, //推广位pid
adzone_pid_cps_name = tgw.Member.username, //推广位cps名称
alliance_id = (int)CpsType., //联盟id
robot_id = 0, //机器人id
group_id = string.Empty, //群id
member_id = 0, //私人id
is_download = false, //不下载
onoff = false //不禁用
};
session.SaveOrUpdate(adzone);
if (0 == adzone.id)
throw new Exception("对不起,推广位设置异常,请稍后重试!");
//else session.Commit();
}
catch (Exception ex)
{
//session.Rollback();
ShowError(ex);
}
}
textBox1.Text = adzone.adzone_name;
session.FindAdzoneInfos(true);
}
}
catch (Exception ex)
{
ShowError(ex);
}
}
/// <summary>
/// 保存一键发送的产品数据
/// </summary>
Dictionary<string, object> goodsDic = new Dictionary<string, object>();
/// <summary>
/// 加入产品待发送区
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
try
{
if (gridView2.RowCount >= 9) throw new Exception("最多添加9个产品");
if (string.IsNullOrWhiteSpace(memoEdit3.Text.Trim())) throw new Exception("请添加文案");
var adzone = ApiClient.GetSession().FindAdzoneInfos().FirstOrDefault(f => f.custom_type == Resources.NonautomaticSoftwareType && f.alliance_id == (int)CpsType.);
if (adzone == null) throw new Exception("请先设置推广位");
var tbAnalysis = new TBHelper.TbAnalysis();
var itemId = tbAnalysis.FindTbItemIdByStr(memoEdit3.Text);
if (string.IsNullOrWhiteSpace(itemId)) throw new Exception("您发送的链接中未带宝贝信息!");
var date = DateTime.Now.ToString("yyyyMMdd");
if (Class1.Config.recordSendGoods.ContainsKey(date))
{
if (Class1.Config.recordSendGoods[date].Contains(itemId))
throw new Exception("今天已经发送过该商品,以防重复系统予以提示!");
}
var tb_cps = CpsClient.Members.FirstOrDefault(f => f.cpstype == CpsType. && f.username == adzone.adzone_pid_cps_name);
var api = CpsClient.CreateAlimamaRequest(tb_cps);
if (api == null) throw new Exception("创建阿里妈妈API请求失败");
var activityId = string.Empty;
var urls = CsharpHttpHelper.HttpExtend.RegexMatchesUrl(memoEdit3.Text);
if (urls != null && urls.Count != 0)
{
foreach (var item in urls)
{
if (item.ToLower().Contains("uland.taobao"))
{
var reg = Regex.Match(item, @"activityId=(?<活动ID>[A-Za-z0-9]+)", RegexOptions.IgnoreCase);
if (reg.Success)
activityId = reg.Groups["活动ID"].Value;
break;
}
}
}
AnalyzeGoods analyze = new AnalyzeGoods();
//goodsinfo.goods_id = itemId;
var goodsinfo = analyze.FindGoodsInfoToItemId(itemId, adzone.adzone_pid_cps_name, adzone.adzone_pid);
analyze.AnalysisText(memoEdit3.Text, goodsinfo);
if (goodsinfo != null)
{
var coupon_url = goodsinfo.shopping_url + "&activityId=" + activityId;
//检测优惠券的有效性
var coupon = api.CheckCoupon(coupon_url);
//查到宝贝返利存在异常,直接提示没有返利
if (coupon == null || coupon.retStatus != 0) throw new Exception("该产品优惠券已经过期,请重新获取。");
var lastIndex = memoEdit3.Text.Trim().LastIndexOf(@"
");
var describe = memoEdit3.Text.Substring(lastIndex + 4).Trim();
decimal final_price = 0;
if (double.Parse(coupon.startFee) > goodsinfo.normal_price)
final_price = (decimal)goodsinfo.normal_price;
else
final_price = ((decimal)goodsinfo.normal_price - decimal.Parse(coupon.amount));
var good = new { goods_name = goodsinfo.goods_name, price = goodsinfo.normal_price, final_price = final_price, rebate = final_price * ((decimal)goodsinfo.promotion_rate / 100m), rate = goodsinfo.promotion_rate + "%", pic = string.IsNullOrEmpty(textBox3.Text.Trim()) ? goodsinfo.goods_thumbnail_url : textBox3.Text.Trim(), coupon_discount = decimal.Parse(coupon.amount), itemid = goodsinfo.goods_id, describe = goodsinfo.goods_desc, coupon_url = coupon_url };
if (goodsDic.ContainsKey(goodsinfo.goods_name)) throw new Exception("对不起,该商品已存在");
goodsDic.Add(goodsinfo.goods_name, good);
gridControl2.DataSource = goodsDic.Values.ToList();
label_num.Text = (int.Parse(label_num.Text) + 1).ToString();
memoEdit3.Text = textBox3.Text = string.Empty;
}
else
throw new Exception("该商品无返利");
}
catch (Exception ex)
{
ShowError(ex);
}
}
/// <summary>
/// 一键发单删除选中项
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ToolStripMenuItem1_Click(object sender, EventArgs e)
{
try
{
var selectRows = gridView2.GetSelectedRows();
if (selectRows.Length > 0)
{
var title = gridView2.GetRowCellValue(selectRows[0], "goods_name").ToString();
goodsDic.Remove(title);
gridControl2.DataSource = goodsDic.Values.ToList();
}
}
catch (Exception ex)
{
ShowError(ex);
}
}
private StringBuilder strb = new StringBuilder();
private void gridView3_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
{
try
{
var selectRow = gridView3.GetSelectedRows()[0];
var modelName = this.gridView3.GetRowCellValue(selectRow, "ModelName").ToString();//获取列的数据
var sendModel = Class1.Config.send_templates.FirstOrDefault(f => f.ModelName == modelName);
if (sendModel != null)
memoEdit4.Text = sendModel.Content;
}
catch (Exception ex)
{
ShowError(ex);
}
}
/// <summary>
/// 显示一键发送模板(刷新)
/// </summary>
private void ShowContentModel()
{
try
{
//var modelName = Class1.Config.send_templates.Select(f => f.ModelName).ToList();
//gridControl3.DataSource = modelName;
List<object> obj = new List<object>();
foreach (var item in Class1.Config.send_templates)
{
obj.Add(new { ModelName = item.ModelName });
}
gridControl3.DataSource = obj;
}
catch (Exception ex)
{
ShowError(ex);
}
}
private void button4_Click(object sender, EventArgs e)
{
try
{
var form = new SetSendModelForm();
form.ShowDialog();
ShowContentModel();
}
catch (Exception ex)
{
ShowError(ex);
}
}
private async void simpleButton3_Click_1(object sender, EventArgs e)
{
simpleButton3.Enabled = false;
Class1.Config.TransmitStyle = (TransmitStyleType)Enum.ToObject(typeof(TransmitStyleType), comboBoxEdit1.SelectedIndex);
Class1.Config.LocationContent = textEdit4.Text;
Class1.Config.GatherPoiCrowd = textEdit5.Text;
Class1.Config.MonitorCrowd = textEdit1.Text.Trim();
Class1.Config.MonitorIntervalTime = (int)numericUpDown1.Value;
Class1.Config.CustomWebApi = textEdit2.Text.Trim();
Class1.Config.AutoPraise = buttonCheck2.Checked;
Class1.Config.AutoPraiseInterval = (int)numericUpDown2.Value;
Class1.Config.CustomWebApiIntervalTime = (int)numericUpDown3.Value;
Class1.Config.AutoTurn = buttonCheck1.Checked;
Class1.Config.Turn_Obstinate = checkBox1.Checked;
Class1.Config.transpond_send_usernames = checkedComboBoxEdit2.Properties.GetCheckedItems().ToString().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(f => f.Trim()).ToList();
Util.Save(Class1.Config); //保存配置文件
var t1 = Task.Run(delegate
{
var timer = TimerTask.GetTimer<MonitorThread>() as MonitorThread;
timer.Run("立即检测", false);
}, tokenSource.Token);
try
{
await t1;
if (!this.IsDisposed) ShowSuccess("立即执行定时检测完成!");
}
catch (Exception ex)
{
if (!this.IsDisposed) ShowError(ex);
}
simpleButton3.Enabled = true;
}
private async void simpleButton4_Click(object sender, EventArgs e)
{
try
{
await Task.Run(delegate
{
var clients = Chat.Framework.ChatClient.WXClient.Values.ToList(); //获取机器人集合
var monitorCrowd = string.Empty; //用户的集合中的id
List<Dictionary<string, object>> news = null; //获取朋友圈的动态
foreach (var item in clients)
{
try
{
if ((item.WeixinType == WeixinType.Grpc微信 || item.WeixinType == WeixinType.Hook微信) && item.Status == WxStatus.线)
{
monitorCrowd = textEdit5.Text.Trim();//undone 获取用户真正的微信id
news = item.FindCircle(monitorCrowd);
//EventClient.OnEvent(this, $"采集账号:{item.WeixinHao} 采集量 = {news.Count}");
if (news != null && news.Count != 0)
{
if (news[0].ContainsKey("ObjectDesc"))
{
var objectDesc = news[0]["ObjectDesc"].ToString(); //新动态的内容部分
var reg = Regex.Match(objectDesc, @"(?<地址信息>\<location.*?\</location\>)");
if (reg.Success)
{
var location = reg.Groups["地址信息"].Value;
reg = Regex.Match(location, @"poiClassifyId=""(?<poi>[^""]+?)""");
if (reg.Success)
{
textEdit4.Text = reg.Groups["poi"].ToString();
if (!this.IsDisposed) ShowSuccess("获取poi信息成功");
return;
}
else
if (!this.IsDisposed) ShowError("获取poi信息失败");
}
else
if (!this.IsDisposed) ShowError("该用户第一条朋友圈不存在poi信息");
}
}
else
if (!this.IsDisposed) ShowError("该用户朋友圈无动态");
}
}
catch (Exception ex)
{
EventClient.OnEvent(this, $"朋友圈工具 - 朋友圈获取poi异常{ex.Message}");
}
}
}, tokenSource.Token);
}
catch (Exception ex)
{
if (!this.IsDisposed) ShowError(ex);
}
}
private void checkedComboBoxEdit_UsernameType_EditValueChanged(object sender, EventArgs e)
{
if (checkedComboBoxEdit_UsernameType.EditValue != null)
Class1.Config.send_usernames = checkedComboBoxEdit_UsernameType.EditValue.ToString().Split(',').Select(f => f.Trim()).ToList();
else
Class1.Config.send_usernames = new List<string>();
}
private void hyperlinkLabelControl2_Click(object sender, EventArgs e)
{
try
{
var image = new ImageForm();
image.ShowDialog();
if (!string.IsNullOrWhiteSpace(Class1.Config.NetworkUrl))
{
var strb = new StringBuilder();
var images = Class1.Config.NetworkUrl.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < images.Length; i++)
{
strb.AppendLine($"[图片={images[i]}]");
}
memoEdit1.Text += strb.ToString();
}
}
catch (Exception ex)
{
ShowError(ex);
}
}
private void hyperlinkLabelControl1_Click(object sender, EventArgs e)
{
try
{
Stream mystream;
OpenFileDialog openfiledialog1 = new OpenFileDialog();
openfiledialog1.Multiselect = true;//允许同时选择多个文件
openfiledialog1.InitialDirectory = "c:\\";
openfiledialog1.Filter = "All Image Files|*.bmp;*.ico;*.gif;*.jpeg;*.jpg;*.png;*.tif;*.tiff|(*.bmp)|*.bmp|(*.ico)|*.ico|(*.gif)|(*.gif)|(*.jpg)|*.jpg;*.jpeg|(*.png)|*.png";
openfiledialog1.FilterIndex = 1;
openfiledialog1.RestoreDirectory = true;
var dialog = openfiledialog1.ShowDialog();
if (dialog == DialogResult.OK)
{
if ((mystream = openfiledialog1.OpenFile()) != null)
{
for (int fi = 0; fi < openfiledialog1.FileNames.Length; fi++)
{
memoEdit1.Text += $"[图片={openfiledialog1.FileNames[fi].ToString()}]\r\n"; //保存图片路径
}
mystream.Close();
}
}
}
catch (Exception ex)
{
ShowError(ex);
}
}
private async void button3_Click(object sender, EventArgs e)
{
try
{
button3.Enabled = false;
fl_plugin_circletools_taskinfos t1 = await Task.Run(() =>
{
try
{
if (goodsDic.Count == 0) throw new Exception("请添加要发布的产品文案");
if (string.IsNullOrWhiteSpace(memoEdit4.Text)) throw new Exception("请选择模板");
var adzone = ApiClient.GetSession().FindAdzoneInfos().FirstOrDefault(f => f.alliance_id == (int)CpsType. && f.custom_type == Resources.NonautomaticSoftwareType);
if (adzone == null) throw new Exception("请先设置推广位");
if (string.IsNullOrWhiteSpace(checkedComboBoxEdit_UsernameType.Text)) throw new Exception("请选择要发送的机器人");
QrImageType qrImage = QrImageType.A;
this.Invoke(new Action(() =>
{
qrImage = (comboBox1.Text == "模板A" ? ApiClient.QrImageType.A : ApiClient.QrImageType.B);
}));
strb.Length = 0;
var tb_cps = CpsClient.Members.FirstOrDefault(f => f.cpstype == CpsType. && f.username == adzone.adzone_pid_cps_name);
var api = CpsClient.CreateAlimamaRequest(tb_cps);
var pid_split = adzone.adzone_pid.Split('_');
var tbAnalysis = new TBHelper.TbAnalysis();
strb.Append(memoEdit4.Text);
foreach (var item in goodsDic.Values)
{
var pic = item.GetType().GetProperty("pic").GetValue(item).ToString();
var item_id = item.GetType().GetProperty("itemid").GetValue(item).ToString();
var title = item.GetType().GetProperty("goods_name").GetValue(item).ToString();
var coupon_click_url = item.GetType().GetProperty("coupon_url").GetValue(item).ToString();//优惠券地址
var describe = item.GetType().GetProperty("describe").GetValue(item).ToString();//商品介绍
//获取淘口令
var tklInfo = tbAnalysis.FindTKL(coupon_click_url, api);
if (tklInfo == null) continue;
var shortUrl = tbAnalysis.FindShortUrlBySrcUrl(coupon_click_url, api);
var temp_url = api.ComposeTbClick(item_id, pic, tklInfo.tkl, tklInfo.isoUrl, true, adzone.adzone_pid, Setting.SystemConfig.ZjyComposeType == ComposeType., (int)DwzType., isCircleZjy: true);
//var temp_url = ApiClient.ShortURL(api.ComposeTbClick(item_id, pic, tkl, coupon_click_url)).Result;//中间页地址
strb.Append("[图片=" + ApiClient.GetQRImage(title, item.GetType().GetProperty("price").GetValue(item).ToString(), item.GetType().GetProperty("coupon_discount").GetValue(item).ToString(), item.GetType().GetProperty("final_price").GetValue(item).ToString(), pic, temp_url, qrImage, CpsType., describe) + "]");
}
var taskinfo = new fl_plugin_circletools_taskinfos();
taskinfo.task_sendtext = strb.ToString();
taskinfo.task_comment = memoEdit5.Text;
taskinfo.robotnames = checkedComboBoxEdit_UsernameType.EditValue.ToString();
return Task.FromResult(taskinfo);
}
catch (Exception)
{
}
return null;
}, tokenSource.Token);
button3.Enabled = true;
AddAutoSendForm sendForm = new AddAutoSendForm(t1);
sendForm.ShowDialog();
}
catch (Exception ex)
{
ShowError(ex);
}
}
/// <summary>
/// 一键发单 发布按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private async void button2_Click(object sender, EventArgs e)
{
try
{
button2.Enabled = false;
if (goodsDic.Count == 0) throw new Exception("请添加要发布的产品文案");
if (string.IsNullOrWhiteSpace(memoEdit4.Text)) throw new Exception("请选择模板");
var adzone = ApiClient.GetSession().FindAdzoneInfos().FirstOrDefault(f => f.alliance_id == (int)CpsType. && f.custom_type == Resources.NonautomaticSoftwareType);
if (adzone == null) throw new Exception("请先设置推广位");
if (string.IsNullOrWhiteSpace(checkedComboBoxEdit_UsernameType.Text)) throw new Exception("请选择要发送的机器人");
var qrImage = (comboBox1.Text == "模板A" ? ApiClient.QrImageType.A : ApiClient.QrImageType.B);
strb.Length = 0;
var t3 = Task.Factory.StartNew(() =>
{
var tb_cps = CpsClient.Members.FirstOrDefault(f => f.cpstype == CpsType. && f.username == adzone.adzone_pid_cps_name);
var api = CpsClient.CreateAlimamaRequest(tb_cps);
//var pid_split = adzone.adzone_pid.Split('_');
var tbAnalysis = new TBHelper.TbAnalysis();
strb.Append(memoEdit4.Text);
foreach (var item in goodsDic.Values)
{
var pic = item.GetType().GetProperty("pic").GetValue(item).ToString();
var item_id = item.GetType().GetProperty("itemid").GetValue(item).ToString();
var title = item.GetType().GetProperty("goods_name").GetValue(item).ToString();
var coupon_click_url = item.GetType().GetProperty("coupon_url").GetValue(item).ToString();//优惠券地址
var describe = item.GetType().GetProperty("describe").GetValue(item).ToString();//商品介绍
var date = DateTime.Now.ToString("yyyyMMdd");
if (!Class1.Config.recordSendGoods.ContainsKey(date))
{
Class1.Config.recordSendGoods.Clear();
Class1.Config.recordSendGoods.Add(date, new List<string>() { item_id });
}
else
Class1.Config.recordSendGoods[date].Add(item_id);
//获取淘口令
var tklInfo = tbAnalysis.FindTKL(coupon_click_url, api);
if (tklInfo == null) continue;
var shortUrl = tbAnalysis.FindShortUrlBySrcUrl(coupon_click_url, api);
var temp_url = api.ComposeTbClick(item_id, pic, tklInfo.tkl, tklInfo.isoUrl, true, adzone.adzone_pid, ApiClient.Setting.SystemConfig.ZjyComposeType == ComposeType., (int)DwzType., isCircleZjy: true);
//var temp_url = ApiClient.ShortURL(api.ComposeTbClick(item_id, pic, tkl, coupon_click_url)).Result;//中间页地址
strb.Append("[图片=" + GetQRImage(title, item.GetType().GetProperty("price").GetValue(item).ToString(), item.GetType().GetProperty("coupon_discount").GetValue(item).ToString(), item.GetType().GetProperty("final_price").GetValue(item).ToString(), pic, temp_url, qrImage, CpsType., describe) + "]");
}
var usernames = checkedComboBoxEdit_UsernameType.EditValue.ToString().Split(',').Select(f => f.Trim()).ToList();
var clients = Chat.Framework.ChatClient.WXClient;
foreach (var item in clients.Values)
{
try
{
if ((item.WeixinType == WeixinType.Grpc微信 || item.WeixinType == WeixinType.Hook微信) && usernames.Contains(item.WeixinHao.Trim()) && item.Status == WxStatus.线)
{
var json = item.SendCircle(strb.ToString());
if (!string.IsNullOrWhiteSpace(memoEdit5.Text))
{
var reg = Regex.Match(json, @"<id>(?<id>\d{15,})</id>");//获取返回的朋友圈id
if (reg.Success) item.SendCircleComment(item.User.Username, reg.Groups["id"].Value, memoEdit5.Text.Trim());
}
}
}
catch (Exception ex)
{
EventClient.OnEvent(this, $"一键发送异常:{item.User.Nick} - {ex.Message}");
}
}
}, tokenSource.Token);
try
{
await t3;
if (!this.IsDisposed)
{
button2.Enabled = true;
label_num.Text = "0";
gridControl2.DataSource = null;
ShowSuccess("发送成功");
goodsDic.Clear();
}
}
catch (Exception ex)
{ }
}
catch (Exception ex)
{
button2.Enabled = true;
ShowError(ex);
}
}
private void memoEdit3_Click(object sender, EventArgs e)
{
memoEdit3.SelectAll();
}
private void labelControl29_Click(object sender, EventArgs e)
{
memoEdit6.Text += labelControl29.Text;
}
}
}