8000 Merge pull request #83 from johnnytung/develop · binarywang/WxJava@fd4505d · GitHub
[go: up one dir, main page]

Skip to content

Commit fd4505d

Browse files
authored
Merge pull request #83 from johnnytung/develop
增加对微信硬件平台事件消息的支持
2 parents 1bc2a5c + a26715c commit fd4505d

File tree

2 files changed

+122
-5
lines changed

2 files changed

+122
-5
lines changed

weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxConsts.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,13 @@ public class WxConsts {
1818
public static final String XML_MSG_LOCATION = "location";
1919
public static final String XML_MSG_LINK = "link";
2020
public static final String XML_MSG_EVENT = "event";
21+
public static final String XML_MSG_DEVICE_TEXT = "device_text";
22+
public static final String XML_MSG_DEVICE_EVENT = "device_event";
23+
public static final String XML_MSG_DEVICE_STATUS = "device_status";
24+
public static final String XML_MSG_HARDWARE = "hardware";
2125
public static final String XML_TRANSFER_CUSTOMER_SERVICE = "transfer_customer_service";
2226

27+
2328
///////////////////////
2429
// 主动发送消息(即客服消息)的消息类型
2530
///////////////////////

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessage.java

Lines changed: 117 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,81 @@ public class WxMpXmlMessage implements Serializable {
263263
@XStreamAlias("FailReason")
264264
private String failReason;
265265

266+
267+
///////////////////////////////////////
268+
// 微信硬件平台相关事件推送
269+
///////////////////////////////////////
270+
/**
271+
* 设备类型,目前为"公众账号原始ID"
272+
*/
273+
@XStreamAlias("DeviceType")
274+
@XStreamConverter(value = XStreamCDataConverter.class)
275+
private String deviceType;
276+
277+
/**
278+
* 设备ID,第三方提供
279+
*/
280+
@XStreamAlias("DeviceId")
281+
@XStreamConverter(value = XStreamCDataConverter.class)
282+
private String deviceId;
283+
284+
285+
@XStreamAlias("HardWare")
286+
private HardWare hardWare = new HardWare();
287+
288+
/**
289+
* 请求类型:0:退订设备状态;1:心跳;(心跳的处理方式跟订阅一样)2:订阅设备状态
290+
*/
291+
@XStreamAlias("OpType")
292+
private Integer opType;
293+
294+
/**
295+
* 设备状态:0:未连接;1:已连接
296+
*/
297+
@XStreamAlias("DeviceStatus")
298+
private Integer deviceStatus;
299+
300+
public Integer getOpType() {
301+
return opType;
302+
}
303+
304+
public void setOpType(Integer opType) {
305+
this.opType = opType;
306+
}
307+
308+
public Integer getDeviceStatus() {
309+
310+
return deviceStatus;
311+
}
312+
313+
public void setDeviceStatus(Integer deviceStatus) {
314+
this.deviceStatus = deviceStatus;
315+
}
316+
317+
public HardWare getHardWare() {
318+
return hardWare;
319+
}
320+
321+
public void setHardWare(HardWare hardWare) {
322< D7AE /td>+
this.hardWare = hardWare;
323+
}
324+
325+
public String getDeviceType() {
326+
return deviceType;
327+
}
328+
329+
public void setDeviceType(String deviceType) {
330+
this.deviceType = deviceType;
331+
}
332+
333+
public String getDeviceId() {
334+
return deviceId;
335+
}
336+
337+
public void setDeviceId(String deviceId) {
338+
this.deviceId = deviceId;
339+
}
340+
266341
public Long getExpiredTime() {
267342
return this.expiredTime;
268343
}
@@ -346,7 +421,6 @@ public void setCreateTime(Long createTime) {
346421
* {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_LINK}
347422
* {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_EVENT}
348423
* </pre>
349-
*
350424
*/
351425
public String getMsgType() {
352426
return this.msgType;
@@ -555,17 +629,17 @@ public static WxMpXmlMessage fromXml(InputStream is) {
555629
* @param msgSignature
556630
*/
557631
public static WxMpXmlMessage fromEncryptedXml(String encryptedXml,
558-
WxMpConfigStorage wxMpConfigStorage, String timestamp, String nonce,
559-
String msgSignature) {
632+
WxMpConfigStorage wxMpConfigStorage, String timestamp, String nonce,
633+
String msgSignature) {
560634
WxMpCryptUtil cryptUtil = new WxMpCryptUtil(wxMpConfigStorage);
561635
String plainText = cryptUtil.decrypt(msgSignature, timestamp, nonce,
562636
encryptedXml);
563637
return fromXml(plainText);
564638
}
565639

566640
public static WxMpXmlMessage fromEncryptedXml(InputStream is,
567-
WxMpConfigStorage wxMpConfigStorage, String timestamp, String nonce,
568-
String msgSignature) {
641+
WxMpConfigStorage wxMpConfigStorage, String timestamp, String nonce,
642+
String msgSignature) {
569643
try {
570644
return fromEncryptedXml(IOUtils.toString(is, "UTF-8"), wxMpConfigStorage,
571645
timestamp, nonce, msgSignature);
@@ -719,6 +793,44 @@ public void setFromKfAccount(String fromKfAccount) {
719793
this.fromKfAccount = fromKfAccount;
720794
}
721795

796+
@XStreamAlias("HardWare")
797+
public static class HardWare {
798+
@Override
799+
public String toString() {
800+
return ToStringUtils.toSimpleString(this);
801+
}
802+
803+
/**
804+
* 消息展示,目前支持myrank(排行榜)
805+
*/
806+
@XStreamAlias("MessageView")
807+
@XStreamConverter(value = XStreamCDataConverter.class)
808+
private String messageView;
809+
810+
/**
811+
* 消息点击动作,目前支持ranklist(点击跳转排行榜)
812+
*/
813+
@XStreamAlias("MessageAction")
814+
@XStreamConverter(value = XStreamCDataConverter.class)
815+
private String messageAction;
816+
817+
public String getMessageView() {
818+
return messageView;
819+
}
820+
821+
public void setMessageView(String messageView) {
822+
this.messageView = messageView;
823+
}
824+
825+
public String getMessageAction() {
826+
return messageAction;
827+
}
828+
829+
public void setMessageAction(String messageAction) {
830+
this.messageAction = messageAction;
831+
}
832+
}
833+
722834
@XStreamAlias("ScanCodeInfo")
723835
public static class ScanCodeInfo {
724836
@Override

0 commit comments

Comments
 (0)
0