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

This commit is contained in:
007gzs 2017-11-14 17:02:13 +08:00 committed by Binary Wang
parent 9eda612db3
commit d32cf99b6d
11 changed files with 692 additions and 482 deletions

774
pom.xml
View File

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

View File

@ -1,26 +1,26 @@
package me.chanjar.weixin.common.util.crypto; package me.chanjar.weixin.common.util.crypto;
import java.util.ArrayList; import java.util.ArrayList;
public class ByteGroup { public class ByteGroup {
ArrayList<Byte> byteContainer = new ArrayList<>(); ArrayList<Byte> byteContainer = new ArrayList<>();
public byte[] toBytes() { public byte[] toBytes() {
byte[] bytes = new byte[this.byteContainer.size()]; byte[] bytes = new byte[this.byteContainer.size()];
for (int i = 0; i < this.byteContainer.size(); i++) { for (int i = 0; i < this.byteContainer.size(); i++) {
bytes[i] = this.byteContainer.get(i); bytes[i] = this.byteContainer.get(i);
} }
return bytes; return bytes;
} }
public ByteGroup addBytes(byte[] bytes) { public ByteGroup addBytes(byte[] bytes) {
for (byte b : bytes) { for (byte b : bytes) {
this.byteContainer.add(b); this.byteContainer.add(b);
} }
return this; return this;
} }
public int size() { public int size() {
return this.byteContainer.size(); return this.byteContainer.size();
} }
} }

View File

@ -1,68 +1,68 @@
/** /**
* 对公众平台发送给公众账号的消息加解密示例代码. * 对公众平台发送给公众账号的消息加解密示例代码.
* *
* @copyright Copyright (c) 1998-2014 Tencent Inc. * @copyright Copyright (c) 1998-2014 Tencent Inc.
*/ */
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
package me.chanjar.weixin.common.util.crypto; package me.chanjar.weixin.common.util.crypto;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.Arrays; import java.util.Arrays;
/** /**
* 提供基于PKCS7算法的加解 * 提供基于PKCS7算法的加解
*/ */
public class PKCS7Encoder { public class PKCS7Encoder {
private static final Charset CHARSET = Charset.forName("utf-8"); private static final Charset CHARSET = Charset.forName("utf-8");
private static final int BLOCK_SIZE = 32; private static final int BLOCK_SIZE = 32;
/** /**
* 获得对明文进行补位填充的字节. * 获得对明文进行补位填充的字节.
* *
* @param count 需要进行填充补位操作的明文字节个数 * @param count 需要进行填充补位操作的明文字节个数
* @return 补齐用的字节数组 * @return 补齐用的字节数组
*/ */
public static byte[] encode(int count) { public static byte[] encode(int count) {
// 计算需要填充的位数 // 计算需要填充的位数
int amountToPad = BLOCK_SIZE - (count % BLOCK_SIZE); int amountToPad = BLOCK_SIZE - (count % BLOCK_SIZE);
if (amountToPad == 0) { if (amountToPad == 0) {
amountToPad = BLOCK_SIZE; amountToPad = BLOCK_SIZE;
} }
// 获得补位所用的字符 // 获得补位所用的字符
char padChr = chr(amountToPad); char padChr = chr(amountToPad);
String tmp = new String(); String tmp = new String();
for (int index = 0; index < amountToPad; index++) { for (int index = 0; index < amountToPad; index++) {
tmp += padChr; tmp += padChr;
} }
return tmp.getBytes(CHARSET); return tmp.getBytes(CHARSET);
} }
/** /**
* 删除解密后明文的补位字符 * 删除解密后明文的补位字符
* *
* @param decrypted 解密后的明文 * @param decrypted 解密后的明文
* @return 删除补位字符后的明文 * @return 删除补位字符后的明文
*/ */
public static byte[] decode(byte[] decrypted) { public static byte[] decode(byte[] decrypted) {
int pad = decrypted[decrypted.length - 1]; int pad = decrypted[decrypted.length - 1];
if (pad < 1 || pad > 32) { if (pad < 1 || pad > 32) {
pad = 0; pad = 0;
} }
return Arrays.copyOfRange(decrypted, 0, decrypted.length - pad); return Arrays.copyOfRange(decrypted, 0, decrypted.length - pad);
} }
/** /**
* 将数字转化成ASCII码对应的字符用于对明文进行补码 * 将数字转化成ASCII码对应的字符用于对明文进行补码
* *
* @param a 需要转化的数字 * @param a 需要转化的数字
* @return 转化得到的字符 * @return 转化得到的字符
*/ */
public static char chr(int a) { public static char chr(int a) {
byte target = (byte) (a & 0xFF); byte target = (byte) (a & 0xFF);
return (char) target; return (char) target;
} }
} }

View File

@ -1,8 +1,10 @@
package me.chanjar.weixin.mp.api; 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.common.exception.WxErrorException;
import me.chanjar.weixin.mp.bean.WxMpShakeInfoResult; import me.chanjar.weixin.mp.bean.WxMpShakeInfoResult;
import me.chanjar.weixin.mp.bean.WxMpShakeQuery; 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; 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;
} }

View File

@ -1,13 +1,16 @@
package me.chanjar.weixin.mp.api.impl; 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.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.WxMpShakeService; import me.chanjar.weixin.mp.api.WxMpShakeService;
import me.chanjar.weixin.mp.bean.WxMpShakeInfoResult; import me.chanjar.weixin.mp.bean.WxMpShakeInfoResult;
import me.chanjar.weixin.mp.bean.WxMpShakeQuery; import me.chanjar.weixin.mp.bean.WxMpShakeQuery;
import me.chanjar.weixin.mp.bean.shake.*;
/** /**
* Created by rememberber on 2017/6/5. * Created by rememberber on 2017/6/5.
*
* @author rememberber * @author rememberber
*/ */
public class WxMpShakeServiceImpl implements WxMpShakeService { 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 * 接口地址https://api.weixin.qq.com/shakearound/user/getshakeinfo?access_token=ACCESS_TOKE
* </pre> * </pre>
* *
* @param wxMpShakeQuery 查询参数 * @param wxMpShakeQuery 查询参数
*/ */
@Override @Override
public WxMpShakeInfoResult getShakeInfo(WxMpShakeQuery wxMpShakeQuery) throws WxErrorException { public WxMpShakeInfoResult getShakeInfo(WxMpShakeQuery wxMpShakeQuery) throws WxErrorException {
@ -36,4 +39,28 @@ public class WxMpShakeServiceImpl implements WxMpShakeService {
String responseContent = this.wxMpService.post(url, postData); String responseContent = this.wxMpService.post(url, postData);
return WxMpShakeInfoResult.fromJson(responseContent); 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);
}
} }

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

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

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

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

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

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