Ejemplo n.º 1
0
        public WxJsonResult SetIndustry(SetIndustryDto dto)
        {
            dto.AccessToken = GetAccessToken(MPConfig.AppId, MPConfig.AppSecret);
            var result = TemplateApi.SetIndustry(dto.AccessToken, (Senparc.Weixin.MP.IndustryCode)dto.industry_id1,
                                                 (Senparc.Weixin.MP.IndustryCode)dto.industry_id2);

            return(result);
        }
Ejemplo n.º 2
0
        public void SetIndustryTest()
        {
            //var accessToken = AccessTokenContainer.GetAccessToken(_appId);
            var result = TemplateApi.SetIndustry(_appId, IndustryCode.IT科技_互联网_电子商务, IndustryCode.IT科技_IT软件与服务);

            Assert.IsNotNull(result);
            Assert.AreEqual(ReturnCode.请求成功, result.errcode);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取模板消息的id
        /// </summary>
        /// <param name="templateKey"></param>
        /// <returns></returns>
        string GetTemplateMessageId(string templateKey)
        {
            var appid     = _settingManager.GetSettingValue(AppSettings.Weixin.AppId);
            var appsecret = _settingManager.GetSettingValue(AppSettings.Weixin.AppSecret);

            if (!AccessTokenContainer.CheckRegistered(appid))
            {
                AccessTokenContainer.Register(appid, appsecret);
            }



            //生成获取 template id
            try
            {
                var tempInfo = _templateKeyRepository.FirstOrDefault(t => t.TempMsgKey == templateKey);
                if (tempInfo != null && !string.IsNullOrEmpty(tempInfo.TempMsgId))
                {
                    return(tempInfo.TempMsgId);
                }

                #region 设置行业(调用频率限制)

                try
                {
                    var temps = TemplateApi.GetIndustry(appid);
                    if (temps.primary_industry.first_class == "IT科技" && temps.primary_industry.second_class == "互联网|电子商务" &&
                        temps.secondary_industry.first_class == "房地产" && temps.secondary_industry.second_class == "物业")
                    {
                    }
                    else
                    {
                        TemplateApi.SetIndustry(appid, IndustryCode.IT科技_互联网_电子商务, IndustryCode.房地产_物业);
                    }
                }
                catch (Exception ex)
                {
                    _logger.Error("初始化模板消息", ex);
                }

                #endregion

                var addResult = TemplateApi.Addtemplate(appid, templateKey);
                if (tempInfo != null)
                {
                    tempInfo.TempMsgId = addResult.template_id;
                    _templateKeyRepository.Update(tempInfo);
                }
                else
                {
                    tempInfo            = new TemplateKey();
                    tempInfo.TempMsgKey = templateKey;
                    tempInfo.TempMsgId  = addResult.template_id;
                    _templateKeyRepository.Insert(tempInfo);
                }
                return(tempInfo.TempMsgId);
            }
            catch (Exception ex)
            {
                _logger.Error("获取模板ID失败", ex);
                throw new UserFriendlyException("获取模板ID失败" + Environment.NewLine + ex.Message, ex);
            }
        }