#516 添加WiFi门店管理查询门店Wi-Fi信息的接口

This commit is contained in:
Binary Wang 2019-06-16 23:07:11 +08:00
parent a4f5aa341b
commit 9c149bb1e2
6 changed files with 224 additions and 15 deletions

View File

@ -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
* 请求URLhttps://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
* 请求URLhttps://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;
}

View File

@ -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()));
}
}

View File

@ -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--已连接+公众号名称+WiFi3--已连接+门店名称+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;
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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);
}
}
}