Skip to content

Commit a7c72f6

Browse files
author
dongfuqiang
committed
update
1 parent 0d56d6c commit a7c72f6

File tree

16 files changed

+668
-0
lines changed

16 files changed

+668
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package me.chanjar.weixin.mp.api;
2+
3+
import me.chanjar.weixin.common.exception.WxErrorException;
4+
import me.chanjar.weixin.mp.bean.device.*;
5+
6+
/**
7+
* Created by keungtung on 10/12/2016.
8+
*/
9+
public interface WxMpDeviceService {
10+
/**
11+
* <pre>
12+
* 主动发送消息给设备
13+
* 详情请见:http://iot.weixin.qq.com/wiki/new/index.html?page=3-4-3
14+
* </pre>
15+
*/
16+
TransMsgResp transMsg(WxDeviceMsg msg) throws WxErrorException;
17+
18+
/**
19+
* <pre>
20+
* 获取一组新的deviceid和设备二维码
21+
* 详情请见:http://iot.weixin.qq.com/wiki/new/index.html?page=3-4-6
22+
* </pre>
23+
* @param productId 产品id
24+
* @return 返回WxDeviceQrCodeResult
25+
*/
26+
WxDeviceQrCodeResult getQrCode(String productId) throws WxErrorException;
27+
28+
/**
29+
* <pre>
30+
* 将device id及其属性信息提交公众平台进行授权
31+
* 详情请见:http://iot.weixin.qq.com/wiki/new/index.html?page=3-4-6
32+
* </pre>
33+
* @param wxDeviceAuthorize 授权请求对象
34+
* @return WxDeviceAuthorizeResult
35+
*/
36+
WxDeviceAuthorizeResult authorize(WxDeviceAuthorize wxDeviceAuthorize) throws WxErrorException;
37+
38+
39+
/**
40+
* <pre>
41+
* 第三方后台绑定成功后,通知公众平台
42+
* 详情请见:http://iot.weixin.qq.com/wiki/new/index.html/page=3-4-7
43+
* </pre>
44+
* @param wxDeviceBind 绑定请求对象
45+
* @return WxDeviceBindResult
46+
*/
47+
WxDeviceBindResult bind(WxDeviceBind wxDeviceBind) throws WxErrorException;
48+
49+
/**
50+
* <pre>
51+
* 强制绑定用户和设备
52+
* 详情请见:http://iot.weixin.qq.com/wiki/new/index.html?page=3-4-7
53+
* </pre>
54+
* @param wxDeviceBind 强制绑定请求对象
55+
* @return WxDeviceBindResult
56+
*/
57+
WxDeviceBindResult compelBind(WxDeviceBind wxDeviceBind) throws WxErrorException;
58+
59+
/**
60+
* <pre>
61+
* 第三方确认用户和设备的解绑操作
62+
* 详情请见:http://iot.weixin.qq.com/wiki/new/index.html/page=3-4-7
63+
* </pre>
64+
* @param wxDeviceBind 绑定请求对象
65+
* @return WxDeviceBidResult
66+
*/
67+
WxDeviceBindResult unbind(WxDeviceBind wxDeviceBind) throws WxErrorException;
68+
69+
/**
70+
* <pre>
71+
* 强制解绑用户和设备
72+
* 详情请见:http://iot.weixin.qq.com/wiki/new/index.html?page=3-4-7
73+
* </pre>
74+
* @param wxDeviceBind 强制解绑请求对象
75+
* @return WxDeviceBindResult
76+
*/
77+
WxDeviceBindResult compelUnbind(WxDeviceBind wxDeviceBind) throws WxErrorException;
78+
79+
80+
}

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
@@ -345,4 +345,11 @@ public interface WxMpService {
345345
* @return WxMpTemplateMsgService
346346
*/
347347
WxMpTemplateMsgService getTemplateMsgService();
348+
349+
/**
350+
* 返回硬件平台相关接口方法的实现类对象,以方便调用其各个接口
351+
*
352+
* @return WxMpDeviceService
353+
*/
354+
WxMpDeviceService getDeviceService();
348355
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package me.chanjar.weixin.mp.api.impl;
2+
3+
import me.chanjar.weixin.common.exception.WxErrorException;
4+
import me.chanjar.weixin.mp.api.WxMpDeviceService;
5+
import me.chanjar.weixin.mp.api.WxMpService;
6+
import me.chanjar.weixin.mp.bean.device.*;
7+
import org.slf4j.Logger;
8+
import org.slf4j.LoggerFactory;
9+
10+
/**
11+
* Created by keungtung on 10/12/2016.
12+
*/
13+
public class WxMpDeviceServiceImpl implements WxMpDeviceService {
14+
private static final String API_URL_PREFIX = "https://api.weixin.qq.com/device";
15+
private static Logger log = LoggerFactory.getLogger(WxMpMenuServiceImpl.class);
16+
17+
private WxMpService wxMpService;
18+
19+
WxMpDeviceServiceImpl(WxMpService wxMpService) {
20+
this.wxMpService = wxMpService;
21+
}
22+
23+
@Override
24+
public TransMsgResp transMsg(WxDeviceMsg msg) throws WxErrorException {
25+
String url = API_URL_PREFIX + "/transmsg";
26+
String response = this.wxMpService.post(url,msg.toJson());
27+
return TransMsgResp.fromJson(response);
28+
}
29+
30+
@Override
31+
public WxDeviceQrCodeResult getQrCode(String productId) throws WxErrorException {
32+
String url = API_URL_PREFIX + "/getqrcode";
33+
String response = this.wxMpService.get(url, "product_id=" + productId);
34+
return WxDeviceQrCodeResult.fromJson(response);
35+
}
36+
37+
@Override
38+
public WxDeviceAuthorizeResult authorize(WxDeviceAuthorize wxDeviceAuthorize) throws WxErrorException {
39+
String url = API_URL_PREFIX + "/authorize_device";
40+
String response = this.wxMpService.post(url,wxDeviceAuthorize.toJson());
41+
return WxDeviceAuthorizeResult.fromJson(response);
42+
}
43+
44+
@Override
45+
public WxDeviceBindResult bind(WxDeviceBind wxDeviceBind) throws WxErrorException {
46+
String url = API_URL_PREFIX + "/bind";
47+
String response = this.wxMpService.post(url,wxDeviceBind.toJson());
48+
return WxDeviceBindResult.fromJson(response);
49+
}
50+
51+
@Override
52+
public WxDeviceBindResult compelBind(WxDeviceBind wxDeviceBind) throws WxErrorException {
53+
String url = API_URL_PREFIX + "/compel_bind";
54+
String response = this.wxMpService.post(url,wxDeviceBind.toJson());
55+
return WxDeviceBindResult.fromJson(response);
56+
}
57+
58+
@Override
59+
public WxDeviceBindResult unbind(WxDeviceBind wxDeviceBind) throws WxErrorException {
60+
String url = API_URL_PREFIX + "/unbind?";
61+
String response = this.wxMpService.post(url, wxDeviceBind.toJson());
62+
return WxDeviceBindResult.fromJson(response);
63+
}
64+
65+
@Override
66+
public WxDeviceBindResult compelUnbind(WxDeviceBind wxDeviceBind) throws WxErrorException {
67+
String url = API_URL_PREFIX + "/compel_unbind?";
68+
String response = this.wxMpService.post(url, wxDeviceBind.toJson());
69+
return WxDeviceBindResult.fromJson(response);
70+
}
71+
}
72+

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ public class WxMpServiceImpl implements WxMpService {
6262

6363
private WxMpTemplateMsgService templateMsgService = new WxMpTemplateMsgServiceImpl(this);
6464

65+
private WxMpDeviceService deviceService = new WxMpDeviceServiceImpl(this);
66+
6567
private CloseableHttpClient httpClient;
6668

6769
private HttpHost httpProxy;
@@ -540,4 +542,8 @@ public WxMpTemplateMsgService getTemplateMsgService() {
540542
return this.templateMsgService;
541543
}
542544

545+
@Override
546+
public WxMpDeviceService getDeviceService() {
547+
return this.deviceService;
548+
}
543549
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package me.chanjar.weixin.mp.bean.device;
2+
3+
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
4+
5+
/**
6+
* Created by keungtung on 14/12/2016.
7+
*/
8+
public abstract class AbstractDeviceBean {
9+
public String toJson() {
10+
return WxGsonBuilder.create().toJson(this);
11+
}
12+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package me.chanjar.weixin.mp.bean.device;
2+
3+
/**
4+
* Created by keungtung on 10/12/2016.
5+
*/
6+
public class BaseResp extends AbstractDeviceBean{
7+
private BaseInfo base_info;
8+
private Integer errcode;
9+
private String errmsg;
10+
11+
public Integer getErrcode() {
12+
return errcode;
13+
}
14+
15+
public void setErrcode(Integer errcode) {
16+
this.errcode = errcode;
17+
}
18+
19+
public BaseInfo getBase_info() {
20+
return base_info;
21+
}
22+
23+
public void setBase_info(BaseInfo base_info) {
24+
this.base_info = base_info;
25+
}
26+
27+
public String getErrmsg() {
28+
return errmsg;
29+
}
30+
31+
public void setErrmsg(String errmsg) {
32+
this.errmsg = errmsg;
33+
}
34+
35+
private class BaseInfo {
36+
private String device_type;
37+
private String device_id;
38+
39+
public String getDevice_type() {
40+
return device_type;
41+
}
42+
43+
public void setDevice_type(String device_type) {
44+
this.device_type = device_type;
45+
}
46+
47+
public String getDevice_id() {
48+
return device_id;
49+
}
50+
51+
public void setDevice_id(String device_id) {
52+
this.device_id = device_id;
53+
}
54+
}
55+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package me.chanjar.weixin.mp.bean.device;
2+
3+
/**
4+
* Created by keungtung on 10/12/2016.
5+
*/
6+
7+
public class RespMsg extends AbstractDeviceBean{
8+
private Integer retCode;
9+
private String errorInfo;
10+
11+
public Integer getRetCode() {
12+
return retCode;
13+
}
14+
15+
public void setRetCode(Integer retCode) {
16+
this.retCode = retCode;
17+
}
18+
19+
public String getErrorInfo() {
20+
return errorInfo;
21+
}
22+
23+
public void setErrorInfo(String errorInfo) {
24+
this.errorInfo = errorInfo;
25+
}
26+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package me.chanjar.weixin.mp.bean.device;
2+
3+
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
4+
5+
/**
6+
* Created by keungtung on 14/12/2016.
7+
*/
8+
public class TransMsgResp extends AbstractDeviceBean{
9+
private Integer ret;
10+
private String ret_info;
11+
private Integer errcode;
12+
private String errmsg;
13+
14+
public static TransMsgResp fromJson(String json) {
15+
return WxGsonBuilder.create().fromJson(json, TransMsgResp.class);
16+
}
17+
18+
public Integer getRet() {
19+
return ret;
20+
}
21+
22+
public void setRet(Integer ret) {
23+
this.ret = ret;
24+
}
25+
26+
public String getRet_info() {
27+
return ret_info;
28+
}
29+
30+
public void setRet_info(String ret_info) {
31+
this.ret_info = ret_info;
32+
}
33+
34+
public Integer getErrcode() {
35+
return errcode;
36+
}
37+
38+
public void setErrcode(Integer errcode) {
39+
this.errcode = errcode;
40+
}
41+
42+
public String getErrmsg() {
43+
return errmsg;
44+
}
45+
46+
public void setErrmsg(String errmsg) {
47+
this.errmsg = errmsg;
48+
}
49+
}

0 commit comments

Comments
 (0)