public static OperationResult SetIndustry()
        {
            string accessToken = WeiXinTemplateProcessor.AccessToken;

            if (string.IsNullOrEmpty(accessToken) || accessToken.StartsWith("error"))
            {
                return(new OperationResult(OperationResultType.Error, "获取AccessToken失败!", null));
            }
            string urlFormat = "https://api.weixin.qq.com/cgi-bin/template/api_set_industry?access_token={0}";
            var    data      = new
            {
                industry_id1 = "1",
                industry_id2 = "2"
            };
            WxJsonResult wxJsonResult = WxTemplateHelp.WxCommonSend <WxJsonResult>(accessToken, urlFormat, data, CommonJsonSendType.POST);

            if (wxJsonResult.errcode == ReturnCode.获取access_token时AppSecret错误或者access_token无效)
            {
                accessToken  = WeiXinTemplateProcessor.GetAccessToken(false);
                wxJsonResult = WxTemplateHelp.WxCommonSend <WxJsonResult>(accessToken, urlFormat, data, CommonJsonSendType.POST);
            }
            if (wxJsonResult.errcode != 0)
            {
                return(new OperationResult(OperationResultType.Error, wxJsonResult.errmsg, null));
            }
            return(new OperationResult(OperationResultType.Success, "", null));
        }
        private static PrivateTemplateJsonResult GetPrivateTemplateJsonResult(string accessToken)
        {
            string urlFormat = "https://api.weixin.qq.com/cgi-bin/template/get_all_private_template?access_token={0}";
            PrivateTemplateJsonResult privateTemplateJsonResult = WxTemplateHelp.WxCommonSend <PrivateTemplateJsonResult>(accessToken, urlFormat, null, CommonJsonSendType.GET);

            if (privateTemplateJsonResult.errcode == ReturnCode.获取access_token时AppSecret错误或者access_token无效)
            {
                accessToken = WeiXinTemplateProcessor.GetAccessToken(false);
                privateTemplateJsonResult = WxTemplateHelp.WxCommonSend <PrivateTemplateJsonResult>(accessToken, urlFormat, null, CommonJsonSendType.GET);
            }
            return(privateTemplateJsonResult);
        }
        private static AddtemplateJsonResult AddtemplateJsonResult(string accessToken, string shortId)
        {
            string urlFormat = "https://api.weixin.qq.com/cgi-bin/template/api_add_template?access_token={0}";
            var    data      = new
            {
                template_id_short = shortId
            };
            AddtemplateJsonResult addtemplateJsonResult = WxTemplateHelp.WxCommonSend <AddtemplateJsonResult>(accessToken, urlFormat, data, CommonJsonSendType.POST);

            if (addtemplateJsonResult.errcode == ReturnCode.获取access_token时AppSecret错误或者access_token无效)
            {
                accessToken           = WeiXinTemplateProcessor.GetAccessToken(false);
                addtemplateJsonResult = WxTemplateHelp.WxCommonSend <AddtemplateJsonResult>(accessToken, urlFormat, data, CommonJsonSendType.POST);
            }
            return(addtemplateJsonResult);
        }
        public static OperationResult GetPrivateTemplate()
        {
            string accessToken = WeiXinTemplateProcessor.AccessToken;

            if (string.IsNullOrEmpty(accessToken) || accessToken.StartsWith("error"))
            {
                return(new OperationResult(OperationResultType.Error, "获取AccessToken失败!", null));
            }
            PrivateTemplateJsonResult privateTemplateJsonResult = WeiXinTemplateProcessor.GetPrivateTemplateJsonResult(accessToken);

            if (privateTemplateJsonResult.errcode != 0)
            {
                return(new OperationResult(OperationResultType.Error, privateTemplateJsonResult.errmsg, null));
            }
            return(new OperationResult(OperationResultType.Success, privateTemplateJsonResult));
        }
        public OperationResult Addtemplate(string template_id_short)
        {
            string accessToken = WeiXinTemplateProcessor.GetAccessToken(true);

            if (string.IsNullOrEmpty(accessToken) || accessToken.StartsWith("error"))
            {
                return(new OperationResult(OperationResultType.Error, "获取AccessToken失败!", null));
            }
            string urlFormat = "https://api.weixin.qq.com/cgi-bin/template/api_add_template?access_token={0}";
            var    data      = new
            {
                template_id_short
            };
            AddtemplateJsonResult addtemplateJsonResult = WxTemplateHelp.WxCommonSend <AddtemplateJsonResult>(accessToken, urlFormat, data, CommonJsonSendType.POST);

            if (addtemplateJsonResult.errcode != 0)
            {
                return(new OperationResult(OperationResultType.Error, addtemplateJsonResult.errmsg, null));
            }
            return(new OperationResult(OperationResultType.Success, addtemplateJsonResult.template_id, null));
        }
        public static OperationResult QuickSetWeixinTemplates()
        {
            string accessToken = WeiXinTemplateProcessor.AccessToken;

            if (string.IsNullOrEmpty(accessToken) || accessToken.StartsWith("error"))
            {
                return(new OperationResult(OperationResultType.Error, "获取AccessToken失败!", null));
            }
            GetIndustryJsonResult industryJsonResult = WeiXinTemplateProcessor.GetIndustryJsonResult(accessToken);

            if (industryJsonResult.errcode == ReturnCode.获取access_token时AppSecret错误或者access_token无效)
            {
                accessToken        = WeiXinTemplateProcessor.GetAccessToken(false);
                industryJsonResult = WeiXinTemplateProcessor.GetIndustryJsonResult(accessToken);
            }
            if (industryJsonResult.errcode != 0 && industryJsonResult.errcode != ReturnCode.系统繁忙此时请开发者稍候再试)
            {
                return(new OperationResult(OperationResultType.Error, industryJsonResult.errmsg, null));
            }
            if (industryJsonResult.errcode == ReturnCode.系统繁忙此时请开发者稍候再试 || industryJsonResult.primary_industry.ConvertToIndustryCode() != IndustryCode.IT科技_互联网_电子商务 || industryJsonResult.secondary_industry.ConvertToIndustryCode() != IndustryCode.IT科技_IT软件与服务)
            {
                OperationResult operationResult = WeiXinTemplateProcessor.SetIndustry();
                if (operationResult.ResultType != OperationResultType.Success)
                {
                    return(operationResult);
                }
            }
            PrivateTemplateJsonResult privateTemplateJsonResult = WeiXinTemplateProcessor.GetPrivateTemplateJsonResult(accessToken);

            if (privateTemplateJsonResult.errcode != 0)
            {
                return(new OperationResult(OperationResultType.Error, privateTemplateJsonResult.errmsg, null));
            }
            List <GetPrivateTemplate_TemplateItem> template_list = privateTemplateJsonResult.template_list;
            List <WxtemplateId> wxtemplateIds = WeiXinTemplateProcessor.GetWxtemplateIds();
            int num = template_list.Count;

            foreach (WxtemplateId item in wxtemplateIds)
            {
                GetPrivateTemplate_TemplateItem getPrivateTemplate_TemplateItem = template_list.FirstOrDefault((GetPrivateTemplate_TemplateItem t) => t.title == item.name && t.primary_industry == "IT科技");
                if (getPrivateTemplate_TemplateItem != null)
                {
                    item.templateid = getPrivateTemplate_TemplateItem.template_id;
                }
                else if (num >= 25)
                {
                    item.templateid = "公众号已有模板数量越额了!";
                }
                else
                {
                    AddtemplateJsonResult addtemplateJsonResult = WeiXinTemplateProcessor.AddtemplateJsonResult(accessToken, item.shortId);
                    if (addtemplateJsonResult.errcode != 0)
                    {
                        item.templateid = addtemplateJsonResult.errmsg;
                    }
                    else
                    {
                        num++;
                        item.templateid = addtemplateJsonResult.template_id;
                    }
                }
            }
            return(new OperationResult(OperationResultType.Success, "", wxtemplateIds));
        }