Skip to content

Commit ea13197

Browse files
rememberberbinarywang
authored andcommitted
新增接口:摇一摇周边获取设备及用户信息 (binarywang#243)
binarywang#240
1 parent ff2caf7 commit ea13197

File tree

7 files changed

+314
-0
lines changed

7 files changed

+314
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,12 @@ public interface WxMpService {
409409
*/
410410
WxMpDeviceService getDeviceService();
411411

412+
/**
413+
* 返回摇一摇周边相关接口方法的实现类对象,以方便调用其各个接口
414+
*
415+
* @return WxMpShakeService
416+
*/
417+
WxMpShakeService getShakeService();
412418

413419
/**
414420
* 初始化http请求对象
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package me.chanjar.weixin.mp.api;
2+
3+
import me.chanjar.weixin.common.exception.WxErrorException;
4+
import me.chanjar.weixin.mp.bean.WxMpShakeInfoResult;
5+
import me.chanjar.weixin.mp.bean.WxMpShakeQuery;
6+
7+
/**
8+
* 摇一摇周边的相关接口
9+
*
10+
* @author rememberber
11+
*/
12+
public interface WxMpShakeService {
13+
14+
/**
15+
* <pre>
16+
* 获取设备及用户信息<br/>
17+
* 获取设备信息,包括UUID、major、minor,以及距离、openID等信息。
18+
* 详情请见: https://mp.weixin.qq.com/wiki?action=doc&id=mp1443447963
19+
* http请求方式: POST(请使用https协议)
20+
* 接口地址:https://api.weixin.qq.com/shakearound/user/getshakeinfo?access_token=ACCESS_TOKE
21+
* </pre>
22+
*
23+
* @param wxMpShakeQuery 查询参数
24+
*/
25+
WxMpShakeInfoResult getShakeInfo(WxMpShakeQuery wxMpShakeQuery) throws WxErrorException;
26+
27+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public abstract class AbstractWxMpServiceImpl<H, P> implements WxMpService, Requ
4141
private WxMpUserBlacklistService blackListService = new WxMpUserBlacklistServiceImpl(this);
4242
private WxMpTemplateMsgService templateMsgService = new WxMpTemplateMsgServiceImpl(this);
4343
private WxMpDeviceService deviceService = new WxMpDeviceServiceImpl(this);
44+
private WxMpShakeService shakeService = new WxMpShakeServiceImpl(this);
4445

4546
private int retrySleepMillis = 1000;
4647
private int maxRetryTimes = 5;
@@ -394,4 +395,9 @@ public WxMpTemplateMsgService getTemplateMsgService() {
394395
public WxMpDeviceService getDeviceService() {
395396
return this.deviceService;
396397
}
398+
399+
@Override
400+
public WxMpShakeService getShakeService(){
401+
return this.shakeService;
402+
}
397403
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package me.chanjar.weixin.mp.api.impl;
2+
3+
import me.chanjar.weixin.common.exception.WxErrorException;
4+
import me.chanjar.weixin.mp.api.WxMpService;
5+
import me.chanjar.weixin.mp.api.WxMpShakeService;
6+
import me.chanjar.weixin.mp.bean.WxMpShakeInfoResult;
7+
import me.chanjar.weixin.mp.bean.WxMpShakeQuery;
8+
9+
/**
10+
* Created by rememberber on 2017/6/5.
11+
* @author rememberber
12+
*/
13+
public class WxMpShakeServiceImpl implements WxMpShakeService {
14+
15+
private WxMpService wxMpService;
16+
17+
public WxMpShakeServiceImpl(WxMpService wxMpService) {
18+
this.wxMpService = wxMpService;
19+
}
20+
21+
/**
22+
* <pre>
23+
* 获取设备及用户信息<br/>
24+
* 获取设备信息,包括UUID、major、minor,以及距离、openID等信息。
25+
* 详情请见: https://mp.weixin.qq.com/wiki?action=doc&id=mp1443447963
26+
* http请求方式: POST(请使用https协议)
27+
* 接口地址:https://api.weixin.qq.com/shakearound/user/getshakeinfo?access_token=ACCESS_TOKE
28+
* </pre>
29+
*
30+
* @param wxMpShakeQuery 查询参数
31+
*/
32+
@Override
33+
public WxMpShakeInfoResult getShakeInfo(WxMpShakeQuery wxMpShakeQuery) throws WxErrorException {
34+
String url = "https://api.weixin.qq.com/shakearound/user/getshakeinfo";
35+
String postData = wxMpShakeQuery.toJsonString();
36+
String responseContent = this.wxMpService.post(url, postData);
37+
return WxMpShakeInfoResult.fromJson(responseContent);
38+
}
39+
}
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
package me.chanjar.weixin.mp.bean;
2+
3+
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
4+
5+
import java.io.Serializable;
6+
7+
/**
8+
* 摇一摇周边:获取设备及用户信息接口返回JSON数据接收类
9+
* Created by rememberber on 2017/6/5.
10+
*
11+
* @author rememberber
12+
*/
13+
public class WxMpShakeInfoResult implements Serializable {
14+
15+
private Integer errcode;
16+
17+
private String errmsg;
18+
19+
private Data data;
20+
21+
public static WxMpShakeInfoResult fromJson(String json) {
22+
return WxMpGsonBuilder.INSTANCE.create().fromJson(json, WxMpShakeInfoResult.class);
23+
}
24+
25+
public class Data {
26+
27+
private String page_id;
28+
29+
private String openid;
30+
31+
private String poi_id;
32+
33+
private String brand_userame;
34+
35+
private BeaconInfo beacon_info;
36+
37+
public class BeaconInfo {
38+
39+
private double distance;
40+
41+
private Integer major;
42+
43+
private Integer measure_power;
44+
45+
private Integer minor;
46+
47+
private Integer rssi;
48+
49+
private String uuid;
50+
51+
public double getDistance() {
52+
return distance;
53+
}
54+
55+
public void setDistance(double distance) {
56+
this.distance = distance;
57+
}
58+
59+
public Integer getMajor() {
60+
return major;
61+
}
62+
63+
public void setMajor(Integer major) {
64+
this.major = major;
65+
}
66+
67+
public Integer getMeasure_power() {
68+
return measure_power;
69+
}
70+
71+
public void setMeasure_power(Integer measure_power) {
72+
this.measure_power = measure_power;
73+
}
74+
75+
public Integer getMinor() {
76+
return minor;
77+
}
78+
79+
public void setMinor(Integer minor) {
80+
this.minor = minor;
81+
}
82+
83+
public Integer getRssi() {
84+
return rssi;
85+
}
86+
87+
public void setRssi(Integer rssi) {
88+
this.rssi = rssi;
89+
}
90+
91+
public String getUuid() {
92+
return uuid;
93+
}
94+
95+
public void setUuid(String uuid) {
96+
this.uuid = uuid;
97+
}
98+
}
99+
100+
public String getPage_id() {
101+
return page_id;
102+
}
103+
104+
public void setPage_id(String page_id) {
105+
this.page_id = page_id;
106+
}
107+
108+
public String getOpenid() {
109+
return openid;
110+
}
111+
112+
public void setOpenid(String openid) {
113+
this.openid = openid;
114+
}
115+
116+
public String getPoi_id() {
117+
return poi_id;
118+
}
119+
120+
public void setPoi_id(String poi_id) {
121+
this.poi_id = poi_id;
122+
}
123+
124+
public BeaconInfo getBeacon_info() {
125+
return beacon_info;
126+
}
127+
128+
public void setBeacon_info(BeaconInfo beacon_info) {
129+
this.beacon_info = beacon_info;
130+
}
131+
132+
public String getBrand_userame() {
133+
return brand_userame;
134+
}
135+
136+
public void setBrand_userame(String brand_userame) {
137+
this.brand_userame = brand_userame;
138+
}
139+
}
140+
141+
public Integer getErrcode() {
142+
return errcode;
143+
}
144+
145+
public void setErrcode(Integer errcode) {
146+
this.errcode = errcode;
147+
}
148+
149+
public String getErrmsg() {
150+
return errmsg;
151+
}
152+
153+
public void setErrmsg(String errmsg) {
154+
this.errmsg = errmsg;
155+
}
156+
157+
public Data getData() {
158+
return data;
159+
}
160+
161+
public void setData(Data data) {
162+
this.data = data;
163+
}
164+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package me.chanjar.weixin.mp.bean;
2+
3+
import com.google.gson.Gson;
4+
5+
import java.util.HashMap;
6+
import java.util.Map;
7+
8+
/**
9+
* Created by rememberber on 2017/6/5.
10+
*
11+
* @author rememberber
12+
*/
13+
public class WxMpShakeQuery {
14+
15+
private String ticket;
16+
17+
private int needPoi;
18+
19+
public String toJsonString() {
20+
Map<String, Object> map = new HashMap<>();
21+
map.put("ticket", this.ticket);
22+
map.put("need_poi", this.needPoi);
23+
return new Gson().toJson(map);
24+
}
25+
26+
public String getTicket() {
27+
return ticket;
28+
}
29+
30+
public void setTicket(String ticket) {
31+
this.ticket = ticket;
32+
}
33+
34+
public int getNeedPoi() {
35+
return needPoi;
36+
}
37+
38+
public void setNeedPoi(int needPoi) {
39+
this.needPoi = needPoi;
40+
}
41+
}
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.mp.api.WxMpService;
5+
import me.chanjar.weixin.mp.api.test.ApiTestModule;
6+
import me.chanjar.weixin.mp.bean.WxMpShakeInfoResult;
7+
import me.chanjar.weixin.mp.bean.WxMpShakeQuery;
8+
import org.testng.annotations.Guice;
9+
import org.testng.annotations.Test;
10+
11+
/**
12+
* 测试摇一摇周边相关的接口
13+
*
14+
* @author rememberber
15+
*/
16+
@Test(groups = "userAPI")
17+
@Guice(modules = ApiTestModule.class)
18+
public class WxMpShakeServiceImplTest {
19+
@Inject
20+
private WxMpService wxService;
21+
22+
public void testGetShakeInfo() throws Exception {
23+
WxMpShakeQuery wxMpShakeQuery = new WxMpShakeQuery();
24+
wxMpShakeQuery.setTicket("b87db7df490e5cbe4f598272f77f46be");
25+
wxMpShakeQuery.setNeedPoi(1);
26+
WxMpShakeInfoResult wxMpShakeInfoResult = this.wxService.getShakeService().getShakeInfo(wxMpShakeQuery);
27+
28+
System.out.println();
29+
}
30+
31+
}

0 commit comments

Comments
 (0)