为Jfinal-weixin SDK添加微信连WiFi成功通知事件

1、在event包中添加InWifiConnectedEvent类:

package com.jfinal.weixin.sdk.msg.in.event;

import com.jfinal.weixin.sdk.msg.in.InMsg;

/**
 通过微信连Wi-Fi连网成功后会触发事件推送,
 该事件将发送至开发者填写的URL(登录公众平台进入开发者中心设置)。
 开发者可通过事件推送获取连网相关信息、数据统计等操作。
 <xml>
     <ToUserName><![CDATA[toUser]]></ToUserName>
     <FromUserName><![CDATA[FromUser]]></FromUserName>
     <CreateTime>123456789</CreateTime>
     <MsgType><![CDATA[event]]></MsgType>
     <Event><![CDATA[WifiConnected]]></Event>
     <ConnectTime>0</ConnectTime>
     <ExpireTime>0</ExpireTime>
     <VendorId>![CDATA[3001224419]]</VendorId>
     <PlaceId>![CDATA[PlaceId]]</PlaceId>
     <DeviceNo>![CDATA[DeviceNo]]</DeviceNo>
 </xml>
 */
public class InWifiConnectedEvent extends InMsg {

    private String event;

    private Integer connectTime;//用户联网时间
    private String expireTime;//系统保留字
    private String vendorId;//系统保留字
    private Integer placeId;//设备所属的门店id
    private String deviceNo;//设备的mac地址

    public InWifiConnectedEvent(String toUserName, String fromUserName, Integer createTime, String msgType) {
        super(toUserName, fromUserName, createTime, msgType);
    }

    public String getEvent() {
        return event;
    }

    public void setEvent(String event) {
        this.event = event;
    }

    public Integer getConnectTime() {
        return connectTime;
    }

    public void setConnectTime(Integer connectTime) {
        this.connectTime = connectTime;
    }

    public String getExpireTime() {
        return expireTime;
    }

    public void setExpireTime(String expireTime) {
        this.expireTime = expireTime;
    }

    public String getVendorId() {
        return vendorId;
    }

    public void setVendorId(String vendorId) {
        this.vendorId = vendorId;
    }

    public Integer getPlaceId() {
        return placeId;
    }

    public void setPlaceId(Integer placeId) {
        this.placeId = placeId;
    }

    public String getDeviceNo() {
        return deviceNo;
    }

    public void setDeviceNo(String deviceNo) {
        this.deviceNo = deviceNo;
    }
}

2、扩展InMsgParaser类的parseInEvent方法:

//微信连WiFi成功通知事件
if ("WifiConnected".equals(event)){
   InWifiConnectedEvent e=new InWifiConnectedEvent(toUserName,fromUserName,createTime,msgType);
   e.setEvent(event);
   e.setConnectTime(Integer.parseInt(root.elementText("ConnectTime")));
   e.setExpireTime(root.elementText("ExpireTime"));
   e.setVendorId(root.elementText("VendorId"));
   e.setPlaceId(Integer.parseInt(root.elementText("PlaceId")));
   e.setDeviceNo(root.elementText("PlaceId"));
   return e;
}

3、继续扩展MsgController类,添加processInWifiConnectedEvent抽象方法:

protected abstract void processInWifiConnectedEvent(InWifiConnectedEvent inWifiConnectedEvent);

在其index方法中添加:

else  if (msg instanceof InWifiConnectedEvent)
   processInWifiConnectedEvent((InWifiConnectedEvent) msg);

5、在WeixinMsgController控制器中实现上一步的抽象方法:

@Override
protected void processInWifiConnectedEvent(InWifiConnectedEvent inWifiConnectedEvent) {
   System.out.println("WiFi连接成功通知事件");
}


为Jfinal-weixin SDK添加微信连WiFi成功通知事件

上一篇:微信开发三【获取access_token储存机制】


下一篇:达沃时代的VNAS为NAS使用提供一种新可能