Skip to content

Commit 159347e

Browse files
committed
🎨 #1233 公众号模板消息设置行业信息接口优化,增加枚举类 WxMpTemplateIndustryEnum 方便使用
1 parent 48586de commit 159347e

File tree

6 files changed

+267
-57
lines changed

6 files changed

+267
-57
lines changed

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpTemplateMsgService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ public interface WxMpTemplateMsgService {
2424
* 详情请见:http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277&token=&lang=zh_CN
2525
* </pre>
2626
*
27+
* @param wxMpIndustry 行业信息
2728
* @return 是否成功
29+
* @throws WxErrorException .
2830
*/
2931
boolean setIndustry(WxMpTemplateIndustry wxMpIndustry) throws WxErrorException;
3032

@@ -35,6 +37,7 @@ public interface WxMpTemplateMsgService {
3537
* </pre>
3638
*
3739
* @return wxMpIndustry
40+
* @throws WxErrorException .
3841
*/
3942
WxMpTemplateIndustry getIndustry() throws WxErrorException;
4043

@@ -44,7 +47,9 @@ public interface WxMpTemplateMsgService {
4447
* 详情请见: http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277&token=&lang=zh_CN
4548
* </pre>
4649
*
50+
* @param templateMessage 模板消息
4751
* @return 消息Id
52+
* @throws WxErrorException .
4853
*/
4954
String sendTemplateMsg(WxMpTemplateMessage templateMessage) throws WxErrorException;
5055

@@ -58,6 +63,7 @@ public interface WxMpTemplateMsgService {
5863
*
5964
* @param shortTemplateId 模板库中模板的编号,有“TM**”和“OPENTMTM**”等形式
6065
* @return templateId 模板Id
66+
* @throws WxErrorException .
6167
*/
6268
String addTemplate(String shortTemplateId) throws WxErrorException;
6369

@@ -70,6 +76,7 @@ public interface WxMpTemplateMsgService {
7076
* </pre>
7177
*
7278
* @return templateId 模板Id
79+
* @throws WxErrorException .
7380
*/
7481
List<WxMpTemplate> getAllPrivateTemplate() throws WxErrorException;
7582

@@ -82,6 +89,8 @@ public interface WxMpTemplateMsgService {
8289
* </pre>
8390
*
8491
* @param templateId 模板Id
92+
* @return .
93+
* @throws WxErrorException .
8594
*/
8695
boolean delPrivateTemplate(String templateId) throws WxErrorException;
8796
}

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public String sendTemplateMsg(WxMpTemplateMessage templateMessage) throws WxErro
4242

4343
@Override
4444
public boolean setIndustry(WxMpTemplateIndustry wxMpIndustry) throws WxErrorException {
45-
if (null == wxMpIndustry.getPrimaryIndustry() || null == wxMpIndustry.getPrimaryIndustry().getId()
46-
|| null == wxMpIndustry.getSecondIndustry() || null == wxMpIndustry.getSecondIndustry().getId()) {
45+
if (null == wxMpIndustry.getPrimaryIndustry() || null == wxMpIndustry.getPrimaryIndustry().getCode()
46+
|| null == wxMpIndustry.getSecondIndustry() || null == wxMpIndustry.getSecondIndustry().getCode()) {
4747
throw new IllegalArgumentException("行业Id不能为空,请核实");
4848
}
4949

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
package me.chanjar.weixin.mp.bean.template;
22

33

4-
import java.io.Serializable;
5-
4+
import lombok.AllArgsConstructor;
65
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
import lombok.experimental.Accessors;
78
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
89

10+
import java.io.Serializable;
11+
912
/**
1013
* @author miller
1114
*/
1215
@Data
16+
@NoArgsConstructor
17+
@AllArgsConstructor
18+
@Accessors(chain = true)
1319
public class WxMpTemplateIndustry implements Serializable {
1420
private static final long serialVersionUID = -7700398224795914722L;
1521

16-
private Industry primaryIndustry;
17-
private Industry secondIndustry;
18-
19-
public WxMpTemplateIndustry() {
20-
}
21-
22-
public WxMpTemplateIndustry(Industry primaryIndustry, Industry secondIndustry) {
23-
this.primaryIndustry = primaryIndustry;
24-
this.secondIndustry = secondIndustry;
25-
}
22+
private WxMpTemplateIndustryEnum primaryIndustry;
23+
private WxMpTemplateIndustryEnum secondIndustry;
2624

2725
public static WxMpTemplateIndustry fromJson(String json) {
2826
return WxMpGsonBuilder.create().fromJson(json, WxMpTemplateIndustry.class);
@@ -41,29 +39,22 @@ public String toJson() {
4139
* 官方文档中,创建和获取的数据结构不一样。所以采用冗余字段的方式,实现相应的接口.
4240
*/
4341
@Data
42+
@NoArgsConstructor
43+
@AllArgsConstructor
44+
@Accessors(chain = true)
4445
public static class Industry implements Serializable {
4546
private static final long serialVersionUID = -1707184885588012142L;
4647
private String id;
4748
private String firstClass;
4849
private String secondClass;
4950

50-
public Industry() {
51-
}
52-
5351
public Industry(String id) {
5452
this.id = id;
5553
}
5654

57-
public Industry(String id, String firstClass, String secondClass) {
58-
this.id = id;
59-
this.firstClass = firstClass;
60-
this.secondClass = secondClass;
61-
}
62-
6355
@Override
6456
public String toString() {
6557
return WxMpGsonBuilder.create().toJson(this);
6658
}
67-
6859
}
6960
}
Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
package me.chanjar.weixin.mp.bean.template;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Getter;
5+
6+
/**
7+
* 模版消息行业枚举.
8+
*
9+
* @author <a href="https://github.com/binarywang">Binary Wang</a>
10+
* @date 2019-10-18
11+
*/
12+
@Getter
13+
@AllArgsConstructor
14+
public enum WxMpTemplateIndustryEnum {
15+
/**
16+
* IT科技 - 互联网|电子商务
17+
*/
18+
E_COMMERCE("IT科技", "互联网|电子商务", 1),
19+
/**
20+
* IT科技 - IT软件与服务
21+
*/
22+
IT_SOFTWARE_AND_SERVICES("IT科技", "IT软件与服务", 2),
23+
/**
24+
* IT科技 - IT硬件与设备
25+
*/
26+
IT_HARDWARE_AND_EQUIPMENT("IT科技", "IT硬件与设备", 3),
27+
/**
28+
* IT科技 - 电子技术
29+
*/
30+
ELECTRONIC_TECHNIQUE("IT科技", "电子技术", 4),
31+
/**
32+
* IT科技 - 通信与运营商
33+
*/
34+
COMMUNICATION_AND_OPERATOR("IT科技", "通信与运营商", 5),
35+
/**
36+
* IT科技 - 网络游戏
37+
*/
38+
ONLINE_GAME("IT科技", "网络游戏", 6),
39+
/**
40+
* 金融业 - 银行
41+
*/
42+
BANK("金融业", "银行", 7),
43+
/**
44+
* 金融业 - 基金|理财|信托
45+
*/
46+
FUND("金融业", "基金|理财|信托", 8),
47+
/**
48+
* 金融业 - 保险
49+
*/
50+
INSURANCE("金融业", "保险", 9),
51+
/**
52+
* 餐饮 - 餐饮
53+
*/
54+
REPAST("餐饮", "餐饮", 10),
55+
/**
56+
* 酒店旅游 - 酒店
57+
*/
58+
HOTEL("酒店旅游", "酒店", 11),
59+
/**
60+
* 酒店旅游 - 旅游
61+
*/
62+
TRAVEL("酒店旅游", "旅游", 12),
63+
/**
64+
* 运输与仓储 - 快递
65+
*/
66+
EXPRESS("运输与仓储", "快递", 13),
67+
/**
68+
* 运输与仓储 - 物流
69+
*/
70+
LOGISTICS("运输与仓储", "物流", 14),
71+
/**
72+
* 运输与仓储 - 仓储
73+
*/
74+
STORAGE("运输与仓储", "仓储", 15),
75+
/**
76+
* 教育 - 培训
77+
*/
78+
CULTIVATE("教育", "培训", 16),
79+
/**
80+
* 教育 - 院校
81+
*/
82+
ACADEMY("教育", "院校", 17),
83+
/**
84+
* 政府与公共事业 - 学术科研
85+
*/
86+
ACADEMIC_RESEARCH("政府与公共事业", "学术科研", 18),
87+
/**
88+
* 政府与公共事业 - 交警
89+
*/
90+
TRAFFIC_POLICE("政府与公共事业", "交警", 19),
91+
/**
92+
* 政府与公共事业 - 博物馆
93+
*/
94+
MUSEUM("政府与公共事业", "博物馆", 20),
95+
/**
96+
* 政府与公共事业 - 公共事业|非盈利机构
97+
*/
98+
PUBLIC_WORKS_NONPROFIT("政府与公共事业", "公共事业|非盈利机构", 21),
99+
/**
100+
* 医药护理 - 医药医疗
101+
*/
102+
MEDICAL_HEALTH("医药护理", "医药医疗", 22),
103+
/**
104+
* 医药护理 - 护理美容
105+
*/
106+
CARE_AND_BEAUTY("医药护理", "护理美容", 23),
107+
/**
108+
* 医药护理 - 保健与卫生
109+
*/
110+
HEALTH_AND_HYGIENE("医药护理", "保健与卫生", 24),
111+
/**
112+
* 交通工具 - 汽车相关
113+
*/
114+
AUTOMOTIVE_RELATED("交通工具", "汽车相关", 25),
115+
/**
116+
* 交通工具 - 摩托车相关
117+
*/
118+
MOTORCYCLE_CORRELATION("交通工具", "摩托车相关", 26),
119+
/**
120+
* 交通工具 - 火车相关
121+
*/
122+
THE_TRAIN_RELATED("交通工具", "火车相关", 27),
123+
/**
124+
* 交通工具 - 飞机相关
125+
*/
126+
THE_PLANE_RELATED("交通工具", "飞机相关", 28),
127+
/**
128+
* 房地产 - 建筑
129+
*/
130+
ARCHITECTURE("房地产", "建筑", 29),
131+
/**
132+
* 房地产 - 物业
133+
*/
134+
REAL_ESTATE("房地产", "物业", 30),
135+
/**
136+
* 消费品 - 消费品
137+
*/
138+
CONSUMER_GOODS("消费品", "消费品", 31),
139+
/**
140+
* 商业服务 - 法律
141+
*/
142+
LEGISLATION("商业服务", "法律", 32),
143+
/**
144+
* 商业服务 - 会展
145+
*/
146+
CONVENTION_AND_EXHIBITION("商业服务", "会展", 33),
147+
/**
148+
* 商业服务 - 中介服务
149+
*/
150+
INTERMEDIARY_SERVICES("商业服务", "中介服务", 34),
151+
/**
152+
* 商业服务 - 认证
153+
*/
154+
AUTHENTICATION("商业服务", "认证", 35),
155+
/**
156+
* 商业服务 - 会计|审计
157+
*/
158+
AUDIT("商业服务", "会计|审计", 36),
159+
/**
160+
* 文体娱乐 - 传媒
161+
*/
162+
MASS_MEDIA("文体娱乐", "传媒", 37),
163+
/**
164+
* 文体娱乐 - 体育
165+
*/
166+
SPORTS("文体娱乐", "体育", 38),
167+
/**
168+
* 文体娱乐 - 娱乐休闲
169+
*/
170+
LEISURE_AND_ENTERTAINMENT("文体娱乐", "娱乐休闲", 39),
171+
/**
172+
* 印刷 - 印刷
173+
*/
174+
PRINTING("印刷", "印刷", 40),
175+
/**
176+
* 其它 - 其它
177+
*/
178+
OTHER("其它", "其它", 41);
179+
180+
/**
181+
* 主行业(一级行业)
182+
*/
183+
public final String firstClass;
184+
/**
185+
* 副行业(二级行业)
186+
*/
187+
public final String secondClass;
188+
/**
189+
* 行业代码
190+
*/
191+
public final Integer code;
192+
193+
/**
194+
* 查找行业
195+
*
196+
* @param industry 二级行业名称
197+
* @return .
198+
*/
199+
public static WxMpTemplateIndustryEnum findBySecondary(String industry) {
200+
for (WxMpTemplateIndustryEnum industryEnum : WxMpTemplateIndustryEnum.values()) {
201+
if (industryEnum.secondClass.equals(industry)) {
202+
return industryEnum;
203+
}
204+
}
205+
206+
return null;
207+
}
208+
209+
/**
210+
* 查找行业
211+
*
212+
* @param code 行业编码
213+
* @return .
214+
*/
215+
public static WxMpTemplateIndustryEnum findByCode(int code) {
216+
for (WxMpTemplateIndustryEnum industryEnum : WxMpTemplateIndustryEnum.values()) {
217+
if (industryEnum.code == code) {
218+
return industryEnum;
219+
}
220+
}
221+
222+
return null;
223+
}
224+
}

0 commit comments

Comments
 (0)