public void SendMessage(Fans fans, string message) { var PostHttpItem = CreateHttpItem(); PostHttpItem.Method = "post"; PostHttpItem.RequestRetryNumber = 1; PostHttpItem.URL = SendMessageApi; PostHttpItem.ContentType = "application/x-www-form-urlencoded"; PostHttpItem.Header.Add("Origin", "https://api.weibo.com"); PostHttpItem.Referer = "https://api.weibo.com/chat/ "; //PostHttpItem.Encoding = Encoding.UTF8; message = System.Web.HttpUtility.UrlEncode(message); PostHttpItem.Postdata = $"text={message}&uid={fans.uid}&extensions={{\"clientid\":\"ioum121csoxafeztq1x6wymifkx37z\"}}&is_encoded=0&decodetime=1&source=209678993"; HttpResult result = HttpHelper.GetHtml(PostHttpItem); var code = result.Html.ToWeiBoJsonResult <object>(); //判断是否发送失败 if (code.error_code > 0) { PrintMsg(PrintType.info, "方法:SendMessage 出错" + code.error); } else { this.NumberRuns++; this.TodaySendMessageCount++; this.LastSendMessageTime = DateTime.Now; this.LastSendMessageUser = fans; } }
/// <summary> /// 给用户发多个消息线程; 处理逻辑: 给所有粉丝发一个消息瞬时发送,发第二个消息间隔1小时左右 /// </summary> public void SendMoreMessageByNew(Fans fans, List <string> message) { for (int i = 0; i < message.Count; i++) { string msg = message[i].Replace("\n", "").Replace(" ", "").Replace("\t", "").Replace("\r", ""); if (i == 0) { SendMessage(fans, msg); } else { //发送第二个,第三个消息.. Task.Factory.StartNew(() => { //一人发个多消息的间隔时间 Thread.Sleep(RandomNumber(moreOffInterTime_begin, moreOffInterTime_end)); //Task.Delay(RandomNumber(moreOffInterTime_begin, moreOffInterTime_end)); SendMessage(fans, msg); }); } } }
/// <summary> /// 粉丝查询(一版本) /// </summary> /// <param name="pageNum">页号</param> public List <Fans> SearchFansLv1(int pageNum) { var Res = new List <Fans>(); //粉丝查询 var GetHttpItem = CreateHttpItem(); GetHttpItem.Method = "GET"; GetHttpItem.URL = string.Format(SearchFansApiLv1, WeiBoUser.uid, pageNum); //xp-修改 HttpResult SearchFansPageHttpResult = new HttpResult(); while (!SearchFansPageHttpResult.Html.Contains("粉丝列表")) { SearchFansPageHttpResult = HttpHelper.GetHtml(GetHttpItem); Thread.Sleep(RandomNumber(2, 5)); } var fansList = Regex.Matches(SearchFansPageHttpResult.Html, "<img usercard=\\\\\"id=(.*?)&refer_flag=.*?\\\\\" width=\\\\\"50\\\\\" height=\\\\\"50\\\\\" alt=\\\\\"(.*?)\\\\\" src=\\\\\"(.*?)\\\\\">"); //解析粉丝列表 Fans fans = null; if (fansList.Count > 0) { foreach (Match match in fansList) { fans = new Fans(); fans.uid = match.Groups[1].Value; fans.nick = match.Groups[2].Value; fans.image = match.Groups[3].Value; Res.Add(fans); } } else { PrintMsg(PrintType.error, $"SearchFansLv1 查询失败 SearchFansPageHttpResult:{JsonConvert.SerializeObject(SearchFansPageHttpResult)}!"); } PrintMsg(PrintType.info, $"SearchFansLv1 查询成功 pageNum:{pageNum}!"); return(Res); }