.NET CORE3.1实现微信小程序发送订阅消息(3)

六、实现消息订阅基类,下面的SetTemplateData方法根据自己的情况设置需要推送消息的内容,如果以后有其他订阅消息模板,新增一个类实现SubscribeMessageModel

using System; using System.Collections.Generic; using Newtonsoft.Json; using BestSoft.Common.Resources; using BSFWorkFlow.Common.GeneralUtility; using WXERP.Models; namespace WXERP.Services.SubscribeMessage {   /// <summary>   /// 審核訂閲消息   /// </summary>   public class AuditSubscribeMessage : SubscribeMessageModel   {     private string page;     private string lang;     private Dictionary<string, DataValue> data;     /// <summary>     /// 設置小程序OpenId     /// </summary>     /// <param>數據庫事務</param>     /// <param>下一個審核通知用戶工號</param>     public AuditSubscribeMessage(object dbTransOrCnn, string nextAuditStaffId)     : base(dbTransOrCnn, nextAuditStaffId)     {     }     /// <summary>     /// 消息模板ID     /// </summary>     [JsonProperty("template_id")]     public new string TemplateId => Common.Configuration["WX:Templates:Audit:TemplateId"];     /// <summary>     /// 設置小程序訂閲消息跳轉頁面     /// </summary>     /// <param></param>     /// <param></param>     public void SetPageUrl(string formId, string tableId)     {       Page = string.Format(Common.Configuration["WX:Templates:Audit:PageUrl"],       formId, tableId);     }     /// <summary>     /// 點擊模板卡片后的跳轉頁面     /// </summary>     [JsonProperty("page")]     public new string Page     {       get       {         return page;       }       set       {         page = value;         return;       }     }     /// <summary>     /// 跳轉小程序類型     /// </summary>     [JsonProperty("miniprogram_state")]     public new string MiniprogramState => Common.Configuration["WX:Templates:Audit:MiniprogramState"];     /// <summary>     /// 進入小程序查看的語言類型,支持zh_CN(簡體中文)、en_US(英文)、zh_HK(繁體中文)、zh_TW(繁體中文),默認為zh_CN     /// </summary>     [JsonProperty("lang")]     public new string Lang     {       get       {         lang = Common.Configuration["WX:Templates:Audit:Lang"];         if (!string.IsNullOrEmpty(MyHttpContext.Current.Request.Headers["bsLanKind"]))         lang = MyHttpContext.Current.Request.Headers["bsLanKind"];         return lang;       }       set       {         lang = value;         return;       }     }     /// <summary>     /// 設置審核訂閲消息數據     /// </summary>     /// <param>審核動作:通過、否決、作廢、退回</param>     /// <param>審核狀態:1代表審核完畢</param>     /// <param>審核標題</param>     public void SetTemplateData(WFAuditOperation operation, WFAuditItemStatus itemAuditStatus, string currentWorkflowName)     {       string tip_msg = "";       switch (operation)       {         case WFAuditOperation.AuditPassAndAgree:           if (itemAuditStatus == WFAuditItemStatus.SuccessfulToFinishAllAudits)             tip_msg = GeneralFunction.ReplaceNullOrEmptyStr(SourcesWarehouse.GetStringSources("WFEngine_FinishAuditTip"), "您的單據已審核完成!");           else             tip_msg = GeneralFunction.ReplaceNullOrEmptyStr(SourcesWarehouse.GetStringSources("WFEngine_AuditAgreeTip"), "您有一筆新單據待審核!");         break;         case WFAuditOperation.AuditPassButDegree:           tip_msg = GeneralFunction.ReplaceNullOrEmptyStr(SourcesWarehouse.GetStringSources("WFEngine_AuditDegreeTip"), "您提交的單據等待異議!");         break;         case WFAuditOperation.AuditAbort:           tip_msg = GeneralFunction.ReplaceNullOrEmptyStr(SourcesWarehouse.GetStringSources("WFEngine_AuditAbortTip"), "您提交的單據已被作廢!");         break;         case WFAuditOperation.AuditBack:           tip_msg = GeneralFunction.ReplaceNullOrEmptyStr(SourcesWarehouse.GetStringSources("WFEngine_AuditBackTip"), "您提交的單據已被退回修正!");         break;       }       string title = Common.Configuration["WX:Templates:Audit:Data:Title"];       string content = Common.Configuration["WX:Templates:Audit:Data:Content"];       string date = Common.Configuration["WX:Templates:Audit:Data:Date"];       Dictionary<string, DataValue> data = new Dictionary<string, DataValue>()       {         {title, new DataValue{ Value= currentWorkflowName }},         {content, new DataValue{ Value= tip_msg }},         {date, new DataValue{ Value= DateTime.Now.ToShortDateString() }}       };       Data = data;     }     /// <summary>     /// 審核訂閲消息數據     /// </summary>     [JsonProperty("data")]     public new Dictionary<string, DataValue> Data     {       get       {         return data;       }       set       {         data = value;         return;       }     }   } }

七、编写发送订阅消息,消息推送配置签名认证

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/4fcdba8fbd80227d9ab75d0286a96833.html