1、在event包中添加AroundBeacon类:
package com.jfinal.weixin.sdk.msg.in.event;
public class AroundBeacon {
private String uuid;
private Integer major;
private Integer minor;
private Float distance;//设备与用户的距离(浮点数;单位:米)
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public Integer getMajor() {
return major;
}
public void setMajor(Integer major) {
this.major = major;
}
public Integer getMinor() {
return minor;
}
public void setMinor(Integer minor) {
this.minor = minor;
}
public Float getDistance() {
return distance;
}
public void setDistance(Float distance) {
this.distance = distance;
}
}
2、在event包中添加InShakearoundUserShakeEvent:
package com.jfinal.weixin.sdk.msg.in.event;
import com.jfinal.weixin.sdk.msg.in.InMsg;
import java.util.ArrayList;
import java.util.List;
/**
* 用户进入摇一摇界面,在“周边”页卡下摇一摇时,
* 微信会把这个事件推送到开发者填写的URL(登录公众平台进入开发者中心设置)。
* 推送内容包含摇一摇时“周边”页卡展示出来的页面所对应的设备信息,
* 以及附近最多五个属于该公众账号的设备的信息。
<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>1433332012</CreateTime>
<MsgType><![CDATA[event]]></MsgType>
<Event><![CDATA[ShakearoundUserShake]]></Event>
<ChosenBeacon>
<Uuid><![CDATA[uuid]]></Uuid>
<Major>major</Major>
<Minor>minor</Minor>
<Distance>0.057</Distance>
</ChosenBeacon>
<AroundBeacons>
<AroundBeacon>
<Uuid><![CDATA[uuid]]></Uuid>
<Major>major</Major>
<Minor>minor</Minor>
<Distance>166.816</Distance>
</AroundBeacon>
<AroundBeacon>
<Uuid><![CDATA[uuid]]></Uuid>
<Major>major</Major>
<Minor>minor</Minor>
<Distance>15.013</Distance>
</AroundBeacon>
</AroundBeacons>
</xml>
*/
public class InShakearoundUserShakeEvent extends InMsg {
private String event;//事件
private String uuid;
private Integer major;
private Integer minor;
private Float distance;//设备与用户的距离(浮点数;单位:米)
private List<AroundBeacon> aroundBeaconList=new ArrayList<AroundBeacon>();
public InShakearoundUserShakeEvent(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 String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public Integer getMajor() {
return major;
}
public void setMajor(Integer major) {
this.major = major;
}
public Integer getMinor() {
return minor;
}
public void setMinor(Integer minor) {
this.minor = minor;
}
public Float getDistance() {
return distance;
}
public void setDistance(Float distance) {
this.distance = distance;
}
public List<AroundBeacon> getAroundBeaconList() {
return aroundBeaconList;
}
public void setAroundBeaconList(List<AroundBeacon> aroundBeaconList) {
this.aroundBeaconList = aroundBeaconList;
}
}
3、扩展InMsgParaser类的parseInEvent方法:
if ("ShakearoundUserShake".equals(event)){
InShakearoundUserShakeEvent e=new InShakearoundUserShakeEvent(toUserName,fromUserName,createTime,msgType);
e.setEvent(event);
Element c=root.element("ChosenBeacon");
e.setUuid(c.elementText("Uuid"));
e.setMajor(Integer.parseInt(c.elementText("Major")));
e.setMinor(Integer.parseInt(c.elementText("Minor")));
e.setDistance(Float.parseFloat(c.elementText("Distance")));
List list=root.elements("AroundBeacon");
if (list!=null && list.size()>0){
AroundBeacon aroundBeacon=null;
List<AroundBeacon> aroundBeacons=new ArrayList<AroundBeacon>();
for (Iterator it = list.iterator(); it.hasNext();) {
Element elm = (Element) it.next();
aroundBeacon=new AroundBeacon();
aroundBeacon.setUuid(elm.elementText("Uuid"));
aroundBeacon.setMajor(Integer.parseInt(elm.elementText("Major")));
aroundBeacon.setMinor(Integer.parseInt(elm.elementText("Minor")));
aroundBeacon.setDistance(Float.parseFloat(elm.elementText("Distance")));
aroundBeacons.add(aroundBeacon);
}
e.setAroundBeaconList(aroundBeacons);
}
return e;
}
4、为MsgController添加processInShakearoundUserShakeEvent抽象方法:
protected abstract void processInShakearoundUserShakeEvent(InShakearoundUserShakeEvent inShakearoundUserShakeEvent);
在其index方法中扩展:
else if (msg instanceof InShakearoundUserShakeEvent)
processInShakearoundUserShakeEvent((InShakearoundUserShakeEvent)msg);
5、WeixinMsgController类中实现摇一摇抽象方法:
@Override
protected void processInShakearoundUserShakeEvent(InShakearoundUserShakeEvent inShakearoundUserShakeEvent) {
System.out.println("摇一摇周边设备信息通知事件");
}
代码写的一般,望见谅,不过我测试过,可以使用滴。