public IHttpActionResult BindSupAgent(BindSupAgentDto req) { var res = new ResponseBase(); if (string.IsNullOrEmpty(req.agentcode) || req.authid == null) { res.code = "100"; res.msg = "信息缺失"; } else { try { var service = new WxService(); var data = service.BindSupAgent(req); if (!string.IsNullOrEmpty(data)) { res.code = "100"; res.msg = data; } res.resData = null; } catch (Exception ex) { res.code = "100"; res.msg = ex.Message; } } return(Ok(res)); }
public HttpResponseMessage GetAgentQrCode(string code) { try { var service = new UtilityService(); var wxservice = new WxService(); var qrcontent = code + "|" + wxservice.GetNickNameByAgentCode(code); var imgByte = service.GetGetQrCode(qrcontent); var resp = new HttpResponseMessage(HttpStatusCode.OK) { Content = new ByteArrayContent(imgByte) }; resp.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png"); return(resp); } catch (Exception ex) { var resp = new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent(ex.Message) }; resp.Content.Headers.ContentType = new MediaTypeHeaderValue("text/plain"); return(resp); } }
public IHttpActionResult Withdraw(AccountWithdrawDto accountwithdto) { var res = new ResponseBase(); try { var service = new WxService(); dynamic data = service.Withdraw(accountwithdto); if (!string.IsNullOrEmpty(data)) { res.code = "100"; res.msg = data; } res.resData = null; //res.resData = JsonConvert.DeserializeObject(data); } catch (Exception ex) { res.code = "100"; res.msg = ex.Message; } return(Ok(res)); }
public ActionResult Index(string companyId) { try { if (string.IsNullOrWhiteSpace(companyId)) { return(RedirectToAction("Index", "BrowseError", new { errorMsg = "请打开扫一扫" })); } WX_ApiConfig config = WXApiConfigServices.QueryWXApiConfig(companyId); var timeStamp = DateTimeHelper.TransferUnixDateTime(DateTime.Now).ToString(); var nonceStr = StringHelper.GetRndString(16); var url = Request.Url.ToString(); var accessToken = AccessTokenContainer.TryGetToken(config.AppId, config.AppSecret, false); var ticket = WxAdvApi.GetTicket(accessToken); string signature = WxService.GetJsApiSignature(nonceStr, ticket.ticket, timeStamp, url); ViewBag.Signature = signature; ViewBag.AppId = config.AppId; ViewBag.Timestamp = timeStamp; ViewBag.NonceStr = nonceStr; return(View()); } catch (Exception ex) { ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "调用扫码方法异常", ex, LogFrom.WeiXin); return(RedirectToAction("Index", "BrowseError", new { errorMsg = "调用扫码方法异常" })); } }
public MyResult <object> CheckToken() { if (string.IsNullOrEmpty(base.TokenModel.Id.ToString()) || base.TokenModel.Id < 0) { return(new MyResult <object>(-1, "请检查是否登录")); } return(WxService.CheckToken(base.TokenModel.Id)); }
public UrlWxMPLoginModel(WxService _service, SignInManager <MemberAccount> _signInManager, UserManager <MemberAccount> _userManager, ILogger <WxService> _logger) { wxService = _service; signInManager = _signInManager; userManager = _userManager; logger = _logger; }
private void BtnOpenWechat_Click(object sender, EventArgs e) { try { WxService.InjectWeDll(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private string GetWeiXinSignature(WX_ApiConfig config, string noncestr, string url, string timestamp) { try { var accessToken = AccessTokenContainer.TryGetToken(config.AppId, config.AppSecret, false); var ticket = WxAdvApi.GetTicket(accessToken); return(WxService.GetJsApiSignature(noncestr, ticket.ticket, timestamp, url)); } catch (Exception ex) { ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "分享页面获取签名错误", ex, LogFrom.WeiXin); return(string.Empty); } }
/// <summary> /// 微信公众号 服务器配置 /// </summary> /// <returns></returns> public void Index() { var param = new EnterParamEntity { echoString = Request.QueryString["echoStr"], signature = Request.QueryString["signature"], timestamp = Request.QueryString["timestamp"], nonce = Request.QueryString["nonce"], encrypt_type = Request.QueryString["encrypt_type"], msg_signature = Request.QueryString["msg_signature"], InputStream = Request.InputStream }; //请求方式 string method = Request.HttpMethod; //验签 if (new CheckSignature().Check(param.token, param.signature, param.timestamp, param.nonce)) { if (method.ToUpperInvariant() != "POST") { #region 成为开发者第一步 //token 与公众号后台token保持一致 if (string.IsNullOrEmpty(token)) { Response.Write("Token 错误"); } //回传 echoString Response.Write(param.echoString); #endregion } else { #region 废弃 ////Response.Write("success"); ////var model = WxRequest.Request(param); ////var responseResult = MessageFactory.CreateResponseMessage(model, param); ////LogHelper.WriteLog("【微信】响应消息:" + responseResult, LogMessageType.Info); ////Response.Write(responseResult); #endregion string result = new WxService().ProcessRequest(param); Response.Write(result); } }//验签结束 }
public IHttpActionResult GetPromotionsTop(int type = 0, int?top = null) { var res = new ResponseBase(); try { var service = new WxService(); var data = service.GetPromotions(type, top); res.resData = data; } catch (Exception ex) { res.code = "100"; res.msg = ex.Message; } return(Ok(res)); }
public IHttpActionResult GetArticle(string title) { var res = new ResponseBase(); try { var service = new WxService(); var data = service.GetArticleByTitle(title); res.resData = data; } catch (Exception ex) { res.code = "100"; res.msg = ex.Message; } return(Ok(res)); }
public IHttpActionResult GetCourses(int id) { var res = new ResponseBase(); try { var service = new WxService(); var data = service.GetCourse(id); res.resData = data; } catch (Exception ex) { res.code = "100"; res.msg = ex.Message; } return(Ok(res)); }
public IHttpActionResult GetExperts() { var res = new ResponseBase(); try { var service = new WxService(); var data = service.GetTeachers(1); res.resData = data; } catch (Exception ex) { res.code = "100"; res.msg = ex.Message; } return(Ok(res)); }
public IHttpActionResult GetUserCommission(Guid authid) { var res = new ResponseBase(); try { var service = new WxService(); var data = service.GetUserCommission(authid); res.resData = data; } catch (Exception ex) { res.code = "100"; res.msg = ex.Message; } return(Ok(res)); //return Json(res); }
public IHttpActionResult GetWithdrawRecords(Guid authid, string queryJson = "") { var res = new ResponseBase(); try { var service = new WxService(); dynamic data = service.GetWithdrawRecords(authid, queryJson); res.resData = data; } catch (Exception ex) { res.code = "100"; res.msg = ex.Message; } return(Ok(res)); }
public IHttpActionResult GetAgentRelationship(string agentcode) { var res = new ResponseBase(); try { var service = new WxService(); dynamic data = service.GetAgentRelationship(agentcode); res.resData = data; //res.resData = JsonConvert.DeserializeObject(data); } catch (Exception ex) { res.code = "100"; res.msg = ex.Message; } return(Ok(res)); }
public IHttpActionResult GetWxUser(string openid) { var res = new ResponseBase(); try { dynamic wxuser = new ExpandoObject(); wxuser.openid = openid; var service = new WxService(); var data = service.GetUserTest(wxuser); res.resData = data; } catch (Exception ex) { res.code = "100"; res.msg = ex.Message; } return(Ok(res)); }
public ActionResult Get(string token, string signature, string timestamp, string nonce, string echostr) { try { WX_ApiConfig config = WXApiConfigServices.QueryByToKen(token); if (config == null || string.IsNullOrWhiteSpace(config.AppId) || string.IsNullOrWhiteSpace(config.AppSecret) || string.IsNullOrWhiteSpace(config.Domain) || string.IsNullOrWhiteSpace(config.Token)) { return(Content(string.Empty)); } if (WxService.CheckSignature(config.Token, timestamp, nonce, signature)) { return(Content(echostr)); } } catch (Exception ex) { ExceptionsServices.AddExceptions(ex, "微信公众账号提交验证失败", LogFrom.WeiXin); TxtLogServices.WriteTxtLogEx("Api_Get", "signature:{0};timestamp:{1};nonce:{2};echostr:{3}", signature, timestamp, nonce, echostr); } return(Content(string.Empty)); }
public IHttpActionResult GetUserProfile(Guid authid) { var res = new ResponseBase(); try { var service = new WxService(); var data = service.GetUserProfile(authid); if (data == null) { throw new Exception("未找到用户明细信息"); } res.resData = data; } catch (Exception ex) { res.code = "100"; res.msg = ex.Message; } return(Ok(res)); }
public IHttpActionResult EditUserProfile(UserProfileDto userpfdto) { var res = new ResponseBase(); try { var service = new WxService(); var data = service.EditUserProfile(userpfdto); if (!string.IsNullOrEmpty(data)) { res.code = "100"; res.msg = data; } res.resData = null; } catch (Exception ex) { res.code = "100"; res.msg = ex.Message; } return(Ok(res)); }
public IHttpActionResult GetWxUser(string code, string iv, string encryptedData, string sharecode = null) { var res = new ResponseBase(); try { WxHelper wh = new WxHelper(); dynamic wxuser = wh.GetWxUser(code, iv, encryptedData); wxuser.sharecode = sharecode; var service = new WxService(); var data = service.GetUser(wxuser); res.resData = data; } catch (Exception ex) { res.code = "100"; res.msg = ex.Message; } return(Ok(res)); }
public APIResult <JSConfig> GetWXJSConfig(string url) { return(WxService.GetJSWxConfig(url)); }
public MyResult <object> Unlimited([FromBody] UnlimitedDto model) { return(WxService.GetUnlimited(base.TokenModel.Id)); }
public MyResult <object> Register([FromBody] WxRegisterDto model) { return(WxService.Register(model)); }
public ActionResult Post(string token, string signature, string timestamp, string nonce, string echostr) { WX_ApiConfig config = WXApiConfigServices.QueryByToKen(token); if (config == null || string.IsNullOrWhiteSpace(config.AppId) || string.IsNullOrWhiteSpace(config.AppSecret) || string.IsNullOrWhiteSpace(config.Domain) || string.IsNullOrWhiteSpace(config.Token)) { return(Content(string.Empty)); } //接收数据 //System.IO.StreamReader reader = new System.IO.StreamReader(Request.InputStream); //String xmlData = reader.ReadToEnd(); //XElement xdoc = XElement.Parse(xmlData); //解析XML //var toUserName = xdoc.Element("ToUserName").Value; //var fromUserName = xdoc.Element("FromUserName").Value; //var createTime = xdoc.Element("CreateTime").Value; //string key = xdoc.Element("EventKey").Value; //var content = xdoc.Element("Ticket").Value; //DateTime datatime = DateTime.Now; //if (!string.IsNullOrEmpty(key)) //{ //userin User = wxApi.GetNickname(wxApi.GetToken(config.AppId, config.AppSecret).Accesstoken, fromUserName); // string createSql = "insert into TgCount values('" + key + "','" + createTime + "','" + User.Nickname + "','" + toUserName + "','" + datatime + "')"; // using (DbOperator dboperator = ConnectionManager.CreateReadConnection()) // { // dboperator.ExecuteNonQuery(createSql, 30000); // } //} try { TxtLogServices.WriteTxtLogEx("Api_Post", "AppId:{0};AppSecret:{1};Domain:{2};Token:{3}", config.AppId, config.AppSecret, config.Domain, config.Token); if (!config.Status) { return(Content("该公众账号暂停使用,请稍后再试!")); } if (!WxService.CheckSignature(config.Token, timestamp, nonce, signature)) { return(Content(string.Empty)); } var conversation = new WeiXinConversation(token, Request.InputStream); try { TxtLogServices.WriteTxtLogEx("Api_Post_Request", conversation.RequestDocument.ToString()); //执行微信处理过程 conversation.Execute(); if (conversation.ResponseDocument != null) { TxtLogServices.WriteTxtLogEx("Api_Post_Response", conversation.ResponseDocument.ToString()); } } catch (Exception ex) { ExceptionsServices.AddExceptions(ex, "执行微信处理过程失败", LogFrom.WeiXin); TxtLogServices.WriteTxtLogEx("Api_Post_Error", ex); if (conversation.ResponseDocument != null) { TxtLogServices.WriteTxtLogEx("Api_Post_Error", conversation.ResponseDocument.ToString()); } } if (conversation.ResponseDocument != null) { //如果是微信位置推送则不回复 if (conversation.Request.MsgType == WReqType.Event) { WReqEventBase wreqevent = conversation.Request as WReqEventBase; if (wreqevent != null && wreqevent.Event == EventType.Location) { return(Content(string.Empty)); } } return(Content(conversation.ResponseDocument.ToString())); } } catch (Exception ex) { ExceptionsServices.AddExceptions(ex, "微信提交事件处理失败", LogFrom.WeiXin); TxtLogServices.WriteTxtLogEx("Api_Post_Error", ex); } return(Content(string.Empty)); }
public APIResult <string> CreateMenu(Menu menu) { return(WxService.CreateMenu(menu)); }
public MyResult <object> WxLogin([FromBody] WxLoginDto model) { return(WxService.Login(model)); }
/// <summary> /// 处理作业单流程 /// </summary> /// <param name="flow"></param> /// <returns></returns> public ActionResult <bool> FlowResult(OpreateBillFlowResult flow) { try { if (flow == null) { throw new Exception("参数有误"); } if ((int)flow.FlowResult == 0) { throw new Exception("处理结果数据有误"); } var oflow = _work.Repository <Basic_OpreationFlow>().GetModel(q => q.ID == flow.OpreationFlowID); if (oflow == null) { throw new Exception("作业流程节点不存在"); } var opreationflow = _work.Repository <Basic_Opreation>().GetModel(oflow.OpreationID); if (opreationflow == null) { throw new Exception("作业流程不存在"); } if (flow.FlowResult == PublicEnum.OpreateFlowResult.reback && !opreationflow.IsBackReturn) { throw new Exception("作业流和不支持回退"); } var checkflow = rpsBillFlow.Any(q => q.FlowResult == (int)flow.FlowResult && q.OpreationFlowID == flow.OpreationFlowID && q.BillID == flow.BillID); if (checkflow) { throw new Exception("该作业单已经提交了该节点的处理结果"); } var billmodel = rpsOpreateBill.GetModel(flow.BillID); if (billmodel == null) { throw new Exception("业务单据不存在"); } if (billmodel.State != (int)PublicEnum.BillFlowState.audited) { throw new Exception("作业单状态不允许"); } //所有节点集合, IEnumerable <Basic_OpreationFlow> points = JsonConvert.DeserializeObject <IEnumerable <Basic_OpreationFlow> >(billmodel.FlowsJson); bool writbill = false; switch (flow.FlowResult) { case PublicEnum.OpreateFlowResult.stop: //终止 billmodel.State = (int)PublicEnum.BillFlowState.stop; writbill = true; break; case PublicEnum.OpreateFlowResult.over: //完成,如果是最后一步则修改单据状态 var lastpointid = points.OrderByDescending(o => o.PointIndex).FirstOrDefault().ID; if (flow.OpreationFlowID == lastpointid) { billmodel.State = (int)PublicEnum.BillFlowState.Over; writbill = true; } //如果不是最后一步就给下一步推送信息 /******************************发送管处理人信息**************************************/ var nextpoint = points.OrderBy(o => o.PointIndex).FirstOrDefault(p => p.PointIndex > oflow.PointIndex); var empsIds = _work.Repository <Basic_PostEmployees>().Queryable(p => p.PostID == nextpoint.PostID).Select(s => s.EmployeeID); var ctrp = _work.Repository <Basic_Employee>().Queryable(p => empsIds.Contains(p.ID)).Select(s => s.Login); var msgToUsers = _work.Repository <Auth_User>().Queryable(p => ctrp.Contains(p.Login)); foreach (var item in msgToUsers) { //判断是否绑定微信 if (string.IsNullOrEmpty(item.openID)) { continue; } var sendData = new Dictionary <string, MessageDataBase>(); sendData.Add("first", new MessageDataBase { value = "请尽快完成当前节点的类容" }); sendData.Add("keyword1", new MessageDataBase { value = billmodel.BillName }); sendData.Add("keyword2", new MessageDataBase { value = "作业流程" }); sendData.Add("keyword3", new MessageDataBase { value = nextpoint.PointName }); sendData.Add("keyword4", new MessageDataBase { value = billmodel.CreateDate.ToString("yyyy-MM-dd HH:mm:ss") }); sendData.Add("keyword5", new MessageDataBase { value = billmodel.EndTime.ToString("yyyy-MM-dd HH:mm:ss") }); sendData.Add("remark", new MessageDataBase { value = "ESF微服为安全护航。" }); var Msg = new TemplateMessagePara { template_id = "6HzNyomBRZiKo5u-JgJFbr2ygqdQ-n7wq3c5obqQpY0", touser = item.openID, data = sendData, url = "http://weixin.bjjtza.com/MyWork/Doingwork" }; WxService.SendTemplateMessage(Msg); } /************************************************************************/ break; case PublicEnum.OpreateFlowResult.reback: //退回到最后一步时则退回完成 var relastpointid = points.OrderBy(o => o.PointIndex).FirstOrDefault().ID; if (flow.OpreationFlowID == relastpointid) { billmodel.State = (int)PublicEnum.BillFlowState.Reback; writbill = true; } //如果不是最后一步就给上一步推送信息 /******************************发送管处理人信息**************************************/ var lastpoint = points.OrderByDescending(o => o.PointIndex).FirstOrDefault(p => p.PointIndex < oflow.PointIndex); var empsIds1 = _work.Repository <Basic_PostEmployees>().Queryable(p => p.PostID == lastpoint.PostID).Select(s => s.EmployeeID); var ctrp1 = _work.Repository <Basic_Employee>().Queryable(p => empsIds1.Contains(p.ID)).Select(s => s.Login); var msgToUsers1 = _work.Repository <Auth_User>().Queryable(p => ctrp1.Contains(p.Login)); foreach (var item in msgToUsers1) { //判断是否绑定微信 if (string.IsNullOrEmpty(item.openID)) { continue; } var sendData = new Dictionary <string, MessageDataBase>(); sendData.Add("first", new MessageDataBase { value = "请尽快完成当前节点的类容" }); sendData.Add("keyword1", new MessageDataBase { value = billmodel.BillName }); sendData.Add("keyword2", new MessageDataBase { value = "作业流程" }); sendData.Add("keyword3", new MessageDataBase { value = lastpoint.PointName }); sendData.Add("keyword4", new MessageDataBase { value = billmodel.CreateDate.ToString("yyyy-MM-dd HH:mm:ss") }); sendData.Add("keyword5", new MessageDataBase { value = billmodel.EndTime.ToString("yyyy-MM-dd HH:mm:ss") }); sendData.Add("remark", new MessageDataBase { value = "ESF微服为安全护航。" }); var Msg = new TemplateMessagePara { template_id = "6HzNyomBRZiKo5u-JgJFbr2ygqdQ-n7wq3c5obqQpY0", touser = item.openID, data = sendData, url = "http://weixin.bjjtza.com/MyWork/Doingwork" }; WxService.SendTemplateMessage(Msg); } /************************************************************************/ break; default: break; } var dbflow = flow.MAPTO <Bll_OpreateionBillFlow>(); dbflow.BillID = billmodel.ID; dbflow.FlowEmployeeID = AppUser.EmployeeInfo.ID; dbflow.FlowTime = DateTime.Now; dbflow.ID = Guid.NewGuid(); rpsBillFlow.Add(dbflow); if (writbill) { rpsOpreateBill.Update(billmodel); } _work.Commit(); return(new ActionResult <bool>(true)); } catch (Exception ex) { return(new ActionResult <bool>(ex)); } }
/// <summary> /// 检查好友 /// </summary> private void CheckFriends() { var entities = FormulaHelper.GetEntities <CommonEntities>(); while (true) { try { if (fansQueue.Count > 0) { #region 加载联系人信息并发送开始提示信息 foreach (var item in fansQueue.Where(c => c.State == 3)) { try { #region 加载并保存用户信息 CookieContainer cc = item.Cookies; IDictionary <string, string> synckey = new Dictionary <string, string>(); JObject init_result = WxService.WxInit(ref cc, item.PassTicket, ref synckey); item.SyncKey = synckey; if (init_result == null) { continue; } else if (init_result["BaseResponse"]["Ret"].ToString() == LogoutErrorCode) { FinishFans(item, LoginErrorTimeMessage); } else { var fansinfo = entities.Set <FansInfo>().Where(c => c.OpenID == item.OpenID).FirstOrDefault(); if (fansinfo == null) { fansinfo = new FansInfo(); fansinfo.ID = FormulaHelper.CreateGuid(); fansinfo.OpenID = item.OpenID; fansinfo.NickName = init_result["User"]["NickName"].ToString(); fansinfo.HeadImgUrl = init_result["User"]["HeadImgUrl"].ToString(); fansinfo.RemarkName = init_result["User"]["RemarkName"].ToString(); fansinfo.Sex = int.Parse(init_result["User"]["Sex"].ToString()); fansinfo.Signature = init_result["User"]["Signature"].ToString(); fansinfo.VerifyFlag = int.Parse(init_result["User"]["VerifyFlag"].ToString()); fansinfo.SnsFlag = int.Parse(init_result["User"]["SnsFlag"].ToString()); entities.Set <FansInfo>().Add(fansinfo); } else { fansinfo.NickName = init_result["User"]["NickName"].ToString(); fansinfo.HeadImgUrl = init_result["User"]["HeadImgUrl"].ToString(); fansinfo.RemarkName = init_result["User"]["RemarkName"].ToString(); fansinfo.Sex = int.Parse(init_result["User"]["Sex"].ToString()); fansinfo.Signature = init_result["User"]["Signature"].ToString(); fansinfo.VerifyFlag = int.Parse(init_result["User"]["VerifyFlag"].ToString()); fansinfo.SnsFlag = int.Parse(init_result["User"]["SnsFlag"].ToString()); } } JObject contact_result = WxService.GetContact(ref cc); if (init_result == null) { continue; } else if (init_result["BaseResponse"]["Ret"].ToString() == LogoutErrorCode) { FinishFans(item, LoginErrorTimeMessage); } else { entities.Set <FansFriends>().Delete(c => c.OpenID == item.OpenID); item.Friends = new List <FansFriend>(); foreach (JObject contact in contact_result["MemberList"]) //完整好友名单 { var user = new FansFriends(); user.ID = FormulaHelper.CreateGuid(); user.OpenID = item.OpenID; user.NickName = contact["NickName"].ToString(); user.HeadImgUrl = contact["HeadImgUrl"].ToString(); user.ContactFlag = int.Parse(contact["ContactFlag"].ToString()); user.RemarkName = contact["RemarkName"].ToString(); user.Sex = int.Parse(contact["Sex"].ToString()); user.Signature = contact["Signature"].ToString(); user.VerifyFlag = int.Parse(contact["VerifyFlag"].ToString()); user.StarFriend = int.Parse(contact["StarFriend"].ToString()); user.Province = contact["Province"].ToString(); user.City = contact["City"].ToString(); user.Alias = contact["Alias"].ToString(); user.SnsFlag = int.Parse(contact["SnsFlag"].ToString()); user.KeyWord = contact["KeyWord"].ToString(); entities.Set <FansFriends>().Add(user); var username = contact["UserName"].ToString(); if (user.VerifyFlag == 0 && !SpecialUsers.Contains(username) && !username.Contains("@@") && username != init_result["User"]["UserName"].ToString()) { FansFriend ff = new FansFriend(); ff.UserName = username; ff.NickName = string.IsNullOrEmpty(user.RemarkName) ? user.NickName : user.RemarkName; ff.State = 0; item.Friends.Add(ff); } } } item.Cookies = cc; item.SyncKey = synckey; try { entities.SaveChanges(); } catch (DbEntityValidationException dbEx) { LogWriter.Error(dbEx); throw dbEx; } #endregion #region 发送微信登录提示信息 if (!string.IsNullOrEmpty(CheckStartMessage)) { try { SendWxMsg(item.OpenID, string.Format(CheckStartMessage, item.Friends.Count, (item.Friends.Count / CheckFriendsCount) + 1)); } catch { item.WxErrorCount++; throw; } } #endregion #region 更新用户状态 item.State = 4; var ety = entities.Set <FansLogin>().Find(item.LoginID); if (ety != null) { ety.IsLogin = true; ety.LoginTime = DateTime.Now; entities.SaveChanges(); } #endregion } catch (Exception ex) { LogWriter.Error(ex); } } #endregion #region 检查好友状态 foreach (var item in fansQueue.Where(c => c.State == 4)) { //每次拉群的时间间隔都要超过30秒,不然微信不让调用网页版接口 if (item.LastCheckTime.AddSeconds(CheckFriendsSingleTime) > DateTime.Now) { continue; } CookieContainer cc = item.Cookies; JObject temp = null; #region 添加好友 if (item.ChartRoomUsers.Count() == 0) { var checkfriends = item.Friends.Where(c => c.State == 0).Take(CheckFriendsCount); if (string.IsNullOrEmpty(item.ChartRoomName)) { temp = WxService.CreateRoom(checkfriends.Select(c => c.UserName).ToList(), ref cc, item.SKey, item.PassTicket); item.LastCheckTime = DateTime.Now; item.Cookies = cc; if (temp["BaseResponse"]["Ret"].ToString() == "0") { item.ChartRoomName = temp["ChatRoomName"].ToString(); item.ChartRoomUsers = checkfriends.Select(c => c.UserName).ToList(); } //操作太频繁 else if (temp["BaseResponse"]["Ret"].ToString() == "1" || temp["BaseResponse"]["ErrMsg"].ToString().Contains("频")) { FinishFans(item, WebMaxErrorMsg); } else { item.WebErrorCount++; continue; } } else { temp = WxService.AddMember(item.ChartRoomName, checkfriends.Select(c => c.UserName).ToList(), ref cc, item.SKey, item.PassTicket); item.LastCheckTime = DateTime.Now; if (temp["BaseResponse"]["Ret"].ToString() == "0") { item.ChartRoomName = temp["ChatRoomName"].ToString(); item.ChartRoomUsers = checkfriends.Select(c => c.UserName).ToList(); } //操作太频繁 else if (temp["BaseResponse"]["Ret"].ToString() == "1" || temp["BaseResponse"]["ErrMsg"].ToString().Contains("频")) { FinishFans(item, WebMaxErrorMsg); } else { item.WebErrorCount++; continue; } } item.Cookies = cc; foreach (JObject obj in temp["MemberList"]) { if (obj["MemberStatus"].ToString() == "4") { item.Friends.Where(c => c.UserName == obj["UserName"].ToString()).AsQueryable().Update(c => c.State = 3); } else if (obj["MemberStatus"].ToString() == "3") { item.Friends.Where(c => c.UserName == obj["UserName"].ToString()).AsQueryable().Update(c => c.State = 2); } else { item.Friends.Where(c => c.UserName == obj["UserName"].ToString()).AsQueryable().Update(c => c.State = 1); } } } #endregion #region 移除好友 else { temp = WxService.DeleteMember(item.ChartRoomName, item.ChartRoomUsers, ref cc, item.SKey, item.PassTicket); item.LastCheckTime = DateTime.Now; if (temp["BaseResponse"]["Ret"].ToString() == "0") { item.ChartRoomUsers.Clear(); } //操作太频繁 else if (temp["BaseResponse"]["Ret"].ToString() == "1" || temp["BaseResponse"]["ErrMsg"].ToString().Contains("频")) { FinishFans(item, WebMaxErrorMsg); } else { item.WebErrorCount++; } if (item.Friends.All(c => c.State != 0)) { WxService.Logout(ref cc, item.SKey); var delete = item.Friends.Count(c => c.State == 3); var block = item.Friends.Count(c => c.State == 2); if (delete == 0 && block == 0) { FinishFans(item, CheckGoodMessage); } else { FinishFans(item, string.Format(CheckGoodMessage , delete == 0 ? "没有" : string.Join(",", item.Friends.Where(c => c.State == 3).Select(c => c.NickName)) , block == 0 ? "没有" : string.Join(",", item.Friends.Where(c => c.State == 2).Select(c => c.NickName)))); } } } #endregion item.Cookies = cc; } #endregion #region 检查登录状态 foreach (var item in fansQueue.Where(c => c.State == 4)) { CookieContainer cc = item.Cookies; IDictionary <string, string> synckey = item.SyncKey; var sync_flag = WxService.WxSyncCheck(ref cc, ref synckey, item.SKey); if (sync_flag == LogoutErrorJS) { FinishFans(item, LoginErrorTimeMessage); } else { item.Cookies = cc; item.SyncKey = synckey; } if (item.WxErrorCount > InterfaceMaxError) { FinishFans(item, ""); } if (item.WebErrorCount > InterfaceMaxError) { FinishFans(item, WebMaxErrorMsg); } } foreach (var item in fansQueue.Where(c => new int[] { 1, 2, 3 }.Contains(c.State) && c.WxErrorCount > InterfaceMaxError)) { FinishFans(item, ""); } #endregion } } catch (Exception ex) { LogWriter.Error(ex); } finally { Thread.Sleep(CheckFriendsTime); } } }
public APIResult <MenuQuery> GetMenu() { return(WxService.GetMenu()); }