using Api.Framework; using Api.Framework.Model; using Api.Framework.SDK; using Api.Framework.Tools; using Chat.Framework; using Chat.Framework.WXSdk.Implement; using CsharpHttpHelper; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using VideoFission.Entitys; using VideoFission.Properties; namespace VideoFission { public class Class1 : Plugin { public Class1() { this.Logo = Resources.视频裂变; this.Name = Resources.PluginName; this.Note = Resources.PluginNote; } #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(); else { if (!session.ColumnExist("fl_plugin_videofission_recorded_info", "record")) session.AddColumn("fl_plugin_videofission_recorded_info", "record", "varchar(255)"); } if (!session.TableExist()) { session.CreateTable(); session.AddUnique("ruletype", "amount"); session.Insertable(new List(){ new fl_plugin_videofission_rule_info() { ruletype = RuleType.好友天数,amount = 5,num = 5}, new fl_plugin_videofission_rule_info() { ruletype = RuleType.好友天数,amount = 15,num = 20}, new fl_plugin_videofission_rule_info() { ruletype = RuleType.好友天数,amount = 99999,num = 30}, new fl_plugin_videofission_rule_info() { ruletype = RuleType.推荐人数,amount = 5,num = 5}, new fl_plugin_videofission_rule_info() { ruletype = RuleType.推荐人数,amount = 15,num = 20}, new fl_plugin_videofission_rule_info() { ruletype = RuleType.推荐人数,amount = 99999,num =30}, new fl_plugin_videofission_rule_info() { ruletype = RuleType.订单总数,amount = 5,num = 5}, new fl_plugin_videofission_rule_info() { ruletype = RuleType.订单总数,amount = 50,num = 20}, new fl_plugin_videofission_rule_info() { ruletype = RuleType.订单总数,amount = 99999,num = 30}, }).ExecuteCommand(); } #endregion //创建配置文件 Config = this.ReadConfig(); SDK.WXNewFriendEvent += SDK_WXNewFriendEvent; SDK.OrderNoticeEvent += SDK_OrderNoticeEvent; SDK.ReciveIMEvent += SDK_ReciveIMEvent; } 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_OrderNoticeEvent(object sender, Api.Framework.Events.OrderNoticeEvent e) { try { if (e.Customer == null && e.Member != null) { if (Config.OnOff) { var session = ApiClient.GetSession(); var wx = ChatClient.WXClient.FirstOrDefault(f => f.Key == e.Member.robot_name).Value; if (wx != null /*&& wx.WeixinType == WeixinType.Grpc微信*/ && wx.Status == Chat.Framework.WXSdk.WxStatus.在线) { //var ipad = wx as WXClientImpl_IPAD; //if (ipad == null) return; var systemOrderStatus = -1; if (e.Order is fl_order_alimama) systemOrderStatus = (int)(e.Order as fl_order_alimama).db_status; if (e.Order is fl_order_pinduoduo) systemOrderStatus = (int)(e.Order as fl_order_pinduoduo).db_status; if (e.Order is fl_order_jingdong) systemOrderStatus = (int)(e.Order as fl_order_jingdong).db_status; if (systemOrderStatus == 1002 || systemOrderStatus == 998 || systemOrderStatus == 999 || systemOrderStatus == 1003) { _ProcessStr(username: e.Member.username); } } } } } catch (Exception ex) { this.OnLog($"{ex.Message} - {ex.StackTrace}"); } } /// /// 新加好友 /// /// /// private void SDK_WXNewFriendEvent(object sender, Chat.Framework.WXSdk.Events.WXNewFriend e) { try { if (Config.OnOff) _ProcessStr(username: e.Friend.UserName); } catch (Exception ex) { this.OnLog($"{ex.Message} . {ex.StackTrace}"); } } /// /// /// /// 用户wxid /// private void _ProcessStr(string username = "", long uid = 0) { try { var session = ApiClient.GetSession(); fl_member_info member = null; if (!string.IsNullOrWhiteSpace(username)) member = session.Find("select * from fl_member_info where username = @username", new { username = username }).FirstOrDefault(); else if (uid != 0) member = session.Find("select * from fl_member_info where id = @id", new { id = uid }).FirstOrDefault(); if (member == null) return; var days = (DateTime.Now.Date - member.crt_time.Date).Days; #region 查询次数/推荐人数/完成订单数(3)/退款数量(3) decimal invite_amount = 0m;//推荐人数 decimal order_amount = 0m;//完成订单数 var incomeResult = session.FindTable(@"select count(id) as num from fl_member_info where inviter_id = @userid UNION ALL select COALESCE(sum(item_num),0) as num from fl_order_alimama where db_userid = @userid and db_status not in (1006,1004) UNION ALL select COALESCE(sum(skuNum),0) as num from fl_order_jingdong where db_userid = @userid and db_status not in (1006,1004) UNION ALL select COALESCE(sum(goods_quantity),0) as num from fl_order_pinduoduo where db_userid = @userid and db_status not in (1006,1004) ", new { userid = member.id }); if (incomeResult.Rows.Count != 0) { invite_amount = decimal.Parse(incomeResult.Rows[0]["num"].ToString()); order_amount = decimal.Parse(incomeResult.Rows[1]["num"].ToString()) + decimal.Parse(incomeResult.Rows[2]["num"].ToString()) + decimal.Parse(incomeResult.Rows[3]["num"].ToString()); } #endregion //查询次数/推荐人数/完成订单数/退款数量 var ruleInvite = session.FindSignInfo(RuleType.推荐人数, (long)invite_amount); var ruleOrder = session.FindSignInfo(RuleType.订单总数, (long)order_amount); var ruleDays = session.FindSignInfo(RuleType.好友天数, days); var recorded_info = session.Find("select * from fl_plugin_videofission_recorded_info where uid = @uid", new { uid = member.id }).FirstOrDefault(); if (recorded_info != null) { int num = 0; AwardItem item = null; if (recorded_info.record == null) item = new AwardItem(); else item = HttpExtend.JsonToDictionary(recorded_info.record).ConvertToObj(); if (ruleInvite != null) { if (item.ruleInviteId != ruleInvite.id) { item.ruleInviteId = ruleInvite.id; num += (int)ruleInvite.num; } } if (ruleOrder != null) { if (item.ruleOrderId != ruleOrder.id) { item.ruleOrderId = ruleOrder.id; num += (int)ruleOrder.num; } } if (ruleDays != null) { if (item.ruleDaysId != ruleDays.id) { item.ruleDaysId = ruleDays.id; num += (int)ruleDays.num; } } if (num != 0) { recorded_info.surplus += num; recorded_info.record = HttpHelper.ObjectToJson(item); session.Saveable(recorded_info).ExecuteCommand(); var robot = session.FindRobotInfo(member.robot_name, member.robot_type); if (robot == null) return; ApiClient.SendMessage(robot, member.username, Config.ParsingTimesIncreaseSuccess.Replace("[剩余次数]", recorded_info.surplus.ToString()).Replace("[增加次数]", num.ToString())); } } } catch (Exception ex) { } } /// /// 通用解析 /// /// /// private void SDK_ReciveIMEvent(object sender, ReciveIMEvent e) { try { #region 自定义电影 if (Config.Custom_OnOff && !string.IsNullOrWhiteSpace(Config.Custom_SearchCMD) && !string.IsNullOrWhiteSpace(Config.Custom_SearchUrl) && !string.IsNullOrWhiteSpace(Config.Custom_SearchMess)) { var reg = Regex.Match(e.Message.Trim(), Config.Custom_SearchCMD); if (reg.Success) { var vname = reg.Groups[1].Value.Trim(); if (!string.IsNullOrWhiteSpace(vname)) { var vmess = Config.Custom_SearchMess.Replace("[电影名]", vname).Replace("[电影网址]", ApiClient.ShortURL(Config.Custom_SearchUrl.Replace("[电影名]", HttpExtend.UrlEncode(vname)), Config.Custom_SearchShortLinkWay).Result ); e.SendMessage(vmess); return; } } } #endregion #region 系统内置电影 var url = e.Message; if (e.Message.Contains("(?<链接>.*?)"); if (regex.Success) { url = regex.Groups["链接"].Value; } } fl_plugin_videofission_recorded_info recorded_info = null; var urlTmp = HttpExtend.RegexMatchUrl(url); if (!string.IsNullOrWhiteSpace(urlTmp)) { var _url = Regex.Match(urlTmp, @"(?(http[s]?://m.v.qq.com)|(http[s]?://m.iqiyi.com)|(http[s]?://v.qq.com/x/page)|(http[s]?://v.qq.com/x/cover)|(http[s]?://www.iqiyi.com/(.*?).html)|(http[s]?://www.le.com/ptv/vplay/(.*?).html)|(http[s]?://www.fun.tv/vplay)|(http[s]?://v.youku.com/v_show/id_)|(http[s]?://www.mgtv.com/(.+?).html)|(mgtv.com/(.+?).html)|(http[s]?://tv.sohu.com/)|(http[s]?://film.sohu.com/album)|(http[s]?://v.pptv.com/show/)|(http[s]?://www.wasu.cn/Play/show/id/)|(http[s]?://new-play.tu dou.com/v/)|(www.youku.com\?sharekey))", RegexOptions.IgnoreCase); if (_url.Success) { if (Config._Unlimited == Api.Framework.Enums.SwitchType.关闭)//没有开启无限制 { //查询用户的信息 var session = ApiClient.GetSession(); recorded_info = session.Find($"select * from fl_plugin_videofission_recorded_info where uid = '{e.GetMemberinfo().id}'").FirstOrDefault(); if (recorded_info == null && Config._Experience == Api.Framework.Enums.SwitchType.开启)//用户为新用户,并且新用户免费多少次开着 { recorded_info = new fl_plugin_videofission_recorded_info() { uid = e.GetMemberinfo().id, surplus = Config.ExperienceCount }; session.Insertable(recorded_info).ExecuteReturnEntity(); } if (recorded_info.surplus > 0) { recorded_info.surplus = recorded_info.surplus - 1; e.SendMessage(Config.LinkResolvedSuccessfully.Replace("[剩余次数]", recorded_info.surplus.ToString()).Replace("[播放链接]", ApiClient.ShortURL(Tools.FindAnalysisUrlFulfill(urlTmp), Config.ShortLinkWay).Result)); session.Updateable(recorded_info).ExecuteCommand(); } else//播放次数不足够时 e.SendMessage(Config.PromptOfInsufficientBalance.Replace("[剩余次数]", recorded_info.surplus.ToString())); } else e.SendMessage(Config.LinkResolvedSuccessfully_Unlimited.Replace("[播放链接]", ApiClient.ShortURL(Tools.FindAnalysisUrlFulfill(urlTmp), Config.ShortLinkWay).Result)); } } if (!string.IsNullOrWhiteSpace(Config._SearchCMD)) { var reg = Regex.Match(e.Message.Trim(), Config._SearchCMD); if (reg.Success) { var num = reg.Groups["集数"].ToString(); HttpHelper http = new HttpHelper(); HttpItem item = new HttpItem() { URL = "http://www.okzyw.com/index.php?m=vod-search", Method = "post", Referer = "http://www.okzyw.com/?m=vod-type-id-1.html", Postdata = $"wd={HttpExtend.UrlEncode(reg.Groups["电影名"].ToString())}&submit=search", ContentType = "application/x-www-form-urlencoded" }; HttpResult result = http.GetHtml(item); string html = result.Html; if (html.Contains("共0条数据")) { e.SendMessage(Config.SearchResolvedUnSuccessfully.Replace("[电影名]", reg.Groups["电影名"].ToString())); return; } var regs = Regex.Matches(html, @"
  • .+?)\"" target=\""_blank\"">(?<节目名称>.+?) (?<节目类型>.+?) (?<时间>.+?)
  • "); //var regs = Regex.Matches(html, @".+?)\"" target=\""_blank\"">(?<节目名称>.+?)(?:[^<]+?)\s*(?<节目类型>.+?)(?:.+?)(?:[\w\W]+?)(?<时间>.+?)"); foreach (Match reg_ in regs) { var skipUrl = reg_.Groups["跳转地址"].ToString(); var name = reg_.Groups["节目名称"].ToString(); var type = reg_.Groups["节目类型"].ToString(); var dateTime = reg_.Groups["时间"].ToString(); http = new HttpHelper(); item = new HttpItem() { URL = "http://www.okzyw.com" + skipUrl, Method = "get", Cookie = "", Referer = "", Postdata = "", Timeout = 100000, ReadWriteTimeout = 30000, UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Firefox/68.0", ContentType = "text/html", Allowautoredirect = false, ProxyIp = "", Host = "www.okzyw.com", }; result = http.GetHtml(item); html = result.Html; string movieImage = string.Empty; reg = Regex.Match(html, @".+?)"" alt="".+?"" />"); //reg = Regex.Match(html, @"
    (?:.*?).+?)\""/>"); if (reg.Success) { movieImage = reg.Groups["电影图片"].ToString(); } reg = Regex.Match(html, @"

    播放类型:kuyun

    (?<所有链接地址>[\w\W]+?)"); //reg = Regex.Match(html, @"
      \s*(?<所有链接地址>[\w\W]+?)
    "); if (reg.Success) { var session = ApiClient.GetSession(); if (recorded_info == null) { recorded_info = session.Find($"select * from fl_plugin_videofission_recorded_info where uid = '{e.GetMemberinfo().id}'").FirstOrDefault(); if (recorded_info == null && Config._Experience == Api.Framework.Enums.SwitchType.开启)//用户为新用户,并且新用户免费多少次开着 { recorded_info = new fl_plugin_videofission_recorded_info() { uid = e.GetMemberinfo().id, surplus = Config.ExperienceCount }; session.Insertable(recorded_info).ExecuteReturnEntity(); } } if (Config._Unlimited == Api.Framework.Enums.SwitchType.关闭 && recorded_info == null) return;//没有开启无限制 var urls = reg.Groups["所有链接地址"].ToString(); regs = Regex.Matches(urls, @"
  • .+?)"" checked="""" />(?<集>.+?)\$(?:.+?)
  • "); //regs = Regex.Matches(urls, @"
  • .+?)\$(?<播放链接>.+?)\"" checked=\""\"">"); var list = new Dictionary(); foreach (Match reg1_ in regs) { var broadcast_address = reg1_.Groups["播放链接"].ToString(); var ji = reg1_.Groups["集"].ToString(); if (!type.EndsWith("剧")) { list.Add(ji, broadcast_address); break; } if (!list.ContainsKey(ji.Replace("第", "").Replace("集", ""))) list.Add(ji.Replace("第", "").Replace("集", ""), broadcast_address); } string mess = string.Empty; if (list.Count != 0) { if (Config._Unlimited == Api.Framework.Enums.SwitchType.关闭)//没有开启无限制 { if (recorded_info.surplus <= 0)//播放次数不足够时 { e.SendMessage(Config.PromptOfInsufficientBalance.Replace("[剩余次数]", recorded_info.surplus.ToString())); return; } } if (list.Count == 1) { if (Config._Unlimited == Api.Framework.Enums.SwitchType.关闭)//没有开启无限制 { recorded_info.surplus = recorded_info.surplus - 1; } if (recorded_info == null)//用户为新用户,并且新用户免费多少次开着 { recorded_info = new fl_plugin_videofission_recorded_info() { uid = e.GetMemberinfo().id, surplus = Config.ExperienceCount }; session.Insertable(recorded_info).ExecuteReturnEntity(); } else { if (Config._Unlimited == Api.Framework.Enums.SwitchType.关闭) { recorded_info.surplus--; session.Updateable(recorded_info).ExecuteCommand(); } } //[电影图片]、[电影名]、[集数]、[播放链接]、[剩余次数] mess = Config.SearchResolvedSuccessfully.Replace("[电影名]", name).Replace("[集数]", string.IsNullOrWhiteSpace(num) ? list.Keys.First() : num).Replace("[播放链接]", ApiClient.ShortURL(list.Values.First(), Config.ShortLinkWay).Result).Replace("[剩余次数]", recorded_info.surplus.ToString()).Replace("[电影图片]", $"[图片={movieImage}]"); ; } else { if (!string.IsNullOrWhiteSpace(num)) { num = num.Length == 1 ? "0" + num : num;//单数需要显示 0X 格式 if (list.ContainsKey(num)) { if (Config._Unlimited == Api.Framework.Enums.SwitchType.关闭)//没有开启无限制 { recorded_info.surplus = recorded_info.surplus - 1; } //[电影图片]、[电影名]、[集数]、[播放链接]、[剩余次数] mess = Config.SearchResolvedSuccessfully.Replace("[电影名]", name).Replace("[集数]", num).Replace("[播放链接]", ApiClient.ShortURL(list[num], Config.ShortLinkWay).Result).Replace("[剩余次数]", recorded_info.surplus.ToString()).Replace("[电影图片]", $"[图片={movieImage}]"); } else mess = Config.SearchteleplayResolvedUnSuccessfully.Replace("[电影名]", name).Replace("[集数]", num); } else//用户没有输入集数,返回第一个 { if (Config._Unlimited == Api.Framework.Enums.SwitchType.关闭)//没有开启无限制 { recorded_info.surplus = recorded_info.surplus - 1; } //[电影图片]、[电影名]、[集数]、[播放链接]、[剩余次数] mess = Config.SearchResolvedSuccessfully.Replace("[电影名]", name).Replace("[集数]", string.IsNullOrWhiteSpace(num) ? list.Keys.First() : num).Replace("[播放链接]", ApiClient.ShortURL(list.Values.First(), Config.ShortLinkWay).Result).Replace("[剩余次数]", recorded_info.surplus.ToString()).Replace("[电影图片]", $"[图片={movieImage}]"); } } if (Config._Unlimited == Api.Framework.Enums.SwitchType.关闭)//没有开启无限制 { session.Updateable(recorded_info).ExecuteCommand(); } } else { mess = Config.SearchResolvedUnSuccessfully.Replace("[电影名]", name); } if (!string.IsNullOrWhiteSpace(mess)) e.SendMessage(mess); } break; } } } #endregion } catch (Exception ex) { this.OnLog(ex.Message + ex.StackTrace); } } } }