From 9c91aeba6e34a4c1bf7e89bfa9c87d2a497cd725 Mon Sep 17 00:00:00 2001 From: Binary Wang <binarywang@gmail.com> Date: Wed, 7 Oct 2020 20:00:59 +0800 Subject: [PATCH] =?UTF-8?q?:new:=20#1686=20=E5=BE=AE=E4=BF=A1=E5=85=AC?= =?UTF-8?q?=E4=BC=97=E5=8F=B7=E5=A2=9E=E5=8A=A0=E5=AF=B9=E8=AF=9D=E8=83=BD?= =?UTF-8?q?=E5=8A=9B=EF=BC=88=E5=8E=9F=E5=AF=BC=E8=B4=AD=E5=8A=A9=E6=89=8B?= =?UTF-8?q?=EF=BC=89=E9=83=A8=E5=88=86=E6=8E=A5=E5=8F=A3=EF=BC=8C=E5=A6=82?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A1=BE=E9=97=AE=E3=80=81=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E9=A1=BE=E9=97=AE=E3=80=81=E8=8E=B7=E5=8F=96=E9=A1=BE=E9=97=AE?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/api/WxMpGuideService.java | 42 +++++++++++++++++++ .../mp/api/impl/WxMpGuideServiceImpl.java | 23 ++++++++++ .../weixin/mp/bean/guide/WxMpGuideList.java | 34 +++++++++++++++ .../mp/bean/message/WxMpXmlMessage.java | 2 +- .../mp/constant/WxMpEventConstants.java | 10 +++++ .../chanjar/weixin/mp/enums/WxMpApiUrl.java | 15 ++++++- .../mp/api/impl/WxMpGuideServiceImplTest.java | 23 ++++++++-- 7 files changed, 143 insertions(+), 6 deletions(-) create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/guide/WxMpGuideList.java diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpGuideService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpGuideService.java index 372589c82..e1427dbb6 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpGuideService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpGuideService.java @@ -2,6 +2,7 @@ package me.chanjar.weixin.mp.api; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.bean.guide.WxMpGuideInfo; +import me.chanjar.weixin.mp.bean.guide.WxMpGuideList; /** * 微信导购助手(现在叫对话能力)接口. @@ -37,6 +38,18 @@ public interface WxMpGuideService { */ void addGuide(WxMpGuideInfo guideInfo) throws WxErrorException; + /** + * 修改顾问的昵称或头像 + * <pre> + * 请求地址: POST https://api.weixin.qq.com/cgi-bin/guide/updateguideacct?access_token=ACCESS_TOKEN + * 文档地址:https://developers.weixin.qq.com/doc/offiaccount/Shopping_Guide/guide-account/shopping-guide.updateGuideAcct.html + * </pre> + * + * @param guideInfo 顾问信息 + * @throws WxErrorException . + */ + void updateGuide(WxMpGuideInfo guideInfo) throws WxErrorException; + /** * 获取顾问信息 * @@ -51,4 +64,33 @@ public interface WxMpGuideService { * @throws WxErrorException . */ WxMpGuideInfo getGuide(String account, String openid) throws WxErrorException; + + /** + * 删除顾问 + * + * <pre> + * 请求地址: POST https://api.weixin.qq.com/cgi-bin/guide/delguideacct?access_token=ACCESS_TOKEN + * 文档地址:https://developers.weixin.qq.com/doc/offiaccount/Shopping_Guide/guide-account/shopping-guide.delGuideAcct.html + * </pre> + * + * @param account 顾问微信号(guide_account和guide_openid二选一,若同时请求,默认为guide_account) + * @param openid 顾问openid或者unionid(guide_account和guide_openid二选一) + * @throws WxErrorException . + */ + void delGuide(String account, String openid) throws WxErrorException; + + /** + * 获取服务号顾问列表 + * + * <pre> + * 请求地址: POST https://api.weixin.qq.com/cgi-bin/guide/getguideacctlist?access_token=ACCESS_TOKEN + * 文档地址:https://developers.weixin.qq.com/doc/offiaccount/Shopping_Guide/guide-account/shopping-guide.getGuideAcctList.html + * </pre> + * + * @param page 分页页数,从0开始 + * @param num 每页数量 + * @return 顾问信息列表 + * @throws WxErrorException . + */ + WxMpGuideList listGuide(int page, int num) throws WxErrorException; } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpGuideServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpGuideServiceImpl.java index 6e6f71a7c..51513fbfe 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpGuideServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpGuideServiceImpl.java @@ -6,6 +6,7 @@ import me.chanjar.weixin.common.util.json.GsonHelper; import me.chanjar.weixin.mp.api.WxMpGuideService; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.bean.guide.WxMpGuideInfo; +import me.chanjar.weixin.mp.bean.guide.WxMpGuideList; import me.chanjar.weixin.mp.enums.WxMpApiUrl; /** @@ -35,9 +36,31 @@ public class WxMpGuideServiceImpl implements WxMpGuideService { OPENID, guideInfo.getOpenid())); } + @Override + public void updateGuide(WxMpGuideInfo guideInfo) throws WxErrorException { + this.mpService.post(WxMpApiUrl.Guide.UPDATE_GUIDE, + GsonHelper.buildJsonObject(ACCOUNT, guideInfo.getAccount(), + "guide_headimgurl", guideInfo.getHeadImgUrl(), + "guide_nickname", guideInfo.getNickName(), + OPENID, guideInfo.getOpenid())); + + } + @Override public WxMpGuideInfo getGuide(String account, String openid) throws WxErrorException { return WxMpGuideInfo.fromJson(this.mpService.post(WxMpApiUrl.Guide.GET_GUIDE, GsonHelper.buildJsonObject(ACCOUNT, account, OPENID, openid))); } + + @Override + public void delGuide(String account, String openid) throws WxErrorException { + this.mpService.post(WxMpApiUrl.Guide.DEL_GUIDE, + GsonHelper.buildJsonObject(ACCOUNT, account, OPENID, openid)); + } + + @Override + public WxMpGuideList listGuide(int page, int num) throws WxErrorException { + return WxMpGuideList.fromJson(this.mpService.post(WxMpApiUrl.Guide.LIST_GUIDE, + GsonHelper.buildJsonObject("page", page, "num", num))); + } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/guide/WxMpGuideList.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/guide/WxMpGuideList.java new file mode 100644 index 000000000..e550c3460 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/guide/WxMpGuideList.java @@ -0,0 +1,34 @@ +package me.chanjar.weixin.mp.bean.guide; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import me.chanjar.weixin.common.util.json.WxGsonBuilder; + +import java.io.Serializable; +import java.util.List; + +/** + * 顾问列表. + * + * @author <a href="https://github.com/binarywang">Binary Wang</a> + * @date 2020-10-07 + */ +@Data +public class WxMpGuideList implements Serializable { + private static final long serialVersionUID = 144044550239346216L; + + /** + * 顾问总数量 + */ + @SerializedName("total_num") + private Integer totalNum; + + /** + * 顾问列表 + */ + private List<WxMpGuideInfo> list; + + public static WxMpGuideList fromJson(String json) { + return WxGsonBuilder.create().fromJson(json, WxMpGuideList.class); + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessage.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessage.java index adee564f9..43d6a47bd 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessage.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessage.java @@ -569,7 +569,7 @@ public class WxMpXmlMessage implements Serializable { * 审核成功时的时间(整形),时间戳 */ @XStreamAlias("SuccTime") - private Long succTime; + private Long successTime; /** * 审核失败的原因 diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/constant/WxMpEventConstants.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/constant/WxMpEventConstants.java index 4d7ef4beb..b2e984b0f 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/constant/WxMpEventConstants.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/constant/WxMpEventConstants.java @@ -141,4 +141,14 @@ public class WxMpEventConstants { public static final String CLOUD_INVOICE_INVOICERESULT_EVENT = "cloud_invoice_invoiceresult_event"; } + /** + * 对话助手相关事件 + */ + public static class Guide { + /** + * 顾问邀请结果通知事件. + */ + public static final String GUIDE_INVITE_RESULT_EVENT = "guide_invite_result_event"; + + } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/enums/WxMpApiUrl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/enums/WxMpApiUrl.java index 9a5c9a965..368814b44 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/enums/WxMpApiUrl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/enums/WxMpApiUrl.java @@ -1166,11 +1166,22 @@ public interface WxMpApiUrl { * 添加顾问 */ ADD_GUIDE(API_DEFAULT_HOST_URL, "/cgi-bin/guide/addguideacct"), - + /** + * 修改顾问 + */ + UPDATE_GUIDE(API_DEFAULT_HOST_URL, "/cgi-bin/guide/updateguideacct"), /** * 获取顾问信息 */ - GET_GUIDE(API_DEFAULT_HOST_URL, "/cgi-bin/guide/getguideacct"); + GET_GUIDE(API_DEFAULT_HOST_URL, "/cgi-bin/guide/getguideacct"), + /** + * 删除顾问 + */ + DEL_GUIDE(API_DEFAULT_HOST_URL, "/cgi-bin/guide/delguideacct"), + /** + * 获取服务号顾问列表 + */ + LIST_GUIDE(API_DEFAULT_HOST_URL, "/cgi-bin/guide/getguideacctlist"); private final String prefix; private final String path; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpGuideServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpGuideServiceImplTest.java index 28b28caef..5742191f9 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpGuideServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpGuideServiceImplTest.java @@ -5,6 +5,7 @@ import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.test.ApiTestModule; import me.chanjar.weixin.mp.bean.guide.WxMpGuideInfo; +import me.chanjar.weixin.mp.bean.guide.WxMpGuideList; import org.testng.annotations.Guice; import org.testng.annotations.Test; @@ -23,17 +24,33 @@ public class WxMpGuideServiceImplTest { @Test public void testAddGuide() throws WxErrorException { - this.wxService.getGuideService().addGuide("abc", "", null, null); + this.wxService.getGuideService().addGuide("wx1java", "", null, null); } @Test public void testAddGuide_another() throws WxErrorException { - this.wxService.getGuideService().addGuide(WxMpGuideInfo.builder().account("cde").build()); + this.wxService.getGuideService().addGuide(WxMpGuideInfo.builder().account("wx1java").build()); } @Test public void testGetGuide() throws WxErrorException { - final WxMpGuideInfo guideInfo = this.wxService.getGuideService().getGuide("abc", null); + final WxMpGuideInfo guideInfo = this.wxService.getGuideService().getGuide("wx1java", null); assertThat(guideInfo).isNotNull(); } + + @Test + public void testUpdateGuide() throws WxErrorException { + this.wxService.getGuideService().updateGuide(WxMpGuideInfo.builder().account("wx1java").nickName("我是谁").build()); + } + + @Test + public void testDelGuide() throws WxErrorException { + this.wxService.getGuideService().delGuide("wx1java", null); + } + + @Test + public void testListGuide() throws WxErrorException { + final WxMpGuideList guideList = this.wxService.getGuideService().listGuide(0, 10); + assertThat(guideList).isNotNull(); + } }