一、在event包中添加AroundBeacon類:java
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; } }
二、在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; } }
三、擴展InMsgParaser類的parseInEvent方法:ide
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; }
四、爲MsgController添加processInShakearoundUserShakeEvent抽象方法:測試
protected abstract void processInShakearoundUserShakeEvent(InShakearoundUserShakeEvent inShakearoundUserShakeEvent);
在其index方法中擴展:ui
else if (msg instanceof InShakearoundUserShakeEvent) processInShakearoundUserShakeEvent((InShakearoundUserShakeEvent)msg);
五、WeixinMsgController類中實現搖一搖抽象方法:this
@Override protected void processInShakearoundUserShakeEvent(InShakearoundUserShakeEvent inShakearoundUserShakeEvent) { System.out.println("搖一搖周邊設備信息通知事件"); }
代碼寫的通常,望見諒,不過我測試過,能夠使用滴。
code