public static void ExcuteSubcirbePush_single() { try { List <SubcribeInfoEn> sublist = SubscribeModel.getSubscribeTask(); foreach (SubcribeInfoEn sub in sublist) { //var data = new //{ // first = new TemplateDataItem("您好,您订阅的" + sub.SubsType + "已触发"), // keyword1 = new TemplateDataItem(sub.Cusno), // keyword2 = new TemplateDataItem(sub.Status), // remark = new TemplateDataItem("触发时间:" + sub.TriggerTime.ToString()) //}; //sub.TemplateId = "-GdghWwMXHwOE_hu1xxm2H5hRDGGRTQwTuGoSIg8xww"; string subcode = ""; if (sub.SubsType == "报关状态") { subcode = sub.DeclarationCode; } else { subcode = sub.OrderCode; } string busiblno = getBusiBlno(sub); var data = new { first = new TemplateDataItem("您好,您订阅的状态已触发"), keyword1 = new TemplateDataItem(subcode), keyword2 = new TemplateDataItem(sub.BusiUnitName), keyword3 = new TemplateDataItem(sub.Contractno), keyword4 = new TemplateDataItem(busiblno), keyword5 = new TemplateDataItem(sub.Status), remark = new TemplateDataItem("触发时间:" + sub.TriggerTime.ToString()) }; sub.TemplateId = "1i5IvENyqxo349wlgluja4skxORiGSB6M5GD_fLeoKk"; string url = ""; if (sub.SubsType == "业务状态" || sub.SubsType == "物流状态") { url = @"http://gwy.jishiks.com/Page/MyBusiness/SubscribeDetail.aspx?code=" + sub.OrderCode; } else { url = @"http://gwy.jishiks.com/Page/DeclSubsDetail.aspx?code=" + sub.DeclarationCode; } SendMassMsgResultEn msg = SendTemplateMessage(TokenModel.AccessToken, sub.Openid, sub.TemplateId, data, url); if (msg.errcode == "0") { SubscribeModel.updateSubscirbeInfo(sub.Id); } LogHelper.Write("TemplateModel_订阅推送回执:" + msg.errcode); } } catch (Exception e) { LogHelper.Write("TemplateModel_订阅推送异常:" + e.Message); } }
public static void ExcuteSubcirbePush_batch() { if (taskFlag) { return; } taskFlag = true;//已经运行 LogHelper.Write("进入订阅执行..."); while (taskFlag) { List <SubcribeInfoEn> sublist = SubscribeModel.getSubscribeTask(); foreach (SubcribeInfoEn sub in sublist) { var data = new { type = new TemplateDataItem(sub.SubsType, "#ff0000"), cusno = new TemplateDataItem(sub.Cusno), tiggertime = new TemplateDataItem(sub.TriggerTime.ToString()), status = new TemplateDataItem(sub.Status) }; //var obj = JsonHelper.SerializeObject(data); if (sub.SubsType == "物流状态") { sub.TemplateId = "2W7nYI371TSk18pLLubXelXz59wA3yMxoWq6o9uLYXY"; } if (sub.SubsType == "报关状态") { sub.TemplateId = "PDpzPNCQdKFyyxTXCxZphl9Vor2mkgfUf-CLqPlLk8E"; } if (sub.SubsType == "业务状态") { sub.TemplateId = "82bKjSd9Iyxdi0JPZMvUZ3zwmuleev6PfXimPfyb7aE"; } SendMassMsgResultEn msg = SendTemplateMessage(TokenModel.AccessToken, sub.Openid, sub.TemplateId, data, "http://weixin.qq.com/download"); if (msg.errcode == "0") { SubscribeModel.updateSubscirbeInfo(sub.Id); } } System.Threading.Thread.Sleep(5000); } }