示例#1
0
        public static bool SetMemberCoinsMsgCacheData(SAppMessageType sAppMessageType, string orderId, string form_id, string mobile, object dataObj, out string errMsg)
        {
            string openId      = string.Empty;
            string accessToken = string.Empty;

            errMsg = string.Empty;
            try
            {
                if (MobileTokenBusiness.GetOpenId(mobile, out openId, out errMsg) && SAppTokenMana.GetAccessToken(out accessToken, out errMsg))
                {
                    SAppPushMessageCacheModel msgModel = new SAppPushMessageCacheModel(orderId, mobile, openId, form_id, CommonConfig.SAppMessagePushXmlFilePath, accessToken, sAppMessageType, dataObj);
                    SAppPushMessageBusiness.Add(msgModel);
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
示例#2
0
        public static bool SetMemberCoinsMsgCacheData(string orderId, string form_id, string mobile, SAppMessageType sAppMessageType, object dataObj, out string errMsg)
        {
            string openId      = string.Empty;
            string accessToken = string.Empty;

            errMsg = string.Empty;
            try
            {
                if (MobileTokenBusiness.GetOpenId(mobile, out openId, out errMsg) && SAppTokenMana.GetAccessToken(out accessToken, out errMsg))
                {
                    string xmlFilePath = HttpContext.Current.Server.MapPath("/Config/SAppMessageTemplate.xml");
                    SAppPushMessageCacheModel msgModel = new SAppPushMessageCacheModel(orderId, mobile, openId, form_id, xmlFilePath, accessToken, sAppMessageType, dataObj);
                    SAppPushMessageBusiness.Add(msgModel);
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
示例#3
0
        private static bool Push <TConfig, TData>(string openId, string accessToken, string form_id, TData dataModel, out string errMsg)
        {
            errMsg = string.Empty;
            TConfig configModel = default(TConfig);

            if (!SAppMsgConfig.GetMsgTemplateConfig <TConfig>(ref configModel, CommonConfig.SAppMessagePushXmlFilePath))
            {
                errMsg = "读取微信消息配置文件出错";
                return(false);
            }

            if (string.IsNullOrEmpty(accessToken))
            {
                if (!SAppTokenMana.GetAccessToken(out accessToken, out errMsg))
                {
                    errMsg = "获取微信令牌出错";
                    return(false);
                }
            }

            string json = SAppMessagePushFactory.CreateMsgJson <TConfig, TData>(openId, form_id, configModel, dataModel);
            string url  = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token={0}";

            url = string.Format(url, accessToken);
            string str = Utils.HttpPost(url, json);

            Dictionary <string, object> dict = new Dictionary <string, object>();

            if (WeiXinJsonHelper.GetResponseJsonResult(str, ref dict))
            {
                return(true);
            }
            else
            {
                errMsg = dict["errmsg"].ToString();
                return(false);
            }
        }