Browse Source

#376 增加摇一摇周边的部分相关接口

master
007gzs 7 years ago
committed by Binary Wang
parent
commit
d32cf99b6d
11 changed files with 692 additions and 482 deletions
  1. +387
    -387
      pom.xml
  2. +26
    -26
      weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/ByteGroup.java
  3. +68
    -68
      weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/PKCS7Encoder.java
  4. +34
    -0
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpShakeService.java
  5. +28
    -1
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpShakeServiceImpl.java
  6. +23
    -0
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpDeviceIdentifier.java
  7. +23
    -0
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundDeviceBindPageQuery.java
  8. +23
    -0
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundPageAddQuery.java
  9. +26
    -0
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundPageAddResult.java
  10. +32
    -0
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundRelationSearchQuery.java
  11. +22
    -0
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundRelationSearchResult.java

+ 387
- 387
pom.xml View File

@@ -1,387 +1,387 @@
<?xml version="1.0"?>
<project
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-parent</artifactId>
<version>2.8.8.BETA</version>
<packaging>pom</packaging>
<name>WeiXin Java Tools - Parent</name>
<description>微信公众号、企业号上级POM</description>
<url>https://github.com/wechat-group/weixin-java-tools</url>
<licenses>
<license>
<name>The Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<developers>
<developer>
<name>Daniel Qian</name>
<email>chanjarster@gmail.com</email>
<url>https://github.com/chanjarster</url>
</developer>
<developer>
<name>Binary Wang</name>
<email>binarywang@gmail.com</email>
<url>https://github.com/binarywang</url>
</developer>
<developer>
<name>gaigeshen</name>
<email>gaigeshen@qq.com</email>
<url>https://github.com/gaigeshen</url>
</developer>
<developer>
<name>Liu Mingbo</name>
<email>liumingbo2008@gmail.com</email>
<url>https://github.com/FirenzesEagle</url>
</developer>
<developer>
<name>kakotor</name>
<email>kakotor@gmail.com</email>
<url>https://github.com/kakotor</url>
</developer>
<developer>
<name>xiong</name>
<email>zhaoxiong.tan@gmail.com</email>
<url>https://github.com/ZhaoxiongTan</url>
</developer>
<developer>
<name>LiuJunGuang</name>
<email>aimilin@yeah.net</email>
<url>https://github.com/aimilin6688</url>
</developer>
<developer>
<name>Eric.Tsai</name>
<email>xiaodong.cai.ks@gmail.com</email>
<url>https://github.com/iwareserictsai</url>
</developer>
<developer>
<name>withinthefog</name>
<email>withinthefog@gmail.com</email>
<url>https://github.com/withinthefog</url>
</developer>
<developer>
<name>Keung</name>
<email>dongfuqiang1988@163.com</email>
<url>https://github.com/johnnytung</url>
</developer>
<developer>
<name>Jonk</name>
<email>aimilin@yeah.net</email>
<url>https://github.com/aimilin6688</url>
</developer>
<developer>
<name>ecoolper</name>
<email>crskyp@gmail.com</email>
<url>https://github.com/crskyp</url>
</developer>
<developer>
<name>007</name>
<email>007gzs@gmail.com</email>
<url>https://github.com/007gzs</url>
</developer>
</developers>
<scm>
<connection>scm:git:https://github.com/wechat-group/weixin-java-tools.git</connection>
<developerConnection>scm:git:git@github.com:wechat-group/weixin-java-tools.git</developerConnection>
<url>https://github.com/wechat-group/weixin-java-tools</url>
</scm>
<modules>
<module>weixin-java-common</module>
<module>weixin-java-cp</module>
<module>weixin-java-mp</module>
<module>weixin-java-pay</module>
<module>weixin-java-miniapp</module>
<module>weixin-java-open</module>
<!--module>weixin-java-osgi</module-->
</modules>
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<downloadJavadocs>true</downloadJavadocs>
<downloadSources>true</downloadSources>
<httpclient.version>4.5</httpclient.version>
<jetty.version>9.3.0.RC0</jetty.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>qrcode-utils</artifactId>
<version>1.1</version>
</dependency>
<!-- 由于jodd-http较新的3.8版本需要jdk8,故而此处采用较低版本 -->
<dependency>
<groupId>org.jodd</groupId>
<artifactId>jodd-http</artifactId>
<version>3.7.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>${httpclient.version}</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.24</version>
</dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.9</version>
</dependency>
<!-- 由于guava较新的21.0版本需要jdk8,故而此处采用较低版本 -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>20.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
</dependency>
<!-- 测试所用依赖 -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jetty.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${jetty.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.18</version>
<scope>compile</scope>
</dependency>
</dependencies>
</dependencyManagement>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
<profiles>
<profile>
<id>doclint-java8-disable</id>
<activation>
<jdk>[1.8,)</jdk>
</activation>
<properties>
<javadoc.opts>-Xdoclint:none</javadoc.opts>
</properties>
</profile>
<profile>
<id>release</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<additionalparam>${javadoc.opts}</additionalparam>
<charset>UTF-8</charset>
<locale>zh_CN</locale>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.3</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<useReleaseProfile>false</useReleaseProfile>
<releaseProfiles>release</releaseProfiles>
<goals>deploy</goals>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<configuration>
<configLocation>quality-checks/google_checks.xml</configLocation>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
</configuration>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
<?xml version="1.0"?>
<project
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-parent</artifactId>
<version>2.8.8.BETA</version>
<packaging>pom</packaging>
<name>WeiXin Java Tools - Parent</name>
<description>微信公众号、企业号上级POM</description>
<url>https://github.com/wechat-group/weixin-java-tools</url>
<licenses>
<license>
<name>The Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<developers>
<developer>
<name>Daniel Qian</name>
<email>chanjarster@gmail.com</email>
<url>https://github.com/chanjarster</url>
</developer>
<developer>
<name>Binary Wang</name>
<email>binarywang@gmail.com</email>
<url>https://github.com/binarywang</url>
</developer>
<developer>
<name>gaigeshen</name>
<email>gaigeshen@qq.com</email>
<url>https://github.com/gaigeshen</url>
</developer>
<developer>
<name>Liu Mingbo</name>
<email>liumingbo2008@gmail.com</email>
<url>https://github.com/FirenzesEagle</url>
</developer>
<developer>
<name>kakotor</name>
<email>kakotor@gmail.com</email>
<url>https://github.com/kakotor</url>
</developer>
<developer>
<name>xiong</name>
<email>zhaoxiong.tan@gmail.com</email>
<url>https://github.com/ZhaoxiongTan</url>
</developer>
<developer>
<name>LiuJunGuang</name>
<email>aimilin@yeah.net</email>
<url>https://github.com/aimilin6688</url>
</developer>
<developer>
<name>Eric.Tsai</name>
<email>xiaodong.cai.ks@gmail.com</email>
<url>https://github.com/iwareserictsai</url>
</developer>
<developer>
<name>withinthefog</name>
<email>withinthefog@gmail.com</email>
<url>https://github.com/withinthefog</url>
</developer>
<developer>
<name>Keung</name>
<email>dongfuqiang1988@163.com</email>
<url>https://github.com/johnnytung</url>
</developer>
<developer>
<name>Jonk</name>
<email>aimilin@yeah.net</email>
<url>https://github.com/aimilin6688</url>
</developer>
<developer>
<name>ecoolper</name>
<email>crskyp@gmail.com</email>
<url>https://github.com/crskyp</url>
</developer>
<developer>
<name>007</name>
<email>007gzs@gmail.com</email>
<url>https://github.com/007gzs</url>
</developer>
</developers>
<scm>
<connection>scm:git:https://github.com/wechat-group/weixin-java-tools.git</connection>
<developerConnection>scm:git:git@github.com:wechat-group/weixin-java-tools.git</developerConnection>
<url>https://github.com/wechat-group/weixin-java-tools</url>
</scm>
<modules>
<module>weixin-java-common</module>
<module>weixin-java-cp</module>
<module>weixin-java-mp</module>
<module>weixin-java-pay</module>
<module>weixin-java-miniapp</module>
<module>weixin-java-open</module>
<!--module>weixin-java-osgi</module-->
</modules>
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<downloadJavadocs>true</downloadJavadocs>
<downloadSources>true</downloadSources>
<httpclient.version>4.5</httpclient.version>
<jetty.version>9.3.0.RC0</jetty.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>qrcode-utils</artifactId>
<version>1.1</version>
</dependency>
<!-- 由于jodd-http较新的3.8版本需要jdk8,故而此处采用较低版本 -->
<dependency>
<groupId>org.jodd</groupId>
<artifactId>jodd-http</artifactId>
<version>3.7.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>${httpclient.version}</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.24</version>
</dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.9</version>
</dependency>
<!-- 由于guava较新的21.0版本需要jdk8,故而此处采用较低版本 -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>20.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
</dependency>
<!-- 测试所用依赖 -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jetty.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${jetty.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.18</version>
<scope>compile</scope>
</dependency>
</dependencies>
</dependencyManagement>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
<profiles>
<profile>
<id>doclint-java8-disable</id>
<activation>
<jdk>[1.8,)</jdk>
</activation>
<properties>
<javadoc.opts>-Xdoclint:none</javadoc.opts>
</properties>
</profile>
<profile>
<id>release</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<additionalparam>${javadoc.opts}</additionalparam>
<charset>UTF-8</charset>
<locale>zh_CN</locale>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.3</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<useReleaseProfile>false</useReleaseProfile>
<releaseProfiles>release</releaseProfiles>
<goals>deploy</goals>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<configuration>
<configLocation>quality-checks/google_checks.xml</configLocation>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
</configuration>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

+ 26
- 26
weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/ByteGroup.java View File

@@ -1,26 +1,26 @@
package me.chanjar.weixin.common.util.crypto;
import java.util.ArrayList;
public class ByteGroup {
ArrayList<Byte> 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<Byte> 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();
}
}

+ 68
- 68
weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/PKCS7Encoder.java View File

@@ -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;
}
}

+ 34
- 0
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpShakeService.java View File

@@ -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;

/**
* <pre>
* 页面管理<br/>
* 详情请见: https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1459246752
* </pre>
* @param shakeAroundPageAddQuery
* @return
* @throws WxErrorException
*/
WxMpShakeAroundPageAddResult pageAdd(WxMpShakeAroundPageAddQuery shakeAroundPageAddQuery) throws WxErrorException;

/**
* <pre>
* 配置设备与页面的关联关系<br/>
* 详情请见: https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1459301931
* </pre>
* @param shakeAroundDeviceBindPageQuery
* @return
* @throws WxErrorException
*/
WxError deviceBindPageQuery(WxMpShakeAroundDeviceBindPageQuery shakeAroundDeviceBindPageQuery) throws WxErrorException;

/**
* <pre>
* 查询设备与页面的关联关系<br/>
* 详情请见: https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1443447914
* </pre>
* @param shakeAroundRelationSearchQuery
* @return
* @throws WxErrorException
*/
WxMpShakeAroundRelationSearchResult relationSearch(WxMpShakeAroundRelationSearchQuery shakeAroundRelationSearchQuery) throws WxErrorException;
}

+ 28
- 1
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpShakeServiceImpl.java View File

@@ -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
* </pre>
*
* @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);
}
}

+ 23
- 0
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpDeviceIdentifier.java View File

@@ -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;
}
}

+ 23
- 0
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundDeviceBindPageQuery.java View File

@@ -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<Integer> 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();
}
}

+ 23
- 0
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundPageAddQuery.java View File

@@ -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();
}
}

+ 26
- 0
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundPageAddResult.java View File

@@ -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;
}
}

+ 32
- 0
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundRelationSearchQuery.java View File

@@ -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();
}
}

+ 22
- 0
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/shake/WxMpShakeAroundRelationSearchResult.java View File

@@ -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<WxMpDeviceIdentifier> relations;
private Integer total_count;
}
}

Loading…
Cancel
Save