mirror of
				https://gitee.com/binary/weixin-java-tools.git
				synced 2025-10-31 18:46:10 +08:00 
			
		
		
		
	🆕 #1686 微信公众号增加对话能力(原导购助手)部分接口,如修改顾问、删除顾问、获取顾问列表等
This commit is contained in:
		| @ -2,6 +2,7 @@ package me.chanjar.weixin.mp.api; | |||||||
|  |  | ||||||
| import me.chanjar.weixin.common.error.WxErrorException; | import me.chanjar.weixin.common.error.WxErrorException; | ||||||
| import me.chanjar.weixin.mp.bean.guide.WxMpGuideInfo; | 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; |   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 . |    * @throws WxErrorException . | ||||||
|    */ |    */ | ||||||
|   WxMpGuideInfo getGuide(String account, String openid) 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; | ||||||
| } | } | ||||||
|  | |||||||
| @ -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.WxMpGuideService; | ||||||
| import me.chanjar.weixin.mp.api.WxMpService; | import me.chanjar.weixin.mp.api.WxMpService; | ||||||
| import me.chanjar.weixin.mp.bean.guide.WxMpGuideInfo; | import me.chanjar.weixin.mp.bean.guide.WxMpGuideInfo; | ||||||
|  | import me.chanjar.weixin.mp.bean.guide.WxMpGuideList; | ||||||
| import me.chanjar.weixin.mp.enums.WxMpApiUrl; | import me.chanjar.weixin.mp.enums.WxMpApiUrl; | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @ -35,9 +36,31 @@ public class WxMpGuideServiceImpl implements WxMpGuideService { | |||||||
|         OPENID, guideInfo.getOpenid())); |         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 |   @Override | ||||||
|   public WxMpGuideInfo getGuide(String account, String openid) throws WxErrorException { |   public WxMpGuideInfo getGuide(String account, String openid) throws WxErrorException { | ||||||
|     return WxMpGuideInfo.fromJson(this.mpService.post(WxMpApiUrl.Guide.GET_GUIDE, |     return WxMpGuideInfo.fromJson(this.mpService.post(WxMpApiUrl.Guide.GET_GUIDE, | ||||||
|       GsonHelper.buildJsonObject(ACCOUNT, account, OPENID, openid))); |       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))); | ||||||
|  |   } | ||||||
| } | } | ||||||
|  | |||||||
| @ -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); | ||||||
|  |   } | ||||||
|  | } | ||||||
| @ -569,7 +569,7 @@ public class WxMpXmlMessage implements Serializable { | |||||||
|    * 审核成功时的时间(整形),时间戳 |    * 审核成功时的时间(整形),时间戳 | ||||||
|    */ |    */ | ||||||
|   @XStreamAlias("SuccTime") |   @XStreamAlias("SuccTime") | ||||||
|   private Long succTime; |   private Long successTime; | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * 审核失败的原因 |    * 审核失败的原因 | ||||||
|  | |||||||
| @ -141,4 +141,14 @@ public class WxMpEventConstants { | |||||||
|     public static final String CLOUD_INVOICE_INVOICERESULT_EVENT = "cloud_invoice_invoiceresult_event"; |     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"; | ||||||
|  |  | ||||||
|  |   } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1166,11 +1166,22 @@ public interface WxMpApiUrl { | |||||||
|      * 添加顾问 |      * 添加顾问 | ||||||
|      */ |      */ | ||||||
|     ADD_GUIDE(API_DEFAULT_HOST_URL, "/cgi-bin/guide/addguideacct"), |     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 prefix; | ||||||
|     private final String path; |     private final String path; | ||||||
|  |  | ||||||
|  | |||||||
| @ -5,6 +5,7 @@ import me.chanjar.weixin.common.error.WxErrorException; | |||||||
| import me.chanjar.weixin.mp.api.WxMpService; | import me.chanjar.weixin.mp.api.WxMpService; | ||||||
| import me.chanjar.weixin.mp.api.test.ApiTestModule; | import me.chanjar.weixin.mp.api.test.ApiTestModule; | ||||||
| import me.chanjar.weixin.mp.bean.guide.WxMpGuideInfo; | 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.Guice; | ||||||
| import org.testng.annotations.Test; | import org.testng.annotations.Test; | ||||||
|  |  | ||||||
| @ -23,17 +24,33 @@ public class WxMpGuideServiceImplTest { | |||||||
|  |  | ||||||
|   @Test |   @Test | ||||||
|   public void testAddGuide() throws WxErrorException { |   public void testAddGuide() throws WxErrorException { | ||||||
|     this.wxService.getGuideService().addGuide("abc", "", null, null); |     this.wxService.getGuideService().addGuide("wx1java", "", null, null); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   @Test |   @Test | ||||||
|   public void testAddGuide_another() throws WxErrorException { |   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 |   @Test | ||||||
|   public void testGetGuide() throws WxErrorException { |   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(); |     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(); | ||||||
|  |   } | ||||||
| } | } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Binary Wang
					Binary Wang