294 lines
12 KiB
C#
294 lines
12 KiB
C#
using Api.Framework;
|
||
using Api.Framework.SDK;
|
||
using Api.Framework.Tools;
|
||
using Api.Framework.Utils;
|
||
using CsharpHttpHelper;
|
||
using Main.Entitys;
|
||
using Main.Properties;
|
||
using Newtonsoft.Json.Linq;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Text.RegularExpressions;
|
||
using System.Threading.Tasks;
|
||
using static Api.Framework.Tools.TBHelper;
|
||
|
||
namespace Main
|
||
{
|
||
public class Class1 : Plugin
|
||
{
|
||
|
||
public Class1()
|
||
{
|
||
this.Name = Resources.PluginName;
|
||
this.Note = Resources.PluginNote;
|
||
this.Logo = Resources.通用;
|
||
}
|
||
|
||
#region 自定义变量
|
||
public static Config Config;
|
||
private MainForm mainForm = null;
|
||
// public static VariateReplace variateReplace = null;
|
||
#endregion
|
||
|
||
public override void Start()
|
||
{
|
||
try
|
||
{
|
||
var session = ApiClient.GetSession();
|
||
#region 判断表是否存在,不存在创建表
|
||
if (!session.TableExist<fl_plugin_tb>())
|
||
{
|
||
session.CreateTable<fl_plugin_tb>();
|
||
session.AddUnique<fl_plugin_tb>("rid");
|
||
}
|
||
#endregion
|
||
|
||
//创建配置文件
|
||
Config = this.ReadConfig<Config>();
|
||
SDK.ReciveIMEvent += SDK_ReciveIMEvent;
|
||
SDK.WXNewFriendEvent += SDK_WXNewFriendEvent;
|
||
SDK.WXApplyFriendEvent += SDK_WXApplyFriendEvent;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.OnLog(ex.Message);
|
||
}
|
||
}
|
||
|
||
private void SDK_WXApplyFriendEvent(object sender, Chat.Framework.WXSdk.Events.WXApplyFriend e)
|
||
{
|
||
var strb = new StringBuilder();
|
||
strb.Append($"新用户:{e.NewFriendNick}({e.NewFriendWxid})申请加好友");
|
||
if (!string.IsNullOrWhiteSpace(e.OldFriendWxid))
|
||
strb.Append($"邀请者:{e.OldFriendNick}({e.OldFriendWxid}).");
|
||
if (Config.AcceptFriend)
|
||
{
|
||
string result = e.Client.AgreeAddMe(e.Token);
|
||
strb.Append($"自动接受申请");
|
||
}
|
||
this.OnLog(strb.ToString());
|
||
}
|
||
|
||
private void SDK_WXNewFriendEvent(object sender, Chat.Framework.WXSdk.Events.WXNewFriend e)
|
||
{
|
||
try
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(Config.NewFriendMess))
|
||
e.Client.SendMessage(e.Friend.UserName, Config.NewFriendMess.Replace("[昵称]", e.Friend.NickName).Replace("[账号]", e.Friend.UserName));
|
||
}
|
||
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
|
||
{
|
||
if (mainForm != null)
|
||
{
|
||
mainForm.CloseForm();
|
||
mainForm = null;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.OnLog(ex.Message);
|
||
}
|
||
}
|
||
|
||
private void SDK_ReciveIMEvent(object sender, ReciveIMEvent e)
|
||
{
|
||
try
|
||
{
|
||
//过滤表情xml和卡片xml
|
||
if ((e.Message.ToLower().Contains(@"<appmsg appid=") || e.Message.ToLower().Contains(@"<msg><emoji") || e.Message.StartsWith("[视频=") || e.Message.StartsWith("[表情=") || e.Message.StartsWith("[声音=") || e.Message.StartsWith("[图片=")) && !e.Message.Contains(@"点击链接,再选择浏览器咑閞")) return;
|
||
var item_id = string.Empty;
|
||
try
|
||
{
|
||
var flag = false;
|
||
var _mess = Regex.Replace(e.Message, "Http:/[A-Za-z]", "", RegexOptions.IgnoreCase);
|
||
|
||
//_mess = Util.RemoveEmoji(_mess);
|
||
var tklTmps = new List<string>();
|
||
#region 正常口令
|
||
var regs1 = Regex.Matches(_mess, "[^A-Za-z0-9]?([A-Za-z0-9]{11})[^A-Za-z0-9]?");
|
||
foreach (Match item in regs1)
|
||
{
|
||
if (item.Success)
|
||
{
|
||
var tkl = item.Groups[1].Value;
|
||
if (Regex.IsMatch(tkl, @"(\d{11})"))
|
||
continue;
|
||
flag = true;
|
||
break;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
if (!flag)
|
||
{
|
||
var tklreg = TbAnalysis.GetTklReg();
|
||
flag = Regex.IsMatch(e.Message, tklreg, RegexOptions.IgnoreCase);
|
||
}
|
||
if (!flag)
|
||
{
|
||
flag = Regex.IsMatch(e.Message, @"(yukhj.com|m.tb.cn|m.yeeoq.top|m.uqlsi|m.rijni|m.gkqmj|m.mulwt|uland\\.taobao\\.com|sjtm.me|aa5d.com|d11a.com|f61[a-z].com|92db.com|yqt.so|e22a.com|f61b.com|detail.m.tmall.hk|k.83jie.com|ewqcxz.com|items.alitrip.com|tmqd.me|detail.tmall.hk|url.cn|taobao.com|mashort.cn|tmall.com|tb.cn|detail.yao.95095.com|laiwang.com|dwz.cn|juhuasuan.com|detail.m.tmall.com|zmnxbc.com|s.click.taobao|detail.liangxinyao.com|m.tb.cn)", RegexOptions.IgnoreCase);
|
||
}
|
||
if (!flag)
|
||
{
|
||
flag = Regex.IsMatch(e.Message.Trim(), @"^找.+", RegexOptions.IgnoreCase);
|
||
}
|
||
|
||
if (flag)
|
||
{
|
||
var db = ApiClient.GetSession();
|
||
var data = db.FindSingle<fl_plugin_tb>("rid = @rid", new { rid = e.RobotInfo.id });
|
||
if (data == null || string.IsNullOrWhiteSpace(data.invitecode))
|
||
return;
|
||
var mess = Send(e.Message, data.invitecode, e.GetMemberinfo().username);
|
||
if (!string.IsNullOrWhiteSpace(mess))
|
||
{
|
||
var jObj = JObject.Parse(mess);
|
||
if (jObj["code"] == null || (int)jObj["code"] != 200) throw new Exception(mess);
|
||
var data1 = jObj["data"];
|
||
|
||
var cardTitle = data1["cardTitle"].ToString();//卡片标题
|
||
var title = data1["title"].ToString();//标题
|
||
var description = data1["description"].ToString();//描述
|
||
var picUrl = data1["picUrl"].ToString();//图片
|
||
var url = data1["url"].ToString();//卡片链接
|
||
var shortUrl = data1["shortUrl"].ToString();//文案短链接
|
||
var hb = (decimal)data1["lijin"];//红包
|
||
var yhq = (decimal)data1["coupon"];//优惠券
|
||
var xdj = (decimal)data1["priceAfterCoupon"];//下单价
|
||
|
||
var jy = hb + yhq;//节约
|
||
|
||
//{"code":200,"msg":"success","data":{"title":"预估购买奖励:0.53元,优惠券:1元,下单价:6.9元","description":"包邮 漫花 抽纸 绒触感5层80抽/4包/20包/30包家用卫生纸纸巾","picUrl":"https://img.alicdn.com/bao/uploaded/i4/6000000002192/O1CN012ZcrnM1S3yuYZVHF5_!!6000000002192-0-picassoopen.jpg","url":"https://52tlj.com:8095/m/#/pages/goods/detail?id=652169220578\u0026spm=uehOAiI7g.0.-1\u0026wxid=wxid_hlgorn846ihp22"}}
|
||
|
||
var m = string.Empty;
|
||
switch (Config.SendType)
|
||
{
|
||
case SendTemplateType.卡片:
|
||
m = Config.CardText.Replace("[标题]", cardTitle).Replace("[下单地址]", url);
|
||
break;
|
||
case SendTemplateType.图文:
|
||
m = Config.ImageText;
|
||
break;
|
||
case SendTemplateType.自定义:
|
||
m = Config.CustomContent;
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
e.SendMessage(m.Replace("[商品图片]", picUrl)
|
||
.Replace("[标题]", title)
|
||
.Replace("[下单价]", xdj.ToString("0.00"))
|
||
.Replace("[优惠券]", yhq.ToString("0.00"))
|
||
.Replace("[红包金额]", hb.ToString("0.00"))
|
||
.Replace("[文案描述]", description)
|
||
.Replace("[下单地址]", shortUrl)
|
||
.Replace("[合计节约]", jy.ToString("0.00"))
|
||
);
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.OnLog($"{ex.Message}");
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
}
|
||
}
|
||
|
||
private string Send(string message, string inviteCode, string wxid)
|
||
{
|
||
StringBuilder strb = new StringBuilder("Web接口请求:");
|
||
try
|
||
{
|
||
strb.AppendLine($"内容:{message}");
|
||
|
||
message = HttpHelper.URLEncode(message, Encoding.UTF8);
|
||
var t = HttpExtend.GetTimeStamp();
|
||
var sig = getSign(message, inviteCode, wxid, t);
|
||
|
||
var postData = @"{""appKey"":""" + appKey + @""",""content"":""" + message + @""",""inviteCode"":""" + inviteCode + @""",""sign"":""" + sig + @""",""t"":" + t + @",""wxId"":""" + wxid + @"""}";
|
||
HttpHelper _http = new HttpHelper();
|
||
HttpItem item = new HttpItem()
|
||
{
|
||
URL = "https://www.52tlj.com/cms/v1/api/fl/transfer",
|
||
Method = "POST",
|
||
IsToLower = false,
|
||
Cookie = string.Empty,
|
||
Referer = "",
|
||
Postdata = postData,
|
||
Timeout = 5000,
|
||
ReadWriteTimeout = 5000,
|
||
UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0",
|
||
ContentType = "application/json",
|
||
Allowautoredirect = false
|
||
};
|
||
//item.SetProxyipCDN();
|
||
var result = _http.GetHtml(item);
|
||
var html = result.Html;
|
||
strb.AppendLine($"返回数据:{html}");
|
||
return html;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
strb.AppendLine($"异常:{ex.Message}");
|
||
}
|
||
finally
|
||
{
|
||
LogHelper.GetSingleObj().Debug("", strb.ToString());
|
||
}
|
||
return string.Empty;
|
||
}
|
||
|
||
private string appKey = "qnly";
|
||
private string appSec = "01ae2596ca8e9349";
|
||
|
||
private string getSign(string message, string inviteCode, string wxid, string t)
|
||
{
|
||
try
|
||
{
|
||
//http://39.103.223.90:18095/cms/v1/api/fl/transfer
|
||
//appKey: test
|
||
// appSec:1234
|
||
//appkey+content+inviteCode+t+wxid+appsec
|
||
var md5 = CsharpHttpHelper.HttpHelper.ToMD5(appKey + message + inviteCode + t + wxid + appSec).ToLower();
|
||
|
||
return md5;
|
||
}
|
||
catch (Exception ex)
|
||
{ }
|
||
return string.Empty;
|
||
}
|
||
|
||
}
|
||
}
|