| @@ -1,6 +1,7 @@ | |||
| package me.chanjar.weixin.mp.api; | |||
| import me.chanjar.weixin.common.error.WxErrorException; | |||
| import me.chanjar.weixin.mp.bean.wifi.WxMpWifiShopDataResult; | |||
| import me.chanjar.weixin.mp.bean.wifi.WxMpWifiShopListResult; | |||
| /** | |||
| @@ -21,8 +22,27 @@ public interface WxMpWifiService { | |||
| * http请求方式: POST | |||
| * 请求URL:https://api.weixin.qq.com/bizwifi/shop/list?access_token=ACCESS_TOKEN | |||
| * </pre> | |||
| * @param pageIndex 分页下标,默认从1开始 | |||
| * | |||
| * @param pageIndex 分页下标,默认从1开始 | |||
| * @param pageSize 每页的个数,默认10个,最大20个 | |||
| * @return 结果 | |||
| * @throws WxErrorException 异常 | |||
| */ | |||
| WxMpWifiShopListResult listShop(int pageIndex, int pageSize) throws WxErrorException; | |||
| /** | |||
| * <pre> | |||
| * 查询门店Wi-Fi信息 | |||
| * 通过此接口查询某一门店的详细Wi-Fi信息,包括门店内的设备类型、ssid、密码、设备数量、商家主页URL、顶部常驻入口文案。 | |||
| * | |||
| * http请求方式: POST | |||
| * 请求URL:https://api.weixin.qq.com/bizwifi/shop/get?access_token=ACCESS_TOKEN | |||
| * POST数据格式:JSON | |||
| * </pre> | |||
| * | |||
| * @param shopId 门店ID | |||
| * @return 结果 | |||
| * @throws WxErrorException 异常 | |||
| */ | |||
| WxMpWifiShopDataResult getShopWifiInfo(int shopId) throws WxErrorException; | |||
| } | |||
| @@ -5,10 +5,11 @@ import lombok.RequiredArgsConstructor; | |||
| import me.chanjar.weixin.common.error.WxErrorException; | |||
| import me.chanjar.weixin.mp.api.WxMpService; | |||
| import me.chanjar.weixin.mp.api.WxMpWifiService; | |||
| import me.chanjar.weixin.mp.bean.wifi.WxMpWifiShopDataResult; | |||
| import me.chanjar.weixin.mp.bean.wifi.WxMpWifiShopListResult; | |||
| import me.chanjar.weixin.mp.enums.WxMpApiUrl; | |||
| import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Wifi.*; | |||
| import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Wifi.BIZWIFI_SHOP_GET; | |||
| import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Wifi.BIZWIFI_SHOP_LIST; | |||
| /** | |||
| * <pre> | |||
| @@ -29,4 +30,11 @@ public class WxMpWifiServiceImpl implements WxMpWifiService { | |||
| final String result = this.wxMpService.post(BIZWIFI_SHOP_LIST, json.toString()); | |||
| return WxMpWifiShopListResult.fromJson(result); | |||
| } | |||
| @Override | |||
| public WxMpWifiShopDataResult getShopWifiInfo(int shopId) throws WxErrorException { | |||
| JsonObject json = new JsonObject(); | |||
| json.addProperty("shop_id", shopId); | |||
| return WxMpWifiShopDataResult.fromJson(this.wxMpService.post(BIZWIFI_SHOP_GET, json.toString())); | |||
| } | |||
| } | |||
| @@ -0,0 +1,114 @@ | |||
| package me.chanjar.weixin.mp.bean.wifi; | |||
| import com.google.gson.JsonParser; | |||
| import com.google.gson.annotations.SerializedName; | |||
| import lombok.Data; | |||
| import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | |||
| import java.util.List; | |||
| /** | |||
| * 门店Wi-Fi信息. | |||
| * | |||
| * @author <a href="https://github.com/binarywang">Binary Wang</a> | |||
| * @date 2019-06-16 | |||
| */ | |||
| @Data | |||
| public class WxMpWifiShopDataResult { | |||
| public static WxMpWifiShopDataResult fromJson(String json) { | |||
| return WxMpGsonBuilder.create().fromJson( | |||
| new JsonParser().parse(json).getAsJsonObject().get("data"), | |||
| WxMpWifiShopDataResult.class); | |||
| } | |||
| /** | |||
| * 门店名称. | |||
| */ | |||
| @SerializedName("shop_name") | |||
| private String shopName; | |||
| /** | |||
| * 无线网络设备的ssid,未添加设备为空,多个ssid时显示第一个. | |||
| */ | |||
| @SerializedName("ssid") | |||
| private String ssid; | |||
| /** | |||
| * 无线网络设备的ssid列表,返回数组格式. | |||
| */ | |||
| @SerializedName("ssid_list") | |||
| private String[] ssidList; | |||
| /** | |||
| * ssid和密码的列表,数组格式。当为密码型设备时,密码才有值. | |||
| */ | |||
| @SerializedName("ssid_password_list") | |||
| private List<SsidPassword> ssidPasswordList; | |||
| /** | |||
| * 设备密码,当设备类型为密码型时返回. | |||
| */ | |||
| @SerializedName("password") | |||
| private String password; | |||
| /** | |||
| * 门店内设备的设备类型,0-未添加设备,4-密码型设备,31-portal型设备. | |||
| */ | |||
| @SerializedName("protocol_type") | |||
| private Integer protocolType; | |||
| /** | |||
| * 门店内设备总数. | |||
| */ | |||
| @SerializedName("ap_count") | |||
| private Integer apCount; | |||
| /** | |||
| * 商家主页模板类型. | |||
| */ | |||
| @SerializedName("template_id") | |||
| private Integer templateId; | |||
| /** | |||
| * 商家主页链接. | |||
| */ | |||
| @SerializedName("homepage_url") | |||
| private String homepageUrl; | |||
| /** | |||
| * 顶部常驻入口上显示的文本内容:0--欢迎光临+公众号名称;1--欢迎光临+门店名称;2--已连接+公众号名称+WiFi;3--已连接+门店名称+Wi-Fi. | |||
| */ | |||
| @SerializedName("bar_type") | |||
| private Integer barType; | |||
| /** | |||
| * 连网完成页链接. | |||
| */ | |||
| @SerializedName("finishpage_url") | |||
| private String finishPageUrl; | |||
| /** | |||
| * 商户自己的id,与门店poi_id对应关系,建议在添加门店时候建立关联关系,具体请参考“微信门店接口”. | |||
| */ | |||
| @SerializedName("sid") | |||
| private String sid; | |||
| /** | |||
| * 门店ID(适用于微信卡券、微信门店业务),具体定义参考微信门店,与shop_id一一对应. | |||
| */ | |||
| @SerializedName("poi_id") | |||
| private String poiId; | |||
| @Data | |||
| public static class SsidPassword { | |||
| /** | |||
| * 无线网络设备的ssid. | |||
| */ | |||
| private String ssid; | |||
| /** | |||
| * 无线网络设备的password. | |||
| */ | |||
| private String password; | |||
| } | |||
| } | |||
| @@ -23,19 +23,19 @@ public class WxMpWifiShopListResult { | |||
| } | |||
| /** | |||
| * 总数 | |||
| * 总数. | |||
| */ | |||
| @SerializedName("totalcount") | |||
| private int totalCount; | |||
| /** | |||
| * 分页下标 | |||
| * 分页下标. | |||
| */ | |||
| @SerializedName("pageindex") | |||
| private int pageIndex; | |||
| /** | |||
| * 分页页数 | |||
| * 分页页数. | |||
| */ | |||
| @SerializedName("pagecount") | |||
| private int pageCount; | |||
| @@ -46,43 +46,46 @@ public class WxMpWifiShopListResult { | |||
| public static class Record { | |||
| /** | |||
| * 门店ID(适用于微信连Wi-Fi业务) | |||
| * 门店ID(适用于微信连Wi-Fi业务). | |||
| */ | |||
| @SerializedName("shop_id") | |||
| private Integer shopId; | |||
| /** | |||
| * 门店名称 | |||
| * 门店名称. | |||
| */ | |||
| @SerializedName("shop_name") | |||
| private String shopName; | |||
| /** | |||
| * 无线网络设备的ssid,未添加设备为空,多个ssid时显示第一个 | |||
| * 无线网络设备的ssid,未添加设备为空,多个ssid时显示第一个. | |||
| */ | |||
| @SerializedName("ssid") | |||
| private String ssid; | |||
| /** | |||
| * 无线网络设备的ssid列表,返回数组格式 | |||
| * 无线网络设备的ssid列表,返回数组格式. | |||
| */ | |||
| @SerializedName("ssid_list") | |||
| private List<String> ssidList; | |||
| /** | |||
| * 门店内设备的设备类型,0-未添加设备,1-专业型设备,4-密码型设备,5-portal自助型设备,31-portal改造型设备 | |||
| * 门店内设备的设备类型. | |||
| * 0-未添加设备,1-专业型设备,4-密码型设备,5-portal自助型设备,31-portal改造型设备 | |||
| */ | |||
| @SerializedName("protocol_type") | |||
| private Integer protocolType; | |||
| /** | |||
| * 商户自己的id,与门店poi_id对应关系,建议在添加门店时候建立关联关系,具体请参考“微信门店接口” | |||
| * 商户自己的id. | |||
| * 与门店poi_id对应关系,建议在添加门店时候建立关联关系,具体请参考“微信门店接口” | |||
| */ | |||
| @SerializedName("sid") | |||
| private String sid; | |||
| /** | |||
| * 门店ID(适用于微信卡券、微信门店业务),具体定义参考微信门店,与shop_id一一对应 | |||
| * 门店ID(适用于微信卡券、微信门店业务). | |||
| * 具体定义参考微信门店,与shop_id一一对应 | |||
| */ | |||
| @SerializedName("poi_id") | |||
| private String poiId; | |||
| @@ -386,7 +386,12 @@ public interface WxMpApiUrl { | |||
| /** | |||
| * list. | |||
| */ | |||
| BIZWIFI_SHOP_LIST(API_DEFAULT_HOST_URL, "/bizwifi/shop/list"); | |||
| BIZWIFI_SHOP_LIST(API_DEFAULT_HOST_URL, "/bizwifi/shop/list"), | |||
| /** | |||
| * get. | |||
| */ | |||
| BIZWIFI_SHOP_GET(API_DEFAULT_HOST_URL, "/bizwifi/shop/get"); | |||
| private String prefix; | |||
| private String path; | |||
| @@ -4,11 +4,17 @@ import com.google.inject.Inject; | |||
| 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.wifi.WxMpWifiShopDataResult; | |||
| import me.chanjar.weixin.mp.bean.wifi.WxMpWifiShopListResult; | |||
| import org.testng.annotations.Guice; | |||
| import org.testng.annotations.Test; | |||
| import static org.testng.Assert.*; | |||
| import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Wifi.BIZWIFI_SHOP_GET; | |||
| import static org.assertj.core.api.Assertions.assertThat; | |||
| import static org.mockito.Matchers.anyString; | |||
| import static org.mockito.Matchers.eq; | |||
| import static org.mockito.Mockito.mock; | |||
| import static org.mockito.Mockito.when; | |||
| /** | |||
| * <pre> | |||
| @@ -26,6 +32,59 @@ public class WxMpWifiServiceImplTest { | |||
| @Test | |||
| public void testListShop() throws WxErrorException { | |||
| final WxMpWifiShopListResult result = this.wxService.getWifiService().listShop(1, 2); | |||
| assertThat(result).isNotNull(); | |||
| System.out.println(result); | |||
| } | |||
| @Test | |||
| public void testGetShopWifiInfo() throws WxErrorException { | |||
| final WxMpWifiShopDataResult wifiInfo = this.wxService.getWifiService().getShopWifiInfo(123); | |||
| assertThat(wifiInfo).isNotNull(); | |||
| System.out.println(wifiInfo); | |||
| } | |||
| public static class MockTest { | |||
| private WxMpService wxService = mock(WxMpService.class); | |||
| @Test | |||
| public void testGetShopWifiInfo() throws Exception { | |||
| String returnJson = "{\n" + | |||
| " \"errcode\": 0,\n" + | |||
| " \"data\": {\n" + | |||
| " \"shop_name\": \"南山店\",\n" + | |||
| " \"ssid\": \" WX123\",\n" + | |||
| " \"ssid_list\": [\n" + | |||
| " \"WX123\",\n" + | |||
| " \"WX456\"\n" + | |||
| " ],\n" + | |||
| " \"ssid_password_list\": [\n" + | |||
| " {\n" + | |||
| " \"ssid\": \"WX123\",\n" + | |||
| " \"password\": \"123456789\"\n" + | |||
| " },\n" + | |||
| " {\n" + | |||
| " \"ssid\": \"WX456\",\n" + | |||
| " \"password\": \"21332465dge\"\n" + | |||
| " }\n" + | |||
| " ],\n" + | |||
| " \"password\": \"123456789\",\n" + | |||
| " \"protocol_type\": 4,\n" + | |||
| " \"ap_count\": 2,\n" + | |||
| " \"template_id\": 1,\n" + | |||
| " \"homepage_url\": \"http://www.weixin.qq.com/\",\n" + | |||
| " \"bar_type\": 1,\n" + | |||
| " \"sid\":\"\",\n" + | |||
| " \"poi_id\":\"285633617\"\n" + | |||
| " }\n" + | |||
| "}"; | |||
| when(wxService.post(eq(BIZWIFI_SHOP_GET), anyString())).thenReturn(returnJson); | |||
| when(wxService.getWifiService()).thenReturn(new WxMpWifiServiceImpl(wxService)); | |||
| final WxMpWifiShopDataResult wifiInfo = this.wxService.getWifiService().getShopWifiInfo(123); | |||
| assertThat(wifiInfo).isNotNull(); | |||
| System.out.println(wifiInfo); | |||
| } | |||
| } | |||
| } | |||