-
-
Notifications
You must be signed in to change notification settings - Fork 9k
实现部分硬件平台接口 #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
实现部分硬件平台接口 #97
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpDeviceService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| package me.chanjar.weixin.mp.api; | ||
|
|
||
| import me.chanjar.weixin.common.exception.WxErrorException; | ||
| import me.chanjar.weixin.mp.bean.device.*; | ||
|
|
||
| /** | ||
| * Created by keungtung on 10/12/2016. | ||
| */ | ||
| public interface WxMpDeviceService { | ||
| /** | ||
| * <pre> | ||
| * 主动发送消息给设备 | ||
| * 详情请见:http://iot.weixin.qq.com/wiki/new/index.html?page=3-4-3 | ||
| * </pre> | ||
| */ | ||
| TransMsgResp transMsg(WxDeviceMsg msg) throws WxErrorException; | ||
|
|
||
| /** | ||
| * <pre> | ||
| * 获取一组新的deviceid和设备二维码 | ||
| * 详情请见:http://iot.weixin.qq.com/wiki/new/index.html?page=3-4-6 | ||
| * </pre> | ||
| * @param productId 产品id | ||
| * @return 返回WxDeviceQrCodeResult | ||
| */ | ||
| WxDeviceQrCodeResult getQrCode(String productId) throws WxErrorException; | ||
|
|
||
| /** | ||
| * <pre> | ||
| * 将device id及其属性信息提交公众平台进行授权 | ||
| * 详情请见:http://iot.weixin.qq.com/wiki/new/index.html?page=3-4-6 | ||
| * </pre> | ||
| * @param wxDeviceAuthorize 授权请求对象 | ||
| * @return WxDeviceAuthorizeResult | ||
| */ | ||
| WxDeviceAuthorizeResult authorize(WxDeviceAuthorize wxDeviceAuthorize) throws WxErrorException; | ||
|
|
||
|
|
||
| /** | ||
| * <pre> | ||
| * 第三方后台绑定成功后,通知公众平台 | ||
| * 详情请见:http://iot.weixin.qq.com/wiki/new/index.html/page=3-4-7 | ||
| * </pre> | ||
| * @param wxDeviceBind 绑定请求对象 | ||
| * @return WxDeviceBindResult | ||
| */ | ||
| WxDeviceBindResult bind(WxDeviceBind wxDeviceBind) throws WxErrorException; | ||
|
|
||
| /** | ||
| * <pre> | ||
| * 强制绑定用户和设备 | ||
| * 详情请见:http://iot.weixin.qq.com/wiki/new/index.html?page=3-4-7 | ||
| * </pre> | ||
| * @param wxDeviceBind 强制绑定请求对象 | ||
| * @return WxDeviceBindResult | ||
| */ | ||
| WxDeviceBindResult compelBind(WxDeviceBind wxDeviceBind) throws WxErrorException; | ||
|
|
||
| /** | ||
| * <pre> | ||
| * 第三方确认用户和设备的解绑操作 | ||
| * 详情请见:http://iot.weixin.qq.com/wiki/new/index.html/page=3-4-7 | ||
| * </pre> | ||
| * @param wxDeviceBind 绑定请求对象 | ||
| * @return WxDeviceBidResult | ||
| */ | ||
| WxDeviceBindResult unbind(WxDeviceBind wxDeviceBind) throws WxErrorException; | ||
|
|
||
| /** | ||
| * <pre> | ||
| * 强制解绑用户和设备 | ||
| * 详情请见:http://iot.weixin.qq.com/wiki/new/index.html?page=3-4-7 | ||
| * </pre> | ||
| * @param wxDeviceBind 强制解绑请求对象 | ||
| * @return WxDeviceBindResult | ||
| */ | ||
| WxDeviceBindResult compelUnbind(WxDeviceBind wxDeviceBind) throws WxErrorException; | ||
|
|
||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpDeviceServiceImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| package me.chanjar.weixin.mp.api.impl; | ||
|
|
||
| import me.chanjar.weixin.common.exception.WxErrorException; | ||
| import me.chanjar.weixin.mp.api.WxMpDeviceService; | ||
| import me.chanjar.weixin.mp.api.WxMpService; | ||
| import me.chanjar.weixin.mp.bean.device.*; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** | ||
| * Created by keungtung on 10/12/2016. | ||
| */ | ||
| public class WxMpDeviceServiceImpl implements WxMpDeviceService { | ||
| private static final String API_URL_PREFIX = "https://api.weixin.qq.com/device"; | ||
| private static Logger log = LoggerFactory.getLogger(WxMpMenuServiceImpl.class); | ||
|
|
||
| private WxMpService wxMpService; | ||
|
|
||
| WxMpDeviceServiceImpl(WxMpService wxMpService) { | ||
| this.wxMpService = wxMpService; | ||
| } | ||
|
|
||
| @Override | ||
| public TransMsgResp transMsg(WxDeviceMsg msg) throws WxErrorException { | ||
| String url = API_URL_PREFIX + "/transmsg"; | ||
| String response = this.wxMpService.post(url,msg.toJson()); | ||
| return TransMsgResp.fromJson(response); | ||
| } | ||
|
|
||
| @Override | ||
| public WxDeviceQrCodeResult getQrCode(String productId) throws WxErrorException { | ||
| String url = API_URL_PREFIX + "/getqrcode"; | ||
| String response = this.wxMpService.get(url, "product_id=" + productId); | ||
| return WxDeviceQrCodeResult.fromJson(response); | ||
| } | ||
|
|
||
| @Override | ||
| public WxDeviceAuthorizeResult authorize(WxDeviceAuthorize wxDeviceAuthorize) throws WxErrorException { | ||
| String url = API_URL_PREFIX + "/authorize_device"; | ||
| String response = this.wxMpService.post(url,wxDeviceAuthorize.toJson()); | ||
| return WxDeviceAuthorizeResult.fromJson(response); | ||
| } | ||
|
|
||
| @Override | ||
| public WxDeviceBindResult bind(WxDeviceBind wxDeviceBind) throws WxErrorException { | ||
| String url = API_URL_PREFIX + "/bind"; | ||
| String response = this.wxMpService.post(url,wxDeviceBind.toJson()); | ||
| return WxDeviceBindResult.fromJson(response); | ||
| } | ||
|
|
||
| @Override | ||
| public WxDeviceBindResult compelBind(WxDeviceBind wxDeviceBind) throws WxErrorException { | ||
| String url = API_URL_PREFIX + "/compel_bind"; | ||
| String response = this.wxMpService.post(url,wxDeviceBind.toJson()); | ||
| return WxDeviceBindResult.fromJson(response); | ||
| } | ||
|
|
||
| @Override | ||
| public WxDeviceBindResult unbind(WxDeviceBind wxDeviceBind) throws WxErrorException { | ||
| String url = API_URL_PREFIX + "/unbind?"; | ||
| String response = this.wxMpService.post(url, wxDeviceBind.toJson()); | ||
| return WxDeviceBindResult.fromJson(response); | ||
| } | ||
|
|
||
| @Override | ||
| public WxDeviceBindResult compelUnbind(WxDeviceBind wxDeviceBind) throws WxErrorException { | ||
| String url = API_URL_PREFIX + "/compel_unbind?"; | ||
| String response = this.wxMpService.post(url, wxDeviceBind.toJson()); | ||
| return WxDeviceBindResult.fromJson(response); | ||
| } | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/AbstractDeviceBean.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package me.chanjar.weixin.mp.bean.device; | ||
|
|
||
| import me.chanjar.weixin.common.util.json.WxGsonBuilder; | ||
|
|
||
| /** | ||
| * Created by keungtung on 14/12/2016. | ||
| */ | ||
| public abstract class AbstractDeviceBean { | ||
| public String toJson() { | ||
| return WxGsonBuilder.create().toJson(this); | ||
| } | ||
| } |
55 changes: 55 additions & 0 deletions
55
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/BaseResp.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package me.chanjar.weixin.mp.bean.device; | ||
|
|
||
| /** | ||
| * Created by keungtung on 10/12/2016. | ||
| */ | ||
| public class BaseResp extends AbstractDeviceBean{ | ||
| private BaseInfo base_info; | ||
| private Integer errcode; | ||
| private String errmsg; | ||
|
|
||
| public Integer getErrcode() { | ||
| return errcode; | ||
| } | ||
|
|
||
| public void setErrcode(Integer errcode) { | ||
| this.errcode = errcode; | ||
| } | ||
|
|
||
| public BaseInfo getBase_info() { | ||
| return base_info; | ||
| } | ||
|
|
||
| public void setBase_info(BaseInfo base_info) { | ||
| this.base_info = base_info; | ||
| } | ||
|
|
||
| public String getErrmsg() { | ||
| return errmsg; | ||
| } | ||
|
|
||
| public void setErrmsg(String errmsg) { | ||
| this.errmsg = errmsg; | ||
| } | ||
|
|
||
| private class BaseInfo { | ||
| private String device_type; | ||
| private String device_id; | ||
|
|
||
| public String getDevice_type() { | ||
| return device_type; | ||
| } | ||
|
|
||
| public void setDevice_type(String device_type) { | ||
| this.device_type = device_type; | ||
| } | ||
|
|
||
| public String getDevice_id() { | ||
| return device_id; | ||
| } | ||
|
|
||
| public void setDevice_id(String device_id) { | ||
| this.device_id = device_id; | ||
| } | ||
| } | ||
| } | ||
26 changes: 26 additions & 0 deletions
26
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/RespMsg.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package me.chanjar.weixin.mp.bean.device; | ||
|
|
||
| /** | ||
| * Created by keungtung on 10/12/2016. | ||
| */ | ||
|
|
||
| public class RespMsg extends AbstractDeviceBean{ | ||
| private Integer retCode; | ||
| private String errorInfo; | ||
|
|
||
| public Integer getRetCode() { | ||
| return retCode; | ||
| } | ||
|
|
||
| public void setRetCode(Integer retCode) { | ||
| this.retCode = retCode; | ||
| } | ||
|
|
||
| public String getErrorInfo() { | ||
| return errorInfo; | ||
| } | ||
|
|
||
| public void setErrorInfo(String errorInfo) { | ||
| this.errorInfo = errorInfo; | ||
| } | ||
| } |
49 changes: 49 additions & 0 deletions
49
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/device/TransMsgResp.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package me.chanjar.weixin.mp.bean.device; | ||
|
|
||
| import me.chanjar.weixin.common.util.json.WxGsonBuilder; | ||
|
|
||
| /** | ||
| * Created by keungtung on 14/12/2016. | ||
| */ | ||
| public class TransMsgResp extends AbstractDeviceBean{ | ||
| private Integer ret; | ||
| private String ret_info; | ||
| private Integer errcode; | ||
| private String errmsg; | ||
|
|
||
| public static TransMsgResp fromJson(String json) { | ||
| return WxGsonBuilder.create().fromJson(json, TransMsgResp.class); | ||
| } | ||
|
|
||
| public Integer getRet() { | ||
| return ret; | ||
| } | ||
|
|
||
| public void setRet(Integer ret) { | ||
| this.ret = ret; | ||
| } | ||
|
|
||
| public String getRet_info() { | ||
| return ret_info; | ||
| } | ||
|
|
||
| public void setRet_info(String ret_info) { | ||
| this.ret_info = ret_info; | ||
| } | ||
|
|
||
| public Integer getErrcode() { | ||
| return errcode; | ||
| } | ||
|
|
||
| public void setErrcode(Integer errcode) { | ||
| this.errcode = errcode; | ||
| } | ||
|
|
||
| public String getErrmsg() { | ||
| return errmsg; | ||
| } | ||
|
|
||
| public void setErrmsg(String errmsg) { | ||
| this.errmsg = errmsg; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这种不规范的命名能否做个重构?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
您是说变量名中有下划线,而没有使用驼峰命名?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没错