public WxJsonResult GetIndustry(BaseMPDto dto) { dto.AccessToken = GetAccessToken(MPConfig.AppId, MPConfig.AppSecret); var result = TemplateApi.GetIndustry(dto.AccessToken); return(result); }
public void GetIndustryTest() { //var accessToken = AccessTokenContainer.GetAccessToken(_appId); var result = TemplateApi.GetIndustry(_appId); Assert.AreEqual("IT科技", result.primary_industry.first_class); Assert.AreEqual("互联网|电子商务", result.primary_industry.second_class); Assert.AreEqual("IT科技", result.secondary_industry.first_class); Assert.AreEqual("IT软件与服务", result.secondary_industry.second_class); Assert.AreEqual(IndustryCode.IT科技_互联网_电子商务, result.primary_industry.ConvertToIndustryCode()); Assert.AreEqual(IndustryCode.IT科技_IT软件与服务, result.secondary_industry.ConvertToIndustryCode()); }
/// <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); } }