예제 #1
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);
        }
예제 #2
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);
        }
예제 #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);
        }
예제 #4
0
        public static WxJsonResult QuickSetWeixinTemplates()
        {
            string accessToken = GetAccessToken();

            if (string.IsNullOrEmpty(accessToken) || accessToken.Contains("errcode"))
            {
                return(new WxJsonResult {
                    errcode = 0x9c41, errmsg = "Token获取失败"
                });
            }
            Hidistro.Messages.GetIndustryJsonResult industryJsonResult = GetIndustryJsonResult(accessToken);
            if ((industryJsonResult.errcode != 0) && (industryJsonResult.errcode != -1))
            {
                industryJsonResult.errmsg = GetErrorMsg(industryJsonResult.errcode, industryJsonResult.errmsg);
                return(industryJsonResult);
            }
            if (((industryJsonResult.errcode == -1) || (industryJsonResult.primary_industry.ConvertToIndustryCode() != IndustryCode.IT科技_互联网_电子商务)) || (industryJsonResult.secondary_industry.ConvertToIndustryCode() != IndustryCode.IT科技_IT软件与服务))
            {
                WxJsonResult result3 = SetIndustry();
                if (result3.errcode != 0)
                {
                    result3.errmsg = GetErrorMsg(result3.errcode, result3.errmsg);
                    return(result3);
                }
            }
            Hidistro.Messages.GetPrivateTemplateJsonResult privateTemplateJsonResult = GetPrivateTemplateJsonResult(accessToken);
            if (privateTemplateJsonResult.errcode != 0)
            {
                privateTemplateJsonResult.errmsg = GetErrorMsg(privateTemplateJsonResult.errcode, privateTemplateJsonResult.errmsg);
                return(privateTemplateJsonResult);
            }
            List <GetPrivateTemplate_TemplateItem> source = privateTemplateJsonResult.template_list;
            List <WxtemplateId> wxtemplateIds             = GetWxtemplateIds();
            int count = source.Count;

            using (List <WxtemplateId> .Enumerator enumerator = wxtemplateIds.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    Func <GetPrivateTemplate_TemplateItem, bool> predicate = null;
                    WxtemplateId wxtempitem = enumerator.Current;
                    if (predicate == null)
                    {
                        predicate = t => (t.title == wxtempitem.name) && (t.primary_industry == "IT科技");
                    }
                    GetPrivateTemplate_TemplateItem item = source.FirstOrDefault <GetPrivateTemplate_TemplateItem>(predicate);
                    if (item != null)
                    {
                        wxtempitem.templateid = item.template_id;
                    }
                    else
                    {
                        if (count >= 0x19)
                        {
                            wxtempitem.templateid = "公众号已有模板数量越额了!";
                            continue;
                        }
                        Hidistro.Messages.AddtemplateJsonResult result5 = AddtemplateJsonResult(accessToken, wxtempitem.shortId);
                        if (result5.errcode != 0)
                        {
                            wxtempitem.templateid = result5.errmsg;
                            continue;
                        }
                        count++;
                        wxtempitem.templateid = result5.template_id;
                    }
                }
            }
            return(new WxJsonResult {
                errcode = 0, errmsg = "设置成功", AppendData = wxtemplateIds
            });
        }