Skip to content

Commit ba7905a

Browse files
committed
binarywang#516 增加获取Wi-Fi门店列表接口
1 parent fa6fe78 commit ba7905a

File tree

6 files changed

+193
-0
lines changed

6 files changed

+193
-0
lines changed

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,13 @@ public interface WxMpService {
415415
*/
416416
WxMpAiOpenService getAiOpenService();
417417

418+
/**
419+
* 返回WIFI接口方法的实现类对象,以方便调用其各个接口
420+
*
421+
* @return WxMpWifiService
422+
*/
423+
WxMpWifiService getWifiService();
424+
418425
void setKefuService(WxMpKefuService kefuService);
419426

420427
void setMaterialService(WxMpMaterialService materialService);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package me.chanjar.weixin.mp.api;
2+
3+
import me.chanjar.weixin.common.error.WxErrorException;
4+
import me.chanjar.weixin.mp.bean.wifi.WxMpWifiShopListResult;
5+
6+
/**
7+
* <pre>
8+
* 微信连接WI-FI接口.
9+
* Created by BinaryWang on 2018/6/10.
10+
* </pre>
11+
*
12+
* @author <a href="https://github.com/binarywang">Binary Wang</a>
13+
*/
14+
public interface WxMpWifiService {
15+
/**
16+
* <pre>
17+
* 获取Wi-Fi门店列表.
18+
* 通过此接口获取WiFi的门店列表,该列表包括公众平台的门店信息、以及添加设备后的WiFi相关信息。创建门店方法请参考“微信门店接口”。
19+
* 注:微信连Wi-Fi下的所有接口中的shop_id,必需先通过此接口获取。
20+
*
21+
* http请求方式: POST
22+
* 请求URL:https://api.weixin.qq.com/bizwifi/shop/list?access_token=ACCESS_TOKEN
23+
* </pre>
24+
* @param pageIndex 分页下标,默认从1开始
25+
* @param pageSize 每页的个数,默认10个,最大20个
26+
*/
27+
WxMpWifiShopListResult listShop(int pageIndex, int pageSize) throws WxErrorException;
28+
}

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/BaseWxMpServiceImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH
5353
private WxMpMemberCardService memberCardService = new WxMpMemberCardServiceImpl(this);
5454
private WxMpMassMessageService massMessageService = new WxMpMassMessageServiceImpl(this);
5555
private WxMpAiOpenService aiOpenService = new WxMpAiOpenServiceImpl(this);
56+
private WxMpWifiService wifiService = new WxMpWifiServiceImpl(this);
5657

5758
private int retrySleepMillis = 1000;
5859
private int maxRetryTimes = 5;
@@ -501,4 +502,9 @@ public WxMpAiOpenService getAiOpenService() {
501502
public void setAiOpenService(WxMpAiOpenService aiOpenService) {
502503
this.aiOpenService = aiOpenService;
503504
}
505+
506+
@Override
507+
public WxMpWifiService getWifiService() {
508+
return this.wifiService;
509+
}
504510
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package me.chanjar.weixin.mp.api.impl;
2+
3+
import com.google.gson.JsonObject;
4+
import me.chanjar.weixin.common.error.WxErrorException;
5+
import me.chanjar.weixin.mp.api.WxMpService;
6+
import me.chanjar.weixin.mp.api.WxMpWifiService;
7+
import me.chanjar.weixin.mp.bean.wifi.WxMpWifiShopListResult;
8+
9+
/**
10+
* <pre>
11+
* Created by BinaryWang on 2018/6/10.
12+
* </pre>
13+
*
14+
* @author <a href="https://github.com/binarywang">Binary Wang</a>
15+
*/
16+
public class WxMpWifiServiceImpl implements WxMpWifiService {
17+
private WxMpService wxMpService;
18+
19+
public WxMpWifiServiceImpl(WxMpService wxMpService) {
20+
this.wxMpService = wxMpService;
21+
}
22+
23+
@Override
24+
public WxMpWifiShopListResult listShop(int pageIndex, int pageSize) throws WxErrorException {
25+
JsonObject json = new JsonObject();
26+
json.addProperty("pageindex", pageIndex);
27+
json.addProperty("pagesize", pageSize);
28+
final String result = this.wxMpService.post("https://api.weixin.qq.com/bizwifi/shop/list", json.toString());
29+
return WxMpWifiShopListResult.fromJson(result);
30+
}
31+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package me.chanjar.weixin.mp.bean.wifi;
2+
3+
import com.google.gson.JsonParser;
4+
import com.google.gson.annotations.SerializedName;
5+
import lombok.Data;
6+
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
7+
8+
import java.util.List;
9+
10+
/**
11+
* <pre>
12+
* Created by BinaryWang on 2018/6/10.
13+
* </pre>
14+
*
15+
* @author <a href="https://github.com/binarywang">Binary Wang</a>
16+
*/
17+
@Data
18+
public class WxMpWifiShopListResult {
19+
public static WxMpWifiShopListResult fromJson(String json) {
20+
return WxMpGsonBuilder.create().fromJson(
21+
new JsonParser().parse(json).getAsJsonObject().get("data"),
22+
WxMpWifiShopListResult.class);
23+
}
24+
25+
/**
26+
* 总数
27+
*/
28+
@SerializedName("totalcount")
29+
private int totalCount;
30+
31+
/**
32+
* 分页下标
33+
*/
34+
@SerializedName("pageindex")
35+
private int pageIndex;
36+
37+
/**
38+
* 分页页数
39+
*/
40+
@SerializedName("pagecount")
41+
private int pageCount;
42+
43+
private List<Record> records;
44+
45+
@Data
46+
public static class Record {
47+
48+
/**
49+
* 门店ID(适用于微信连Wi-Fi业务)
50+
*/
51+
@SerializedName("shop_id")
52+
private Integer shopId;
53+
54+
/**
55+
* 门店名称
56+
*/
57+
@SerializedName("shop_name")
58+
private String shopName;
59+
60+
/**
61+
* 无线网络设备的ssid,未添加设备为空,多个ssid时显示第一个
62+
*/
63+
@SerializedName("ssid")
64+
private String ssid;
65+
66+
/**
67+
* 无线网络设备的ssid列表,返回数组格式
68+
*/
69+
@SerializedName("ssid_list")
70+
private List<String> ssidList;
71+
72+
/**
73+
* 门店内设备的设备类型,0-未添加设备,1-专业型设备,4-密码型设备,5-portal自助型设备,31-portal改造型设备
74+
*/
75+
@SerializedName("protocol_type")
76+
private Integer protocolType;
77+
78+
/**
79+
* 商户自己的id,与门店poi_id对应关系,建议在添加门店时候建立关联关系,具体请参考“微信门店接口”
80+
*/
81+
@SerializedName("sid")
82+
private String sid;
83+
84+
/**
85+
* 门店ID(适用于微信卡券、微信门店业务),具体定义参考微信门店,与shop_id一一对应
86+
*/
87+
@SerializedName("poi_id")
88+
private String poiId;
89+
}
90+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package me.chanjar.weixin.mp.api.impl;
2+
3+
import com.google.inject.Inject;
4+
import me.chanjar.weixin.common.error.WxErrorException;
5+
import me.chanjar.weixin.mp.api.WxMpService;
6+
import me.chanjar.weixin.mp.api.test.ApiTestModule;
7+
import me.chanjar.weixin.mp.bean.wifi.WxMpWifiShopListResult;
8+
import org.testng.annotations.Guice;
9+
import org.testng.annotations.Test;
10+
11+
import static org.testng.Assert.*;
12+
13+
/**
14+
* <pre>
15+
* Created by BinaryWang on 2018/6/10.
16+
* </pre>
17+
*
18+
* @author <a href="https://github.com/binarywang">Binary Wang</a>
19+
*/
20+
@Test
21+
@Guice(modules = ApiTestModule.class)
22+
public class WxMpWifiServiceImplTest {
23+
@Inject
24+
private WxMpService wxService;
25+
26+
@Test
27+
public void testListShop() throws WxErrorException {
28+
final WxMpWifiShopListResult result = this.wxService.getWifiService().listShop(1, 2);
29+
System.out.println(result);
30+
}
31+
}

0 commit comments

Comments
 (0)