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 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 DelPrivateTemplate(string template_id)
        {
            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/del_private_template?access_token={0}";
            var    data      = new
            {
                template_id
            };
            WxJsonResult 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));
        }
Example #6
0
        public static WxTemplateMessageResult SendTemplateMessage(string accessTocken, TempleteModel TempleteModel)
        {
            string urlFormat = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={0}";

            return(WxTemplateHelp.WxCommonSend <WxTemplateMessageResult>(accessTocken, urlFormat, TempleteModel, CommonJsonSendType.POST));
        }
        private static GetIndustryJsonResult GetIndustryJsonResult(string accessToken)
        {
            string urlFormat = "https://api.weixin.qq.com/cgi-bin/template/get_industry?access_token={0}";

            return(WxTemplateHelp.WxCommonSend <GetIndustryJsonResult>(accessToken, urlFormat, null, CommonJsonSendType.GET));
        }