diff --git a/src/main/java/me/chanjar/weixin/api/WxConsts.java b/src/main/java/me/chanjar/weixin/api/WxConsts.java index 317806fa..f2152428 100644 --- a/src/main/java/me/chanjar/weixin/api/WxConsts.java +++ b/src/main/java/me/chanjar/weixin/api/WxConsts.java @@ -78,9 +78,15 @@ public class WxConsts { public static final String EVT_UNSUBSCRIBE = "unsubscribe"; public static final String EVT_SCAN = "SCAN"; public static final String EVT_LOCATION = "LOCATION"; - public static final String EVT_CLICK = "LOCATION"; + public static final String EVT_CLICK = "CLICK"; public static final String EVT_VIEW = "VIEW"; public static final String EVT_MASS_SEND_JOB_FINISH = "MASSSENDJOBFINISH"; + public static final String EVT_SCANCODE_PUSH = "scancode_push"; + public static final String EVT_SCANCODE_WAITMSG = "scancode_waitmsg"; + public static final String EVT_PIC_SYSPHOTO = "pic_sysphoto"; + public static final String EVT_PIC_PHOTO_OR_ALBUM = "pic_photo_or_album"; + public static final String EVT_PIC_WEIXIN = "pic_weixin"; + public static final String EVT_LOCATION_SELECT = "location_select"; /////////////////////// // 上传多媒体文件的类型 @@ -98,4 +104,25 @@ public class WxConsts { public static final String FILE_ARM = "arm"; public static final String FILE_MP4 = "mp4"; + + /////////////////////// + // 自定义菜单的按钮类型 + /////////////////////// + /** 点击推事件 */ + public static final String BUTTON_CLICK = "click"; + /** 跳转URL */ + public static final String BUTTON_VIEW = "view"; + /** 扫码推事件 */ + public static final String BUTTON_SCANCODE_PUSH = "scancode_push"; + /** 扫码推事件且弹出“消息接收中”提示框 */ + public static final String BUTTON_SCANCODE_WAITMSG = "scancode_waitmsg"; + /** 弹出系统拍照发图 */ + public static final String PIC_SYSPHOTO = "pic_sysphoto"; + /** 弹出拍照或者相册发图 */ + public static final String PIC_PHOTO_OR_ALBUM = "pic_photo_or_album"; + /** 弹出微信相册发图器 */ + public static final String PIC_WEIXIN = "pic_weixin"; + /** 弹出地理位置选择器 */ + public static final String LOCATION_SELECT = "location_select"; + } diff --git a/src/main/java/me/chanjar/weixin/bean/WxXmlMessage.java b/src/main/java/me/chanjar/weixin/bean/WxXmlMessage.java index 67fe1bbd..97a8e3a6 100644 --- a/src/main/java/me/chanjar/weixin/bean/WxXmlMessage.java +++ b/src/main/java/me/chanjar/weixin/bean/WxXmlMessage.java @@ -8,13 +8,12 @@ import me.chanjar.weixin.util.xml.XmlTransformer; import org.apache.commons.io.IOUtils; import javax.xml.bind.JAXBException; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.*; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; /** *
@@ -149,6 +148,15 @@ public class WxXmlMessage {
    */
   private Integer ErrorCount;
 
+  @XmlElement(name = "ScanCodeInfo")
+  private ScanCodeInfo ScanCodeInfo = new ScanCodeInfo();
+
+  @XmlElement(name = "SendPicsInfo")
+  private SendPicsInfo SendPicsInfo = new SendPicsInfo();
+
+  @XmlElement(name = "SendLocationInfo")
+  private SendLocationInfo SendLocationInfo = new SendLocationInfo();
+
   public String getToUserName() {
     return ToUserName;
   }
@@ -454,4 +462,173 @@ public class WxXmlMessage {
     ErrorCount = errorCount;
   }
 
+  public WxXmlMessage.ScanCodeInfo getScanCodeInfo() {
+    return ScanCodeInfo;
+  }
+
+  public void setScanCodeInfo(WxXmlMessage.ScanCodeInfo scanCodeInfo) {
+    ScanCodeInfo = scanCodeInfo;
+  }
+
+  public WxXmlMessage.SendPicsInfo getSendPicsInfo() {
+    return SendPicsInfo;
+  }
+
+  public void setSendPicsInfo(WxXmlMessage.SendPicsInfo sendPicsInfo) {
+    SendPicsInfo = sendPicsInfo;
+  }
+
+  public WxXmlMessage.SendLocationInfo getSendLocationInfo() {
+    return SendLocationInfo;
+  }
+
+  public void setSendLocationInfo(WxXmlMessage.SendLocationInfo sendLocationInfo) {
+    SendLocationInfo = sendLocationInfo;
+  }
+
+  @XmlRootElement(name = "ScanCodeInfo")
+  @XmlAccessorType(XmlAccessType.FIELD)
+  public static class ScanCodeInfo {
+
+    @XmlElement(name = "ScanType")
+    @XmlJavaTypeAdapter(AdapterCDATA.class)
+    private String ScanType;
+
+    @XmlElement(name = "ScanResult")
+    @XmlJavaTypeAdapter(AdapterCDATA.class)
+    private String ScanResult;
+
+    /**
+     * 扫描类型,一般是qrcode
+     * @return
+     */
+    public String getScanType() {
+
+      return ScanType;
+    }
+
+    public void setScanType(String scanType) {
+      ScanType = scanType;
+    }
+
+    /**
+     * 扫描结果,即二维码对应的字符串信息
+     * @return
+     */
+    public String getScanResult() {
+      return ScanResult;
+    }
+
+    public void setScanResult(String scanResult) {
+      ScanResult = scanResult;
+    }
+
+  }
+
+  @XmlRootElement(name = "SendPicsInfo")
+  @XmlAccessorType(XmlAccessType.FIELD)
+  public static class SendPicsInfo {
+
+    private Long Count;
+
+    @XmlElementWrapper(name="PicList")
+    @XmlElement(name = "item")
+    protected final List PicList = new ArrayList();
+
+    public Long getCount() {
+      return Count;
+    }
+
+    public void setCount(Long count) {
+      Count = count;
+    }
+
+    public List getPicList() {
+      return PicList;
+    }
+
+    @XmlRootElement(name = "item")
+    @XmlAccessorType(XmlAccessType.FIELD)
+    @XmlType(name = "me.chanjar.weixin.bean.WxXmlMessage.SendPicsInfo.Item")
+    public static class Item {
+
+      @XmlElement(name = "PicMd5Sum")
+      @XmlJavaTypeAdapter(AdapterCDATA.class)
+      private String PicMd5Sum;
+
+      public String getPicMd5Sum() {
+        return PicMd5Sum;
+      }
+
+      public void setPicMd5Sum(String picMd5Sum) {
+        PicMd5Sum = picMd5Sum;
+      }
+    }
+  }
+
+  @XmlRootElement(name = "SendLocationInfo")
+  @XmlAccessorType(XmlAccessType.FIELD)
+  public static class SendLocationInfo {
+
+    @XmlElement(name = "Location_X")
+    @XmlJavaTypeAdapter(AdapterCDATA.class)
+    private String Location_X;
+
+    @XmlElement(name = "Location_Y")
+    @XmlJavaTypeAdapter(AdapterCDATA.class)
+    private String Location_Y;
+
+    @XmlElement(name = "Scale")
+    @XmlJavaTypeAdapter(AdapterCDATA.class)
+    private String Scale;
+
+    @XmlElement(name = "Label")
+    @XmlJavaTypeAdapter(AdapterCDATA.class)
+    private String Label;
+
+    @XmlElement(name = "Poiname")
+    @XmlJavaTypeAdapter(AdapterCDATA.class)
+    private String Poiname;
+
+    public String getLocation_X() {
+      return Location_X;
+    }
+
+    public void setLocation_X(String location_X) {
+      Location_X = location_X;
+    }
+
+    public String getLocation_Y() {
+      return Location_Y;
+    }
+
+    public void setLocation_Y(String location_Y) {
+      Location_Y = location_Y;
+    }
+
+    public String getScale() {
+      return Scale;
+    }
+
+    public void setScale(String scale) {
+      Scale = scale;
+    }
+
+    public String getLabel() {
+      return Label;
+    }
+
+    public void setLabel(String label) {
+      Label = label;
+    }
+
+    public String getPoiname() {
+      return Poiname;
+    }
+
+    public void setPoiname(String poiname) {
+      Poiname = poiname;
+    }
+  }
+
 }
diff --git a/src/test/java/me/chanjar/weixin/api/WxMenuAPITest.java b/src/test/java/me/chanjar/weixin/api/WxMenuAPITest.java
index f85f2ed4..72fc59a6 100644
--- a/src/test/java/me/chanjar/weixin/api/WxMenuAPITest.java
+++ b/src/test/java/me/chanjar/weixin/api/WxMenuAPITest.java
@@ -44,12 +44,12 @@ public class WxMenuAPITest {
   public Object[][] getMenu() throws JAXBException {
     WxMenu menu = new WxMenu();
     WxMenuButton button1 = new WxMenuButton();
-    button1.setType("click");
+    button1.setType(WxConsts.BUTTON_CLICK);
     button1.setName("今日歌曲");
     button1.setKey("V1001_TODAY_MUSIC");
     
     WxMenuButton button2 = new WxMenuButton();
-    button2.setType("click");
+    button2.setType(WxConsts.BUTTON_CLICK);
     button2.setName("歌手简介");
     button2.setKey("V1001_TODAY_SINGER");
     
@@ -61,17 +61,17 @@ public class WxMenuAPITest {
     menu.getButton().add(button3);
     
     WxMenuButton button31 = new WxMenuButton();
-    button31.setType("view");
+    button31.setType(WxConsts.BUTTON_VIEW);
     button31.setName("搜索");
     button31.setUrl("http://www.soso.com/");
     
     WxMenuButton button32 = new WxMenuButton();
-    button32.setType("view");
+    button32.setType(WxConsts.BUTTON_VIEW);
     button32.setName("视频");
     button32.setUrl("http://v.qq.com/");
     
     WxMenuButton button33 = new WxMenuButton();
-    button33.setType("click");
+    button33.setType(WxConsts.BUTTON_CLICK);
     button33.setName("赞一下我们");
     button33.setKey("V1001_GOOD");
     
diff --git a/src/test/java/me/chanjar/weixin/bean/WxXmlMessageTest.java b/src/test/java/me/chanjar/weixin/bean/WxXmlMessageTest.java
index 79ad7634..9a6691cc 100644
--- a/src/test/java/me/chanjar/weixin/bean/WxXmlMessageTest.java
+++ b/src/test/java/me/chanjar/weixin/bean/WxXmlMessageTest.java
@@ -33,6 +33,25 @@ public class WxXmlMessageTest {
                 + "23.137466"
                 + "113.352425"
                 + "119.385040"
+                + ""
+                + " "
+                + " "
+                + ""
+                + ""
+                + " 1\n"
+                + " "
+                + "  "
+                + "   "
+                + "  "
+                + " "
+                + ""
+                + ""
+                + "  \n"
+                + "  \n"
+                + "  \n"
+                + "  \n"
+                + "  \n"
+                + ""
                 + "";
     WxXmlMessage wxMessage = WxXmlMessage.fromXml(xml);
     Assert.assertEquals(wxMessage.getToUserName(), "toUser");
@@ -58,6 +77,15 @@ public class WxXmlMessageTest {
     Assert.assertEquals(wxMessage.getLatitude(), new Double(23.137466));
     Assert.assertEquals(wxMessage.getLongitude(), new Double(113.352425));
     Assert.assertEquals(wxMessage.getPrecision(), new Double(119.385040));
+    Assert.assertEquals(wxMessage.getScanCodeInfo().getScanType(), "qrcode");
+    Assert.assertEquals(wxMessage.getScanCodeInfo().getScanResult(), "1");
+    Assert.assertEquals(wxMessage.getSendPicsInfo().getCount(), new Long(1l));
+    Assert.assertEquals(wxMessage.getSendPicsInfo().getPicList().get(0).getPicMd5Sum(), "1b5f7c23b5bf75682a53e7b6d163e185");
+    Assert.assertEquals(wxMessage.getSendLocationInfo().getLocation_X(), "23");
+    Assert.assertEquals(wxMessage.getSendLocationInfo().getLocation_Y(), "113");
+    Assert.assertEquals(wxMessage.getSendLocationInfo().getScale(), "15");
+    Assert.assertEquals(wxMessage.getSendLocationInfo().getLabel(), " 广州市海珠区客村艺苑路 106号");
+    Assert.assertEquals(wxMessage.getSendLocationInfo().getPoiname(), "wo de poi");
   }
   
 }