新增「模板消息所处行业设置」「模板消息ID获取」接口
This commit is contained in:
parent
2f4e0ea076
commit
42f8491a39
@ -170,6 +170,10 @@ netty的代码没有放到maven中心仓库,也没什么意义,因为最终需
|
||||
|
||||
+ 重构了POM
|
||||
|
||||
* 2014-12-12
|
||||
|
||||
+ **weixin4j-mp**: 新增设置`模板消息所处行业`、`获取模板消息ID`接口
|
||||
|
||||
接下来
|
||||
------
|
||||
* 微信小店
|
||||
|
||||
@ -139,3 +139,7 @@ weixin4j-mp
|
||||
+ **weixin4j-mp-api**: 重新定义(手贱)了「被动消息」「客服消息」「群发消息」的传输实体
|
||||
|
||||
+ **weixin4j-mp-server**: `WeixinServerBootstrap`重命名为`WeixinMpServerBootstrap`
|
||||
|
||||
* 2014-12-12
|
||||
|
||||
+ **weixin4j-mp-api**: 新增设置`模板消息所处行业`、`获取模板消息ID`接口
|
||||
@ -120,3 +120,7 @@ weixin.properties说明
|
||||
* 2014-11-17
|
||||
|
||||
+ 新增`冲正`和`被扫支付`接口
|
||||
|
||||
* 2014-12-12
|
||||
|
||||
+ 新增设置`模板消息所处行业`、`获取模板消息ID`接口
|
||||
@ -39,6 +39,7 @@ import com.foxinmy.weixin4j.mp.payment.RefundResult;
|
||||
import com.foxinmy.weixin4j.mp.payment.v2.Order;
|
||||
import com.foxinmy.weixin4j.mp.type.BillType;
|
||||
import com.foxinmy.weixin4j.mp.type.IdQuery;
|
||||
import com.foxinmy.weixin4j.mp.type.IndustryType;
|
||||
import com.foxinmy.weixin4j.msg.model.Base;
|
||||
import com.foxinmy.weixin4j.msg.model.MpArticle;
|
||||
import com.foxinmy.weixin4j.msg.model.Video;
|
||||
@ -693,6 +694,40 @@ public class WeixinProxy {
|
||||
return qrApi.getQR(parameter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置所属行业(每月可修改行业1次,账号仅可使用所属行业中相关的模板)
|
||||
*
|
||||
* @param industryType
|
||||
* 所处行业 目前不超过两个
|
||||
* @return 操作结果
|
||||
* @throws WeixinException
|
||||
* @see com.foxinmy.weixin4j.mp.type.IndustryType
|
||||
* @see com.foxinmy.weixin4j.mp.api.TmplApi
|
||||
* @see <a href="http://mp.weixin.qq.com/wiki/17/304
|
||||
* c1885ea66dbedf7dc170d84999a9d
|
||||
* .html#.E8.AE.BE.E7.BD.AE.E6.89.80.E5.B1
|
||||
* .9E.E8.A1.8C.E4.B8.9A">设置所处行业</a>
|
||||
*/
|
||||
public JsonResult setTmplIndustry(IndustryType... industryType)
|
||||
throws WeixinException {
|
||||
return tmplApi.setTmplIndustry(industryType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模板ID
|
||||
*
|
||||
* @param shortId
|
||||
* 模板库中模板的编号,有“TM**”和“OPENTMTM**”等形式
|
||||
* @return 模板ID
|
||||
* @throws WeixinException
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/17/304c1885ea66dbedf7dc170d84999a9d.html#.E8.8E.B7.E5.BE.97.E6.A8.A1.E6.9D.BFID">获得模板ID</a>
|
||||
* @see com.foxinmy.weixin4j.mp.api.TmplApi
|
||||
*/
|
||||
public String getTemplateId(String shortId) throws WeixinException {
|
||||
return tmplApi.getTemplateId(shortId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送模板消息
|
||||
*
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
package com.foxinmy.weixin4j.mp.api;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.JsonResult;
|
||||
import com.foxinmy.weixin4j.http.Response;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.mp.message.TemplateMessage;
|
||||
import com.foxinmy.weixin4j.mp.type.IndustryType;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
|
||||
/**
|
||||
@ -25,10 +27,60 @@ public class TmplApi extends MpApi {
|
||||
this.tokenHolder = tokenHolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置所属行业(每月可修改行业1次,账号仅可使用所属行业中相关的模板)
|
||||
*
|
||||
* @param industryType
|
||||
* 所处行业 目前不超过两个
|
||||
* @return 操作结果
|
||||
* @throws WeixinException
|
||||
* @see com.foxinmy.weixin4j.mp.type.IndustryType
|
||||
* @see <a href="http://mp.weixin.qq.com/wiki/17/304
|
||||
* c1885ea66dbedf7dc170d84999a9d
|
||||
* .html#.E8.AE.BE.E7.BD.AE.E6.89.80.E5.B1
|
||||
* .9E.E8.A1.8C.E4.B8.9A">设置所处行业</a>
|
||||
*/
|
||||
public JsonResult setTmplIndustry(IndustryType... industryType)
|
||||
throws WeixinException {
|
||||
JSONObject obj = new JSONObject();
|
||||
for (int i = 0; i < industryType.length; i++) {
|
||||
obj.put(String.format("industry_id%d", i + 1),
|
||||
String.valueOf(industryType[i].getValue()));
|
||||
}
|
||||
Token token = tokenHolder.getToken();
|
||||
String template_set_industry_uri = getRequestUri("template_set_industry_uri");
|
||||
Response response = request.post(String.format(
|
||||
template_set_industry_uri, token.getAccessToken()), obj
|
||||
.toJSONString());
|
||||
|
||||
return response.getAsJsonResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模板ID
|
||||
*
|
||||
* @param shortId
|
||||
* 模板库中模板的编号,有“TM**”和“OPENTMTM**”等形式
|
||||
* @return 模板ID
|
||||
* @throws WeixinException
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/17/304c1885ea66dbedf7dc170d84999a9d.html#.E8.8E.B7.E5.BE.97.E6.A8.A1.E6.9D.BFID">获得模板ID</a>
|
||||
*/
|
||||
public String getTemplateId(String shortId) throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
String template_getid_uri = getRequestUri("template_getid_uri");
|
||||
Response response = request.post(
|
||||
String.format(template_getid_uri, token.getAccessToken()),
|
||||
String.format("{\"template_id_short\":\"%s\"}", shortId));
|
||||
|
||||
return response.getAsJson().getString("template_id");
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送模板消息
|
||||
*
|
||||
* @param message 消息对象
|
||||
* @param message
|
||||
* 消息对象
|
||||
* @return 发送结果
|
||||
* @throws WeixinException
|
||||
* @see <a
|
||||
@ -41,7 +93,8 @@ public class TmplApi extends MpApi {
|
||||
Token token = tokenHolder.getToken();
|
||||
String template_send_uri = getRequestUri("template_send_uri");
|
||||
Response response = request.post(
|
||||
String.format(template_send_uri, token.getAccessToken()), JSON.toJSONString(tplMessage));
|
||||
String.format(template_send_uri, token.getAccessToken()),
|
||||
JSON.toJSONString(tplMessage));
|
||||
|
||||
return response.getAsJsonResult();
|
||||
}
|
||||
|
||||
@ -72,7 +72,11 @@ shorturl_uri={api_cgi_url}/shorturl?access_token=%s
|
||||
p_shorturl_uri={mch_base_url}/tools/shorturl
|
||||
# \u8bbe\u7f6e\u5907\u6ce8\u540d
|
||||
updateremark_uri={api_cgi_url}/user/info/updateremark?access_token=%s
|
||||
# \u6a21\u677f\u6d88\u606f
|
||||
# \u8bbe\u7f6e\u6a21\u677f\u6d88\u606f\u6240\u5904\u884c\u4e1a
|
||||
template_set_industry_uri={api_cgi_url}/template/api_set_industry?access_token=%s
|
||||
# \u83b7\u53d6\u6a21\u677f\u6d88\u606fID
|
||||
template_getid_uri={api_cgi_url}/template/api_add_template?access_token=%s
|
||||
# \u53d1\u9001\u6a21\u677f\u6d88\u606f
|
||||
template_send_uri={api_cgi_url}/message/template/send?access_token=%s
|
||||
# \u8bed\u4e49\u7406\u89e3
|
||||
semantic_uri={api_base_url}/semantic/semproxy/search?access_token=%s
|
||||
|
||||
@ -0,0 +1,59 @@
|
||||
package com.foxinmy.weixin4j.mp.type;
|
||||
|
||||
/**
|
||||
* 模板消息所用到的行业信息
|
||||
*
|
||||
* @className IndustryType
|
||||
* @author jy
|
||||
* @date 2014年12月12日
|
||||
* @since JDK 1.7
|
||||
* @see<a href=
|
||||
* "http://mp.weixin.qq.com/wiki/17/304c1885ea66dbedf7dc170d84999a9d.html#.E8.AE.BE.E7.BD.AE.E6.89.80.E5.B1.9E.E8.A1.8C.E4.B8.9A"
|
||||
* >所处行业</a>
|
||||
*/
|
||||
public enum IndustryType {
|
||||
ITKEJI_HULIANWANG$DIANZISHANGWU("IT科技", "互联网/电子商务", 1), ITKEJI_ITRUANJIANYUFUWU(
|
||||
"IT科技", "IT软件与服务", 2), ITKEJI_ITYINGJIANYUSHEBEI("IT科技", "IT硬件与设备",
|
||||
3), ITKEJI_DIANZIJISHU("IT科技", "电子技术", 4), ITKEJI_TONGXINYUYUNYINGSHANG(
|
||||
"IT科技", "通信与运营商", 5), ITKEJI_WANGLUOYOUXI("IT科技", "网络游戏", 6), JINRONGYE_YINXING(
|
||||
"金融业", "银行", 7), JINRONGYE_JIJIN$LICAI$XINTUO("金融业", "基金|理财|信托", 8), JINRONGYE_BAOXIAN(
|
||||
"金融业", "保险", 9), CANYIN_CANYIN("餐饮", "餐饮", 10), JIUDIANLUYOU_JIUDIAN(
|
||||
"酒店旅游", "酒店", 11), JIUDIANLUYOU_LUYOU("酒店旅游", "旅游", 12), YUNSHUYUCANGCHU_KUAIDI(
|
||||
"运输与仓储", "快递", 13), YUNSHUYUCANGCHU_WULIU("运输与仓储", "物流", 14), YUNSHUYUCANGCHU_CANGCHU(
|
||||
"运输与仓储", "仓储", 15), JIAOYU_PEIXUN("教育", "培训", 16), JIAOYU_YUANXIAO(
|
||||
"教育", "院校", 17), ZHENGFUYUGONGGONGSHIYE_XUESHUKEYAN("政府与公共事业",
|
||||
"学术科研", 18), ZHENGFUYUGONGGONGSHIYE_JIAOJING("政府与公共事业", "交警", 19), ZHENGFUYUGONGGONGSHIYE_BOWUGUAN(
|
||||
"政府与公共事业", "博物馆", 20), ZHENGFUYUGONGGONGSHIYE_GONGGONGSHIYE$FEIYINGLIJIGOU(
|
||||
"政府与公共事业", "公共事业|非盈利机构", 21), YIYAOHULI_YIYAOYILIAO("医药护理", "医药医疗",
|
||||
22), YIYAOHULI_HULIMEIRONG("医药护理", "护理美容", 23), YIYAOHULI_BAOJIANYUWEISHENG(
|
||||
"医药护理", "保健与卫生", 24), JIAOTONGGONGJU_QICHEXIANGGUAN("交通工具", "汽车相关",
|
||||
25), JIAOTONGGONGJU_MOTUOCHEXIANGGUAN("交通工具", "摩托车相关", 26), JIAOTONGGONGJU_HUOCHEXIANGGUAN(
|
||||
"交通工具", "火车相关", 27), JIAOTONGGONGJU_FEIJIXIANGGUAN("交通工具", "飞机相关",
|
||||
28), FANGDICHAN_JIANZHU("房地产", "建筑", 29), FANGDICHAN_WUYE("房地产",
|
||||
"物业", 30), XIAOFEIPIN_XIAOFEIPIN("消费品", "消费品", 31), SHANGYEFUWU_FALU(
|
||||
"商业服务", "法律", 32), SHANGYEFUWU_HUIZHAN("商业服务", "会展", 33), SHANGYEFUWU_ZHONGJIEFUWU(
|
||||
"商业服务", "中介服务", 34), SHANGYEFUWU_RENZHENG("商业服务", "认证", 35), SHANGYEFUWU_SHENJI(
|
||||
"商业服务", "审计", 36), WENTIYULE_CHUANMEI("文体娱乐", "传媒", 37), WENTIYULE_TIYU(
|
||||
"文体娱乐", "体育", 38), WENTIYULE_YULEXIUXIAN("文体娱乐", "娱乐休闲", 39), YINSHUA_YINSHUA(
|
||||
"印刷", "印刷", 40), QITA_QITA("其它", "其它", 41);
|
||||
private String main;
|
||||
private String sub;
|
||||
private int value;
|
||||
|
||||
IndustryType(String main, String sub, int value) {
|
||||
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getMain() {
|
||||
return main;
|
||||
}
|
||||
|
||||
public String getSub() {
|
||||
return sub;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@ -9,6 +9,7 @@ import com.foxinmy.weixin4j.http.JsonResult;
|
||||
import com.foxinmy.weixin4j.mp.api.TmplApi;
|
||||
import com.foxinmy.weixin4j.mp.message.TemplateMessage;
|
||||
import com.foxinmy.weixin4j.mp.test.TokenTest;
|
||||
import com.foxinmy.weixin4j.mp.type.IndustryType;
|
||||
|
||||
public class TemplateMsgTest extends TokenTest {
|
||||
private TmplApi tmplApi;
|
||||
@ -18,6 +19,17 @@ public class TemplateMsgTest extends TokenTest {
|
||||
this.tmplApi = new TmplApi(tokenHolder);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setIndustry() throws WeixinException {
|
||||
System.out.println(tmplApi
|
||||
.setTmplIndustry(IndustryType.ITKEJI_DIANZIJISHU));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getid() throws WeixinException {
|
||||
System.out.println(tmplApi.getTemplateId("OPENTM201490080"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() throws WeixinException {
|
||||
TemplateMessage tplMessage = new TemplateMessage("touser",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user