设置公众号模板消息所属行业
模板消息仅用于公众号向用户发送重要的服务通知,只能用于符合要求的服务场景中,如信用卡刷卡通知、商品购买成功通知等。不支持广告等营销类消息,以及其他所有可能对用户造成骚扰的消息。
文档地址:
https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277
设置所属行业
设置行业可以在微信公众平台后台完成,每月可修改行业 1 次。帐号只能使用所属行业中相关的模板。为方便第三方开发者,微信也提供通过接口调用修改账号所属行业的方式。
接口调用请求说明:
HTTP 请求方式:POST
https://api.weixin.qq.com/cgi-bin/template/api_set_industry?access_token=ACCESS_TOKEN
POST 数据示例:
{
"industry_id1": "1",
"industry_id2": "4"
}Code language: JSON / JSON with Comments (json)
参数说明:
| 参数 | 是否必须 | 说明 |
|---|---|---|
| access_token | 是 | 接口调用凭证 |
| industry_id1 | 是 | 公众号模板消息所属行业编号 |
| industry_id2 | 是 | 公众号模板消息所属行业编号 |
说白了,不同行业有不同的模板格式,需要通过接口设置公众号所属行业。具体行业代码可参考上面的文档地址。
Handler 实现
public class ApiSetIndustryHandler : WeiXinHandlerBase, IWeiXinHandler
{
private string url = "https://api.weixin.qq.com/cgi-bin/template/api_set_industry?access_token={0}";
public T DoGet<T>(params string[] param) where T : class
{
throw new NotImplementedException();
}
public T DoPost<T>(params string[] param) where T : class
{
var para = new
{
industry_id1 = "1",
industry_id2 = "10"
};
var json = JsonHelper.SerializeObject(para);
url = string.Format(url, accessTokenInfo.access_token);
var content = HtmlHelper.HttpPost(url, json);
return JsonHelper.DeserializeJsonToObject<T>(content);
}
}Code language: HTML, XML (xml)
控制器中调用
public ActionResult ApiSetIndustry()
{
var result = new ApiSetIndustryHandler().DoPost<dynamic>();
return Json(result);
}Code language: PHP (php)
访问测试
http://xxxxx.imwork.net/home/ApiSetIndustry
返回:
{"errcode":43100,"errmsg":"change template too frequently hint: [kLqX706961961]"}Code language: JSON / JSON with Comments (json)
原因是:公众号所属行业一个月只能设置一次。
Previous: 11-关注或者取消关注事件-发送欢迎消息
Next: 13-获取模板列表