protected void ExcuteSend() { string responseContent = string.Empty; string url = string.Format(urlSendTemplateMsg, AccessTokenManage.GetAccessTokenName()); string first = @"first"": {""value"":""#"",""color"":""$"" },"; string keynote = @"""keyword1"":{""value"":""#"", ""color"":""$"" }"; string sendTemplateMsgContent = @"{ ""touser"":""$"",""template_id"":""#"",""url"":""%"",""data"":{""*""}}"; first = first.Replace("#", templateMsgContent.DicFirst.First().Key).Replace("$", templateMsgContent.DicFirst.First().Value); keynote = keynote.Replace("#", templateMsgContent.DicKeynote.First().Key).Replace("$", templateMsgContent.DicKeynote.First().Value); string dataTemp = first + keynote; string sendTemplateMsg = sendTemplateMsgContent.Replace("$", templateMsgContent.OpenId).Replace("#", templateMsgContent.Template_id).Replace("%", templateMsgContent.Url).Replace("*", dataTemp); sendTemplateMsg = sendTemplateMsg.Remove(sendTemplateMsg.LastIndexOf('"'), 1); HttpManager.Request(url, out responseContent, WebRequestMethods.Http.Post, data: sendTemplateMsg); if (responseContent.Contains("40001")) //token失效码 { url = string.Format(urlSendTemplateMsg, AccessTokenManage.GetAccessTokenName(true)); HttpManager.Request(url, out responseContent, WebRequestMethods.Http.Post, data: sendTemplateMsg); } }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); Logger.Error("网站启动了:" + DateTime.Now); AccessTokenManage.GetAccessTokenName(true); ButtonHelp.InitButton(); Task.Factory.StartNew(() => { var msgContext = new MsgContext(new SendData()); while (true) { msgContext.Process(); Thread.Sleep(60000 * 1435); } }); }
public void Send() { try { var lsOpenId = new List <string>(); var ret = UserManage.GetOpenIdListByAccessTokenNameAndOpenId(AccessTokenManage.GetAccessTokenName()); JObject Jo = (JObject)JsonConvert.DeserializeObject(ret); JArray Jarows = JArray.Parse(Jo["data"]["openid"].ToString()); for (int i = 0; i < Jarows.Count; i++) { lsOpenId.Add(Jarows[i].ToString()); } var record = ControllerHelper.GetMatchedRecord(); lsOpenId.ForEach(p => SendCore(p, record)); } catch (Exception ex) { Logger.Error("给用户发送通知时失败:" + ex); } }