Пример #1
0
        public static WxJsonResult SetIndustry()
        {
            string       accessToken = WxTemplateSendHelp.GetAccessToken();
            WxJsonResult result;

            if (string.IsNullOrEmpty(accessToken) || accessToken.Contains("errcode"))
            {
                result = new WxJsonResult
                {
                    errcode = 40001,
                    errmsg  = "令牌获取失败"
                };
            }
            else
            {
                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 = WxTemplateSendHelp.SendCommonJson <WxJsonResult>(accessToken, urlFormat, data);
                result = wxJsonResult;
            }
            return(result);
        }
Пример #2
0
        public static WxJsonResult DelPrivateTemplate(string template_id)
        {
            string       accessToken = WxTemplateSendHelp.GetAccessToken();
            WxJsonResult result;

            if (string.IsNullOrEmpty(accessToken) || accessToken.Contains("errcode"))
            {
                result = new WxJsonResult
                {
                    errcode = 40001,
                    errmsg  = "Token获取失败"
                };
            }
            else
            {
                string urlFormat = "https://api.weixin.qq.com/cgi-bin/template/del_private_template?access_token={0}";
                var    data      = new
                {
                    template_id
                };
                WxJsonResult wxJsonResult = WxTemplateSendHelp.SendCommonJson <WxJsonResult>(accessToken, urlFormat, data);
                result = wxJsonResult;
            }
            return(result);
        }
Пример #3
0
        public static WxJsonResult QuickSetWeixinTemplates()
        {
            string       accessToken = WxTemplateSendHelp.GetAccessToken();
            WxJsonResult result;

            if (string.IsNullOrEmpty(accessToken) || accessToken.Contains("errcode"))
            {
                result = new WxJsonResult
                {
                    errcode = 40001,
                    errmsg  = "Token获取失败"
                };
            }
            else
            {
                GetIndustryJsonResult industryJsonResult = WxTemplateSendHelp.GetIndustryJsonResult(accessToken);
                if (industryJsonResult.errcode != 0 && industryJsonResult.errcode != -1)
                {
                    industryJsonResult.errmsg = WxTemplateSendHelp.GetErrorMsg(industryJsonResult.errcode, industryJsonResult.errmsg);
                    result = industryJsonResult;
                }
                else
                {
                    if (industryJsonResult.errcode == -1 || industryJsonResult.primary_industry.ConvertToIndustryCode() != IndustryCode.IT科技_互联网_电子商务 || industryJsonResult.secondary_industry.ConvertToIndustryCode() != IndustryCode.IT科技_IT软件与服务)
                    {
                        WxJsonResult wxJsonResult = WxTemplateSendHelp.SetIndustry();
                        if (wxJsonResult.errcode != 0)
                        {
                            wxJsonResult.errmsg = WxTemplateSendHelp.GetErrorMsg(wxJsonResult.errcode, wxJsonResult.errmsg);
                            result = wxJsonResult;
                            return(result);
                        }
                    }
                    GetPrivateTemplateJsonResult privateTemplateJsonResult = WxTemplateSendHelp.GetPrivateTemplateJsonResult(accessToken);
                    if (privateTemplateJsonResult.errcode != 0)
                    {
                        privateTemplateJsonResult.errmsg = WxTemplateSendHelp.GetErrorMsg(privateTemplateJsonResult.errcode, privateTemplateJsonResult.errmsg);
                        result = privateTemplateJsonResult;
                    }
                    else
                    {
                        List <GetPrivateTemplate_TemplateItem> template_list = privateTemplateJsonResult.template_list;
                        List <WxtemplateId> wxtemplateIds = WxTemplateSendHelp.GetWxtemplateIds();
                        int num = template_list.Count;
                        using (List <WxtemplateId> .Enumerator enumerator = wxtemplateIds.GetEnumerator())
                        {
                            while (enumerator.MoveNext())
                            {
                                WxtemplateId item = enumerator.Current;
                                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 = WxTemplateSendHelp.AddtemplateJsonResult(accessToken, item.shortId);
                                    if (addtemplateJsonResult.errcode != 0)
                                    {
                                        item.templateid = addtemplateJsonResult.errmsg;
                                    }
                                    else
                                    {
                                        num++;
                                        item.templateid = addtemplateJsonResult.template_id;
                                    }
                                }
                            }
                        }
                        result = new WxJsonResult
                        {
                            errcode    = 0,
                            errmsg     = "设置成功",
                            AppendData = wxtemplateIds
                        };
                    }
                }
            }
            return(result);
        }