コード例 #1
0
        /// <summary>
        /// 检查ODS账户信息
        /// </summary>
        /// <param name="strAccount"></param>
        /// <param name="strTemplateID"></param>
        /// <param name="strURL"></param>
        /// <param name="strTemData"></param>
        /// <param name="pDlg"></param>
        /// <returns></returns>
        private string CheckAccountInfo(string strAccount, string strTemplateID, string strURL, string strTemData, DlgCommonString pDlgGetOpenIDByAccount)
        {
            if (string.IsNullOrEmpty(strAccount))
            {
                EGExceptionOperator.ThrowX <Exception>("缺少ODS账户", EGActionCode.缺少必要参数);
            }

            if (string.IsNullOrEmpty(strTemplateID))
            {
                EGExceptionOperator.ThrowX <Exception>("缺少模板消息ID", EGActionCode.缺少必要参数);
            }

            if (string.IsNullOrEmpty(strURL))
            {
                EGExceptionOperator.ThrowX <Exception>("缺少模板消息回调地址ID", EGActionCode.缺少必要参数);
            }

            //EG.WeChat.Business.JR.BL.AccountBL pBL = new EG.WeChat.Business.JR.BL.AccountBL();
            //string strOpenID = pBL.GetOpenIDByAccountName(strAccount);
            string strOpenID = pDlgGetOpenIDByAccount.Invoke(strAccount);

            if (string.IsNullOrEmpty(strOpenID))
            {
                EGExceptionOperator.ThrowX <Exception>("缺少账户对应微信用户信息", EGActionCode.缺少目标数据);
            }

            return(strOpenID);
        }
コード例 #2
0
 /// <summary>
 /// 发送模板消息_已知ODS账户,需要获取ODS对应微信用户OpenID
 /// 需要转换消息内容json文本为WCTemplateAction
 /// </summary>
 /// <param name="strAccount">目标ODS账户</param>
 /// <param name="strTemplateID"></param>
 /// <param name="strURL"></param>
 /// <param name="strTemData"></param>
 /// <param name="pDlgGetOpenIDByAccount">通过ODSAccount获取OPenID委托</param>
 public void SendTemplateMessage(string strAccount, string strTemplateID, string strURL, string strTemData, DlgCommonString pDlgGetOpenIDByAccount)
 {
     this.ExecuteTryCatch(() =>
     {
         //检查服务输入信息,并通过ods账户获取微信用户openid
         //由于,模板消息不能大量发送,因此并发性较低,因此,采用直连数据库获取信息
         string strOpenID = CheckAccountInfo(strAccount, strTemplateID, strURL, strTemData, pDlgGetOpenIDByAccount);
         //Json转换为WCTemplateAction实体
         WCTemplateAction pEntity = FromJsonToMatch(strTemData);
         //发送模板消息
         EG.WeChat.Service.WeiXin.WeixinMessageSender.SendTemplateMessage <WCTemplateAction>(strOpenID, strTemplateID, System.Drawing.Color.AliceBlue, strURL, pEntity);
     });
 }