Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,24 @@ public interface WxMpDeviceService {
*/
WxDeviceBindResult compelUnbind(WxDeviceBind wxDeviceBind) throws WxErrorException;

/**
* <pre>
* 通过device type和device id 获取设备主人的openid
* 详情请见:http://iot.weixin.qq.com/wiki/new/index.html?page=3-4-11
* </pre>
* @param deviceType 设备类型,目前为"公众账号原始ID"
* @param deviceId 设备ID
* @return WxDeviceOpenIdResult
*/
WxDeviceOpenIdResult getOpenId(String deviceType,String deviceId) throws WxErrorException;

/**
* <pre>
* 通过openid获取用户在当前devicetype下绑定的deviceid列表`
* 详情请见:http://iot.weixin.qq.com/wiki/new/index.html?page=3-4-12
* </pre>
* @param openId 要查询的用户的openid
* @return WxDeviceBindDeviceResult
*/
WxDeviceBindDeviceResult getBindDevice(String openId) throws WxErrorException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class WxMpDeviceServiceImpl implements WxMpDeviceService {
@Override
public TransMsgResp transMsg(WxDeviceMsg msg) throws WxErrorException {
String url = API_URL_PREFIX + "/transmsg";
String response = this.wxMpService.post(url,msg.toJson());
String response = this.wxMpService.post(url, msg.toJson());
return TransMsgResp.fromJson(response);
}

Expand All @@ -37,21 +37,21 @@ public WxDeviceQrCodeResult getQrCode(String productId) throws WxErrorException
@Override
public WxDeviceAuthorizeResult authorize(WxDeviceAuthorize wxDeviceAuthorize) throws WxErrorException {
String url = API_URL_PREFIX + "/authorize_device";
String response = this.wxMpService.post(url,wxDeviceAuthorize.toJson());
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());
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());
String response = this.wxMpService.post(url, wxDeviceBind.toJson());
return WxDeviceBindResult.fromJson(response);
}

Expand All @@ -68,5 +68,19 @@ public WxDeviceBindResult compelUnbind(WxDeviceBind wxDeviceBind) throws WxError
String response = this.wxMpService.post(url, wxDeviceBind.toJson());
return WxDeviceBindResult.fromJson(response);
}

@Override
public WxDeviceOpenIdResult getOpenId(String deviceType, String deviceId) throws WxErrorException {
String url = API_URL_PREFIX + "/get_openid";
String response = this.wxMpService.get(url, "device_type=" + deviceType + "&device_id=" + deviceId);
return WxDeviceOpenIdResult.fromJson(response);
}

@Override
public WxDeviceBindDeviceResult getBindDevice(String openId) throws WxErrorException {
String url = API_URL_PREFIX+"/get_bind_device";
String response = this.wxMpService.get(url,"openid="+openId);
return WxDeviceBindDeviceResult.fromJson(response);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,25 @@ public void setErrMsg(String errMsg) {
}

private class BaseInfo {
private String device_type;
private String device_id;
@SerializedName("device_type")
private String deviceType;
@SerializedName("device_id")
private String deviceId;

public String getDevice_type() {
return device_type;
public String getDeviceType() {
return deviceType;
}

public void setDevice_type(String device_type) {
this.device_type = device_type;
public void setDeviceType(String deviceType) {
this.deviceType = deviceType;
}

public String getDevice_id() {
return device_id;
public String getDeviceId() {
return deviceId;
}

public void setDevice_id(String device_id) {
this.device_id = device_id;
public void setDeviceId(String deviceId) {
this.deviceId = deviceId;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package me.chanjar.weixin.mp.bean.device;

import com.google.gson.annotations.SerializedName;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;

import java.util.List;

/**
* Created by keungtung on 16/12/2016.
*/
public class WxDeviceBindDeviceResult extends AbstractDeviceBean {
@SerializedName("resp_msg")
private RespMsg respMsg;
@SerializedName("openid")
private String openId;
@SerializedName("device_list")
private List<Device> devices;

public static WxDeviceBindDeviceResult fromJson(String json) {
return WxMpGsonBuilder.create().fromJson(json, WxDeviceBindDeviceResult.class);
}

private class Device {
@SerializedName("device_type")
private String deviceType;
@SerializedName("device_id")
private String deviceId;

public String getDeviceType() {
return deviceType;
}

public void setDeviceType(String deviceType) {
this.deviceType = deviceType;
}

public String getDeviceId() {
return deviceId;
}

public void setDeviceId(String deviceId) {
this.deviceId = deviceId;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package me.chanjar.weixin.mp.bean.device;

import com.google.gson.annotations.SerializedName;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;

import java.util.List;

/**
* Created by keungtung on 16/12/2016.
*/
public class WxDeviceOpenIdResult extends AbstractDeviceBean {
@SerializedName("errcode")
private Integer errCode;
@SerializedName("errmsg")
private String errMsg;
@SerializedName("open_id")
private List<String> openIds;
@SerializedName("resp_msg")
private RespMsg respMsg;

public static WxDeviceOpenIdResult fromJson(String json) {
return WxMpGsonBuilder.create().fromJson(json, WxDeviceOpenIdResult.class);
}

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

public List<String> getOpenIds() {
return openIds;
}

public void setOpenIds(List<String> openIds) {
this.openIds = openIds;
}

public RespMsg getRespMsg() {
return respMsg;
}

public void setRespMsg(RespMsg respMsg) {
this.respMsg = respMsg;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
/**
* Created by keungtung on 10/12/2016.
*/
public class WxDeviceQrCodeResult extends AbstractDeviceBean{
public class WxDeviceQrCodeResult extends AbstractDeviceBean {
@SerializedName("deviceid")
private String deviceId;
@SerializedName("qrticket")
private String qrTicket;
@SerializedName("devicelicence")
private String deviceLicence;
@SerializedName("resp_msg")
private RespMsg respMsg;
@SerializedName("base_resp")
private BaseResp baseResp;

public static WxDeviceQrCodeResult fromJson(String json) {
return WxMpGsonBuilder.INSTANCE.create().fromJson(json, WxDeviceQrCodeResult.class);
Expand All @@ -28,12 +28,12 @@ public void setDeviceLicence(String deviceLicence) {
this.deviceLicence = deviceLicence;
}

public RespMsg getRespMsg() {
return respMsg;
public BaseResp getBaseResp() {
return baseResp;
}

public void setRespMsg(RespMsg respMsg) {
this.respMsg = respMsg;
public void setBaseResp(BaseResp baseResp) {
this.baseResp = baseResp;
}

public String getDeviceId() {
Expand Down