diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java index 0fc8ad91..223893e1 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java @@ -965,4 +965,27 @@ public interface WxMpService { * @throws WxErrorException */ public WxMediaImgUploadResult mediaImgUpload(File file) throws WxErrorException; + + /* + *
+ * 设置所属行业 + * 官方文档中暂未告知响应内容 + * 详情请见:http://mp.weixin.qq.com/wiki/5/6dde9eaa909f83354e0094dc3ad99e05.html#.E8.AE.BE.E7.BD.AE.E6.89.80.E5.B1.9E.E8.A1.8C.E4.B8.9A + *+ * @param wxMpIndustry + * @return JsonObject + * @throws WxErrorException + */ + String setIndustry(WxMpIndustry wxMpIndustry) throws WxErrorException; + + /*** + *
+ * 获取设置的行业信息 + * 详情请见:http://mp.weixin.qq.com/wiki/5/6dde9eaa909f83354e0094dc3ad99e05.html#.E8.AE.BE.E7.BD.AE.E6.89.80.E5.B1.9E.E8.A1.8C.E4.B8.9A + *+ * + * @return wxMpIndustry + * @throws WxErrorException + */ + WxMpIndustry getIndustry() throws WxErrorException; } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java index 00ca446c..d20e5c5f 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java @@ -1294,4 +1294,20 @@ public class WxMpServiceImpl implements WxMpService { return execute(new MediaImgUploadRequestExecutor(), url, file); } + @Override + public String setIndustry(WxMpIndustry wxMpIndustry) throws WxErrorException { + if (null == wxMpIndustry.getPrimaryIndustry() || null == wxMpIndustry.getPrimaryIndustry().getId() + || null == wxMpIndustry.getSecondIndustry() || null == wxMpIndustry.getSecondIndustry().getId()) { + throw new IllegalArgumentException("industry id is empty"); + } + String url = "https://api.weixin.qq.com/cgi-bin/template/api_set_industry"; + return execute(new SimplePostRequestExecutor(), url, wxMpIndustry.toJson()); + } + + @Override + public WxMpIndustry getIndustry() throws WxErrorException { + String url = "https://api.weixin.qq.com/cgi-bin/template/get_industry"; + String responseContent = execute(new SimpleGetRequestExecutor(), url, null); + return WxMpIndustry.fromJson(responseContent); + } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/Industry.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/Industry.java new file mode 100644 index 00000000..1270e7f5 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/Industry.java @@ -0,0 +1,38 @@ +package me.chanjar.weixin.mp.bean; + +import java.io.Serializable; + +/** + * @author miller + * 官方文档中,创建和获取的数据结构不一样。所以采用冗余字段的方式,实现相应的接口 + */ +public class Industry implements Serializable { + private static final long serialVersionUID = -1707184885588012142L; + private String id; + private String firstClass; + private String secondClass; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getFirstClass() { + return firstClass; + } + + public void setFirstClass(String firstClass) { + this.firstClass = firstClass; + } + + public String getSecondClass() { + return secondClass; + } + + public void setSecondClass(String secondClass) { + this.secondClass = secondClass; + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpIndustry.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpIndustry.java new file mode 100644 index 00000000..be62084d --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpIndustry.java @@ -0,0 +1,39 @@ +package me.chanjar.weixin.mp.bean; + + +import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; + +import java.io.Serializable; + +/** + * @author miller + */ +public class WxMpIndustry implements Serializable { + private static final long serialVersionUID = -7700398224795914722L; + private Industry primaryIndustry; + private Industry secondIndustry; + + public static WxMpIndustry fromJson(String json) { + return WxMpGsonBuilder.create().fromJson(json, WxMpIndustry.class); + } + + public String toJson() { + return WxMpGsonBuilder.create().toJson(this); + } + + public Industry getPrimaryIndustry() { + return primaryIndustry; + } + + public void setPrimaryIndustry(Industry primaryIndustry) { + this.primaryIndustry = primaryIndustry; + } + + public Industry getSecondIndustry() { + return secondIndustry; + } + + public void setSecondIndustry(Industry secondIndustry) { + this.secondIndustry = secondIndustry; + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpGsonBuilder.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpGsonBuilder.java index a451673d..34570b30 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpGsonBuilder.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpGsonBuilder.java @@ -42,6 +42,7 @@ public class WxMpGsonBuilder { INSTANCE.registerTypeAdapter(WxMpCard.class, new WxMpCardGsonAdapter()); INSTANCE.registerTypeAdapter(WxMpMassPreviewMessage.class, new WxMpMassPreviewMessageGsonAdapter()); INSTANCE.registerTypeAdapter(WxMediaImgUploadResult.class, new WxMediaImgUploadResultGsonAdapter()); + INSTANCE.registerTypeAdapter(WxMpIndustry.class, new WxMpIndustryGsonAdapter()); } public static Gson create() { diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpIndustryGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpIndustryGsonAdapter.java new file mode 100644 index 00000000..79fb5f0b --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpIndustryGsonAdapter.java @@ -0,0 +1,44 @@ +package me.chanjar.weixin.mp.util.json; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import me.chanjar.weixin.common.util.json.GsonHelper; +import me.chanjar.weixin.mp.bean.Industry; +import me.chanjar.weixin.mp.bean.WxMpIndustry; + +import java.lang.reflect.Type; + +/** + * @author miller + */ +public class WxMpIndustryGsonAdapter implements JsonSerializer