From d32cf99b6d315cc65d72f1337ab30c23b8149fff Mon Sep 17 00:00:00 2001 From: 007gzs <007gzs@gmail.com> Date: Tue, 14 Nov 2017 17:02:13 +0800 Subject: [PATCH] =?UTF-8?q?#376=20=E5=A2=9E=E5=8A=A0=E6=91=87=E4=B8=80?= =?UTF-8?q?=E6=91=87=E5=91=A8=E8=BE=B9=E7=9A=84=E9=83=A8=E5=88=86=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 774 +++++++++--------- .../weixin/common/util/crypto/ByteGroup.java | 52 +- .../common/util/crypto/PKCS7Encoder.java | 136 +-- .../weixin/mp/api/WxMpShakeService.java | 34 + .../mp/api/impl/WxMpShakeServiceImpl.java | 29 +- .../mp/bean/shake/WxMpDeviceIdentifier.java | 23 + .../WxMpShakeAroundDeviceBindPageQuery.java | 23 + .../shake/WxMpShakeAroundPageAddQuery.java | 23 + .../shake/WxMpShakeAroundPageAddResult.java | 26 + .../WxMpShakeAroundRelationSearchQuery.java | 32 + .../WxMpShakeAroundRelationSearchResult.java | 22 + 11 files changed, 692 insertions(+), 482 deletions(-) create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpDeviceIdentifier.java create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundDeviceBindPageQuery.java create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundPageAddQuery.java create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundPageAddResult.java create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundRelationSearchQuery.java create mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundRelationSearchResult.java diff --git a/pom.xml b/pom.xml index 2beb4488..54f52b02 100644 --- a/pom.xml +++ b/pom.xml @@ -1,387 +1,387 @@ - - - 4.0.0 - com.github.binarywang - weixin-java-parent - 2.8.8.BETA - pom - WeiXin Java Tools - Parent - 微信公众号、企业号上级POM - https://github.com/wechat-group/weixin-java-tools - - - - The Apache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - - - - - - Daniel Qian - chanjarster@gmail.com - https://github.com/chanjarster - - - Binary Wang - binarywang@gmail.com - https://github.com/binarywang - - - gaigeshen - gaigeshen@qq.com - https://github.com/gaigeshen - - - Liu Mingbo - liumingbo2008@gmail.com - https://github.com/FirenzesEagle - - - kakotor - kakotor@gmail.com - https://github.com/kakotor - - - xiong - zhaoxiong.tan@gmail.com - https://github.com/ZhaoxiongTan - - - LiuJunGuang - aimilin@yeah.net - https://github.com/aimilin6688 - - - Eric.Tsai - xiaodong.cai.ks@gmail.com - https://github.com/iwareserictsai - - - withinthefog - withinthefog@gmail.com - https://github.com/withinthefog - - - Keung - dongfuqiang1988@163.com - https://github.com/johnnytung - - - Jonk - aimilin@yeah.net - https://github.com/aimilin6688 - - - ecoolper - crskyp@gmail.com - https://github.com/crskyp - - - 007 - 007gzs@gmail.com - https://github.com/007gzs - - - - - scm:git:https://github.com/wechat-group/weixin-java-tools.git - scm:git:git@github.com:wechat-group/weixin-java-tools.git - https://github.com/wechat-group/weixin-java-tools - - - - weixin-java-common - weixin-java-cp - weixin-java-mp - weixin-java-pay - weixin-java-miniapp - weixin-java-open - - - - - 1.7 - 1.7 - - UTF-8 - true - true - 4.5 - 9.3.0.RC0 - - - - - - com.github.binarywang - qrcode-utils - 1.1 - - - - org.jodd - jodd-http - 3.7.1 - provided - - - com.squareup.okhttp3 - okhttp - 3.7.0 - provided - - - - org.apache.httpcomponents - httpclient - ${httpclient.version} - - - org.apache.httpcomponents - httpmime - ${httpclient.version} - - - commons-codec - commons-codec - 1.10 - - - commons-io - commons-io - 2.5 - - - org.apache.commons - commons-lang3 - 3.5 - - - org.slf4j - slf4j-api - 1.7.24 - - - com.thoughtworks.xstream - xstream - 1.4.9 - - - - com.google.guava - guava - 20.0 - - - com.google.code.gson - gson - 2.8.0 - - - - - joda-time - joda-time - 2.9.7 - test - - - ch.qos.logback - logback-classic - 1.1.11 - test - - - com.google.inject - guice - 3.0 - test - - - org.testng - testng - 6.10 - test - - - org.mockito - mockito-all - 1.9.5 - test - - - org.eclipse.jetty - jetty-server - ${jetty.version} - test - - - org.eclipse.jetty - jetty-servlet - ${jetty.version} - test - - - redis.clients - jedis - 2.9.0 - provided - - - org.projectlombok - lombok - 1.16.18 - compile - - - - - - - ossrh - https://oss.sonatype.org/content/repositories/snapshots - - - ossrh - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - - - - - doclint-java8-disable - - [1.8,) - - - -Xdoclint:none - - - - - release - - - - org.apache.maven.plugins - maven-source-plugin - 2.2.1 - - - attach-sources - - jar-no-fork - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.9.1 - - - attach-javadocs - - jar - - - - - ${javadoc.opts} - UTF-8 - zh_CN - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.6 - - - sign-artifacts - verify - - sign - - - - - - - - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.17 - - true - - - - - - - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.3 - true - - ossrh - https://oss.sonatype.org/ - true - - - - org.apache.maven.plugins - maven-release-plugin - 2.5.1 - - true - false - release - deploy - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.6.0 - - UTF-8 - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - 2.17 - - quality-checks/google_checks.xml - true - true - true - - - - verify - - check - - - - - - - - + + + 4.0.0 + com.github.binarywang + weixin-java-parent + 2.8.8.BETA + pom + WeiXin Java Tools - Parent + 微信公众号、企业号上级POM + https://github.com/wechat-group/weixin-java-tools + + + + The Apache License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + + + + + + Daniel Qian + chanjarster@gmail.com + https://github.com/chanjarster + + + Binary Wang + binarywang@gmail.com + https://github.com/binarywang + + + gaigeshen + gaigeshen@qq.com + https://github.com/gaigeshen + + + Liu Mingbo + liumingbo2008@gmail.com + https://github.com/FirenzesEagle + + + kakotor + kakotor@gmail.com + https://github.com/kakotor + + + xiong + zhaoxiong.tan@gmail.com + https://github.com/ZhaoxiongTan + + + LiuJunGuang + aimilin@yeah.net + https://github.com/aimilin6688 + + + Eric.Tsai + xiaodong.cai.ks@gmail.com + https://github.com/iwareserictsai + + + withinthefog + withinthefog@gmail.com + https://github.com/withinthefog + + + Keung + dongfuqiang1988@163.com + https://github.com/johnnytung + + + Jonk + aimilin@yeah.net + https://github.com/aimilin6688 + + + ecoolper + crskyp@gmail.com + https://github.com/crskyp + + + 007 + 007gzs@gmail.com + https://github.com/007gzs + + + + + scm:git:https://github.com/wechat-group/weixin-java-tools.git + scm:git:git@github.com:wechat-group/weixin-java-tools.git + https://github.com/wechat-group/weixin-java-tools + + + + weixin-java-common + weixin-java-cp + weixin-java-mp + weixin-java-pay + weixin-java-miniapp + weixin-java-open + + + + + 1.7 + 1.7 + + UTF-8 + true + true + 4.5 + 9.3.0.RC0 + + + + + + com.github.binarywang + qrcode-utils + 1.1 + + + + org.jodd + jodd-http + 3.7.1 + provided + + + com.squareup.okhttp3 + okhttp + 3.7.0 + provided + + + + org.apache.httpcomponents + httpclient + ${httpclient.version} + + + org.apache.httpcomponents + httpmime + ${httpclient.version} + + + commons-codec + commons-codec + 1.10 + + + commons-io + commons-io + 2.5 + + + org.apache.commons + commons-lang3 + 3.5 + + + org.slf4j + slf4j-api + 1.7.24 + + + com.thoughtworks.xstream + xstream + 1.4.9 + + + + com.google.guava + guava + 20.0 + + + com.google.code.gson + gson + 2.8.0 + + + + + joda-time + joda-time + 2.9.7 + test + + + ch.qos.logback + logback-classic + 1.1.11 + test + + + com.google.inject + guice + 3.0 + test + + + org.testng + testng + 6.10 + test + + + org.mockito + mockito-all + 1.9.5 + test + + + org.eclipse.jetty + jetty-server + ${jetty.version} + test + + + org.eclipse.jetty + jetty-servlet + ${jetty.version} + test + + + redis.clients + jedis + 2.9.0 + provided + + + org.projectlombok + lombok + 1.16.18 + compile + + + + + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + + ossrh + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + + doclint-java8-disable + + [1.8,) + + + -Xdoclint:none + + + + + release + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9.1 + + + attach-javadocs + + jar + + + + + ${javadoc.opts} + UTF-8 + zh_CN + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.6 + + + sign-artifacts + verify + + sign + + + + + + + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.17 + + true + + + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.3 + true + + ossrh + https://oss.sonatype.org/ + true + + + + org.apache.maven.plugins + maven-release-plugin + 2.5.1 + + true + false + release + deploy + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.0 + + UTF-8 + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 2.17 + + quality-checks/google_checks.xml + true + true + true + + + + verify + + check + + + + + + + + diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/ByteGroup.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/ByteGroup.java index b12ec655..bff08d68 100755 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/ByteGroup.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/ByteGroup.java @@ -1,26 +1,26 @@ -package me.chanjar.weixin.common.util.crypto; - -import java.util.ArrayList; - -public class ByteGroup { - ArrayList byteContainer = new ArrayList<>(); - - public byte[] toBytes() { - byte[] bytes = new byte[this.byteContainer.size()]; - for (int i = 0; i < this.byteContainer.size(); i++) { - bytes[i] = this.byteContainer.get(i); - } - return bytes; - } - - public ByteGroup addBytes(byte[] bytes) { - for (byte b : bytes) { - this.byteContainer.add(b); - } - return this; - } - - public int size() { - return this.byteContainer.size(); - } -} +package me.chanjar.weixin.common.util.crypto; + +import java.util.ArrayList; + +public class ByteGroup { + ArrayList byteContainer = new ArrayList<>(); + + public byte[] toBytes() { + byte[] bytes = new byte[this.byteContainer.size()]; + for (int i = 0; i < this.byteContainer.size(); i++) { + bytes[i] = this.byteContainer.get(i); + } + return bytes; + } + + public ByteGroup addBytes(byte[] bytes) { + for (byte b : bytes) { + this.byteContainer.add(b); + } + return this; + } + + public int size() { + return this.byteContainer.size(); + } +} diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/PKCS7Encoder.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/PKCS7Encoder.java index 145896a5..8ce94cba 100755 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/PKCS7Encoder.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/PKCS7Encoder.java @@ -1,68 +1,68 @@ -/** - * 对公众平台发送给公众账号的消息加解密示例代码. - * - * @copyright Copyright (c) 1998-2014 Tencent Inc. - */ - -// ------------------------------------------------------------------------ - -package me.chanjar.weixin.common.util.crypto; - -import java.nio.charset.Charset; -import java.util.Arrays; - -/** - * 提供基于PKCS7算法的加解 - */ -public class PKCS7Encoder { - - private static final Charset CHARSET = Charset.forName("utf-8"); - private static final int BLOCK_SIZE = 32; - - /** - * 获得对明文进行补位填充的字节. - * - * @param count 需要进行填充补位操作的明文字节个数 - * @return 补齐用的字节数组 - */ - public static byte[] encode(int count) { - // 计算需要填充的位数 - int amountToPad = BLOCK_SIZE - (count % BLOCK_SIZE); - if (amountToPad == 0) { - amountToPad = BLOCK_SIZE; - } - // 获得补位所用的字符 - char padChr = chr(amountToPad); - String tmp = new String(); - for (int index = 0; index < amountToPad; index++) { - tmp += padChr; - } - return tmp.getBytes(CHARSET); - } - - /** - * 删除解密后明文的补位字符 - * - * @param decrypted 解密后的明文 - * @return 删除补位字符后的明文 - */ - public static byte[] decode(byte[] decrypted) { - int pad = decrypted[decrypted.length - 1]; - if (pad < 1 || pad > 32) { - pad = 0; - } - return Arrays.copyOfRange(decrypted, 0, decrypted.length - pad); - } - - /** - * 将数字转化成ASCII码对应的字符,用于对明文进行补码 - * - * @param a 需要转化的数字 - * @return 转化得到的字符 - */ - public static char chr(int a) { - byte target = (byte) (a & 0xFF); - return (char) target; - } - -} +/** + * 对公众平台发送给公众账号的消息加解密示例代码. + * + * @copyright Copyright (c) 1998-2014 Tencent Inc. + */ + +// ------------------------------------------------------------------------ + +package me.chanjar.weixin.common.util.crypto; + +import java.nio.charset.Charset; +import java.util.Arrays; + +/** + * 提供基于PKCS7算法的加解 + */ +public class PKCS7Encoder { + + private static final Charset CHARSET = Charset.forName("utf-8"); + private static final int BLOCK_SIZE = 32; + + /** + * 获得对明文进行补位填充的字节. + * + * @param count 需要进行填充补位操作的明文字节个数 + * @return 补齐用的字节数组 + */ + public static byte[] encode(int count) { + // 计算需要填充的位数 + int amountToPad = BLOCK_SIZE - (count % BLOCK_SIZE); + if (amountToPad == 0) { + amountToPad = BLOCK_SIZE; + } + // 获得补位所用的字符 + char padChr = chr(amountToPad); + String tmp = new String(); + for (int index = 0; index < amountToPad; index++) { + tmp += padChr; + } + return tmp.getBytes(CHARSET); + } + + /** + * 删除解密后明文的补位字符 + * + * @param decrypted 解密后的明文 + * @return 删除补位字符后的明文 + */ + public static byte[] decode(byte[] decrypted) { + int pad = decrypted[decrypted.length - 1]; + if (pad < 1 || pad > 32) { + pad = 0; + } + return Arrays.copyOfRange(decrypted, 0, decrypted.length - pad); + } + + /** + * 将数字转化成ASCII码对应的字符,用于对明文进行补码 + * + * @param a 需要转化的数字 + * @return 转化得到的字符 + */ + public static char chr(int a) { + byte target = (byte) (a & 0xFF); + return (char) target; + } + +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpShakeService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpShakeService.java index 87a6747a..697bfe89 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpShakeService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpShakeService.java @@ -1,8 +1,10 @@ package me.chanjar.weixin.mp.api; +import me.chanjar.weixin.common.bean.result.WxError; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.mp.bean.WxMpShakeInfoResult; import me.chanjar.weixin.mp.bean.WxMpShakeQuery; +import me.chanjar.weixin.mp.bean.shake.*; /** * 摇一摇周边的相关接口 @@ -24,4 +26,36 @@ public interface WxMpShakeService { */ WxMpShakeInfoResult getShakeInfo(WxMpShakeQuery wxMpShakeQuery) throws WxErrorException; + /** + *
+   * 页面管理
+ * 详情请见: https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1459246752 + *
+ * @param shakeAroundPageAddQuery + * @return + * @throws WxErrorException + */ + WxMpShakeAroundPageAddResult pageAdd(WxMpShakeAroundPageAddQuery shakeAroundPageAddQuery) throws WxErrorException; + + /** + *
+   * 配置设备与页面的关联关系
+ * 详情请见: https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1459301931 + *
+ * @param shakeAroundDeviceBindPageQuery + * @return + * @throws WxErrorException + */ + WxError deviceBindPageQuery(WxMpShakeAroundDeviceBindPageQuery shakeAroundDeviceBindPageQuery) throws WxErrorException; + + /** + *
+   * 查询设备与页面的关联关系
+ * 详情请见: https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1443447914 + *
+ * @param shakeAroundRelationSearchQuery + * @return + * @throws WxErrorException + */ + WxMpShakeAroundRelationSearchResult relationSearch(WxMpShakeAroundRelationSearchQuery shakeAroundRelationSearchQuery) throws WxErrorException; } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpShakeServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpShakeServiceImpl.java index bee636fd..2c90f70e 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpShakeServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpShakeServiceImpl.java @@ -1,13 +1,16 @@ package me.chanjar.weixin.mp.api.impl; +import me.chanjar.weixin.common.bean.result.WxError; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpShakeService; import me.chanjar.weixin.mp.bean.WxMpShakeInfoResult; import me.chanjar.weixin.mp.bean.WxMpShakeQuery; +import me.chanjar.weixin.mp.bean.shake.*; /** * Created by rememberber on 2017/6/5. + * * @author rememberber */ public class WxMpShakeServiceImpl implements WxMpShakeService { @@ -27,7 +30,7 @@ public class WxMpShakeServiceImpl implements WxMpShakeService { * 接口地址:https://api.weixin.qq.com/shakearound/user/getshakeinfo?access_token=ACCESS_TOKE * * - * @param wxMpShakeQuery 查询参数 + * @param wxMpShakeQuery 查询参数 */ @Override public WxMpShakeInfoResult getShakeInfo(WxMpShakeQuery wxMpShakeQuery) throws WxErrorException { @@ -36,4 +39,28 @@ public class WxMpShakeServiceImpl implements WxMpShakeService { String responseContent = this.wxMpService.post(url, postData); return WxMpShakeInfoResult.fromJson(responseContent); } + + @Override + public WxMpShakeAroundPageAddResult pageAdd(WxMpShakeAroundPageAddQuery shakeAroundPageAddQuery) throws WxErrorException { + String url = "https://api.weixin.qq.com/shakearound/page/add"; + String postData = shakeAroundPageAddQuery.toJsonString(); + String responseContent = this.wxMpService.post(url, postData); + return WxMpShakeAroundPageAddResult.fromJson(responseContent); + } + + @Override + public WxError deviceBindPageQuery(WxMpShakeAroundDeviceBindPageQuery shakeAroundDeviceBindPageQuery) throws WxErrorException { + String url = "https://api.weixin.qq.com/shakearound/device/bindpage"; + String postData = shakeAroundDeviceBindPageQuery.toJsonString(); + String responseContent = this.wxMpService.post(url, postData); + return WxError.fromJson(responseContent); + } + + @Override + public WxMpShakeAroundRelationSearchResult relationSearch(WxMpShakeAroundRelationSearchQuery shakeAroundRelationSearchQuery) throws WxErrorException { + String url = "https://api.weixin.qq.com/shakearound/relation/search"; + String postData = shakeAroundRelationSearchQuery.toJsonString(); + String responseContent = this.wxMpService.post(url, postData); + return WxMpShakeAroundRelationSearchResult.fromJson(responseContent); + } } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpDeviceIdentifier.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpDeviceIdentifier.java new file mode 100644 index 00000000..e93bf75c --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpDeviceIdentifier.java @@ -0,0 +1,23 @@ +package me.chanjar.weixin.mp.bean.shake; + +import com.google.gson.JsonObject; +import lombok.Data; + +import java.io.Serializable; + +@Data +public class WxMpDeviceIdentifier implements Serializable { + private Integer device_id; + private String uuid; + private Integer page_id; + private Integer major; + private Integer minor; + public JsonObject toJsonObject(){ + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("device_id", device_id); + jsonObject.addProperty("uuid", uuid); + jsonObject.addProperty("major", major); + jsonObject.addProperty("minor", minor); + return jsonObject; + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundDeviceBindPageQuery.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundDeviceBindPageQuery.java new file mode 100644 index 00000000..71da0b1c --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundDeviceBindPageQuery.java @@ -0,0 +1,23 @@ +package me.chanjar.weixin.mp.bean.shake; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import lombok.Data; + +import java.util.Collection; + +@Data +public class WxMpShakeAroundDeviceBindPageQuery { + private WxMpDeviceIdentifier deviceIdentifier; + private Collection pageIds; + public String toJsonString(){ + JsonObject jsonObject = new JsonObject(); + jsonObject.add("device_identifier", deviceIdentifier.toJsonObject()); + JsonArray jsonArray = new JsonArray(); + for(Integer pageid: pageIds){ + jsonArray.add(pageid); + } + jsonObject.add("page_ids", jsonArray); + return jsonObject.toString(); + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundPageAddQuery.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundPageAddQuery.java new file mode 100644 index 00000000..b04ced93 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundPageAddQuery.java @@ -0,0 +1,23 @@ +package me.chanjar.weixin.mp.bean.shake; + +import com.google.gson.JsonObject; +import lombok.Data; + +import java.io.Serializable; +@Data +public class WxMpShakeAroundPageAddQuery implements Serializable { + private String title; + private String description; + private String pageUrl; + private String comment; + private String iconUrl; + public String toJsonString(){ + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("title", title); + jsonObject.addProperty("description", description); + jsonObject.addProperty("page_url", pageUrl); + jsonObject.addProperty("comment", comment); + jsonObject.addProperty("icon_url", iconUrl); + return jsonObject.toString(); + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundPageAddResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundPageAddResult.java new file mode 100644 index 00000000..632fe4f3 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundPageAddResult.java @@ -0,0 +1,26 @@ +package me.chanjar.weixin.mp.bean.shake; + +import com.google.gson.JsonObject; +import lombok.Data; +import me.chanjar.weixin.common.util.json.GsonHelper; +import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; + +import java.io.Serializable; + +@Data +public class WxMpShakeAroundPageAddResult implements Serializable { + private Integer errorCode; + private String errorMsg; + private Integer pageId; + public static WxMpShakeAroundPageAddResult fromJson(String json) { + JsonObject jsonObject = WxMpGsonBuilder.INSTANCE.create().fromJson(json, JsonObject.class); + WxMpShakeAroundPageAddResult result = new WxMpShakeAroundPageAddResult(); + result.setErrorCode(GsonHelper.getInteger(jsonObject, "errcode")); + result.setErrorMsg(GsonHelper.getString(jsonObject, "errmsg")); + jsonObject = jsonObject.getAsJsonObject("data"); + if(jsonObject != null){ + result.setPageId(GsonHelper.getInteger(jsonObject, "page_id")); + } + return result; + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundRelationSearchQuery.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundRelationSearchQuery.java new file mode 100644 index 00000000..390fe509 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundRelationSearchQuery.java @@ -0,0 +1,32 @@ +package me.chanjar.weixin.mp.bean.shake; + +import com.google.gson.JsonObject; +import lombok.Data; + +import java.io.Serializable; + +@Data +public class WxMpShakeAroundRelationSearchQuery implements Serializable { + private int type; + private Integer pageId; + private Integer begin; + private Integer count; + private WxMpDeviceIdentifier deviceIdentifier; + public String toJsonString(){ + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("type", type); + switch (type){ + case 1: + jsonObject.add("device_identifier", deviceIdentifier.toJsonObject()); + break; + case 2: + jsonObject.addProperty("page_id", pageId); + jsonObject.addProperty("begin", begin); + jsonObject.addProperty("count", count); + break; + default: + throw new IllegalArgumentException("type error"); + } + return jsonObject.toString(); + } +} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundRelationSearchResult.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundRelationSearchResult.java new file mode 100644 index 00000000..2b7269e5 --- /dev/null +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundRelationSearchResult.java @@ -0,0 +1,22 @@ +package me.chanjar.weixin.mp.bean.shake; + +import lombok.Data; +import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; + +import java.io.Serializable; +import java.util.List; + +@Data +public class WxMpShakeAroundRelationSearchResult implements Serializable { + private Integer errcode; + private String errmsg; + private WxMpShakeAcoundRelationSearch data; + public static WxMpShakeAroundRelationSearchResult fromJson(String json) { + return WxMpGsonBuilder.INSTANCE.create().fromJson(json, WxMpShakeAroundRelationSearchResult.class); + } + @Data + public static class WxMpShakeAcoundRelationSearch implements Serializable{ + private List relations; + private Integer total_count; + } +}