1
0
mirror of synced 2026-02-12 06:57:49 +08:00

批量格式化代码

This commit is contained in:
Binary Wang
2017-05-11 17:07:08 +08:00
parent 5f887739a3
commit 8982cf8471
223 changed files with 2425 additions and 2793 deletions

View File

@@ -39,13 +39,13 @@ public class WxCpJedisConfigStorage implements WxCpConfigStorage {
this.jedisPool = new JedisPool(host, port);
}
public WxCpJedisConfigStorage(JedisPoolConfig poolConfig, String host, int port) {
this.jedisPool = new JedisPool(poolConfig, host, port);
this.jedisPool = new JedisPool(poolConfig, host, port);
}
public WxCpJedisConfigStorage(JedisPoolConfig poolConfig, String host, int port, int timeout, final String password) {
this.jedisPool = new JedisPool(poolConfig, host, port, timeout, password);
this.jedisPool = new JedisPool(poolConfig, host, port, timeout, password);
}
/**

View File

@@ -481,13 +481,6 @@ public interface WxCpService {
*/
<T, E> T execute(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException;
/**
* 注入 {@link WxCpConfigStorage} 的实现
*
* @param wxConfigProvider 配置对象
*/
void setWxCpConfigStorage(WxCpConfigStorage wxConfigProvider);
/**
* <pre>
* 设置当微信系统响应系统繁忙时,要等待多少 retrySleepMillis(ms) * 2^(重试次数 - 1) 再发起重试
@@ -563,4 +556,11 @@ public interface WxCpService {
* @return WxMpConfigStorage
*/
WxCpConfigStorage getWxCpConfigStorage();
/**
* 注入 {@link WxCpConfigStorage} 的实现
*
* @param wxConfigProvider 配置对象
*/
void setWxCpConfigStorage(WxCpConfigStorage wxConfigProvider);
}

View File

@@ -1,7 +1,5 @@
package me.chanjar.weixin.cp.api.impl.okhttp;
import java.io.IOException;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;
@@ -11,6 +9,8 @@ import me.chanjar.weixin.cp.api.WxCpConfigStorage;
import me.chanjar.weixin.cp.api.impl.AbstractWxCpServiceImpl;
import okhttp3.*;
import java.io.IOException;
public class WxCpServiceImpl extends AbstractWxCpServiceImpl<ConnectionPool, OkhttpProxyInfo> {
protected ConnectionPool httpClient;
protected OkhttpProxyInfo httpProxy;

View File

@@ -1,9 +1,9 @@
package me.chanjar.weixin.cp.bean;
import java.io.Serializable;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import java.io.Serializable;
/**
* 微信部门
*
@@ -60,10 +60,10 @@ public class WxCpDepart implements Serializable {
@Override
public String toString() {
return "WxCpDepart{" +
"id=" + this.id +
", name='" + this.name + '\'' +
", parentId=" + this.parentId +
", order=" + this.order +
'}';
"id=" + this.id +
", name='" + this.name + '\'' +
", parentId=" + this.parentId +
", order=" + this.order +
'}';
}
}

View File

@@ -33,14 +33,6 @@ public class WxCpMessage implements Serializable {
private List<NewArticle> articles = new ArrayList<>();
private List<MpnewsArticle> mpnewsArticles = new ArrayList<>();
public List<MpnewsArticle> getMpnewsArticles() {
return mpnewsArticles;
}
public void setMpnewsArticles(List<MpnewsArticle> mpnewsArticles) {
this.mpnewsArticles = mpnewsArticles;
}
/**
* 获得文本消息builder
*/
@@ -90,6 +82,14 @@ public class WxCpMessage implements Serializable {
return new FileBuilder();
}
public List<MpnewsArticle> getMpnewsArticles() {
return mpnewsArticles;
}
public void setMpnewsArticles(List<MpnewsArticle> mpnewsArticles) {
this.mpnewsArticles = mpnewsArticles;
}
public String getToUser() {
return this.toUser;
}

View File

@@ -1,9 +1,9 @@
package me.chanjar.weixin.cp.bean;
import java.io.Serializable;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import java.io.Serializable;
/**
* Created by Daniel Qian
*/

View File

@@ -1,11 +1,11 @@
package me.chanjar.weixin.cp.bean;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
/**
* 微信用户信息
*

View File

@@ -1,21 +1,19 @@
package me.chanjar.weixin.cp.bean;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
import me.chanjar.weixin.cp.api.WxCpConfigStorage;
import me.chanjar.weixin.cp.util.crypto.WxCpCryptUtil;
import me.chanjar.weixin.cp.util.xml.XStreamTransformer;
import org.apache.commons.io.IOUtils;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.IOUtils;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
import me.chanjar.weixin.cp.api.WxCpConfigStorage;
import me.chanjar.weixin.cp.util.crypto.WxCpCryptUtil;
import me.chanjar.weixin.cp.util.xml.XStreamTransformer;
/**
* <pre>
* 微信推送过来的消息也是同步回复给用户的消息xml格式
@@ -183,18 +181,18 @@ public class WxCpXmlMessage implements Serializable {
* @param msgSignature
*/
public static WxCpXmlMessage fromEncryptedXml(
String encryptedXml,
WxCpConfigStorage wxCpConfigStorage,
String timestamp, String nonce, String msgSignature) {
String encryptedXml,
WxCpConfigStorage wxCpConfigStorage,
String timestamp, String nonce, String msgSignature) {
WxCpCryptUtil cryptUtil = new WxCpCryptUtil(wxCpConfigStorage);
String plainText = cryptUtil.decrypt(msgSignature, timestamp, nonce, encryptedXml);
return fromXml(plainText);
}
public static WxCpXmlMessage fromEncryptedXml(
InputStream is,
WxCpConfigStorage wxCpConfigStorage,
String timestamp, String nonce, String msgSignature) {
InputStream is,
WxCpConfigStorage wxCpConfigStorage,
String timestamp, String nonce, String msgSignature) {
try {
return fromEncryptedXml(IOUtils.toString(is, "UTF-8"), wxCpConfigStorage, timestamp, nonce, msgSignature);
} catch (IOException e) {
@@ -493,40 +491,40 @@ public class WxCpXmlMessage implements Serializable {
@Override
public String toString() {
return "WxCpXmlMessage{" +
"agentId=" + this.agentId +
", toUserName='" + this.toUserName + '\'' +
", fromUserName='" + this.fromUserName + '\'' +
", createTime=" + this.createTime +
", msgType='" + this.msgType + '\'' +
", content='" + this.content + '\'' +
", msgId=" + this.msgId +
", picUrl='" + this.picUrl + '\'' +
", mediaId='" + this.mediaId + '\'' +
", format='" + this.format + '\'' +
", thumbMediaId='" + this.thumbMediaId + '\'' +
", locationX=" + this.locationX +
", locationY=" + this.locationY +
", scale=" + this.scale +
", label='" + this.label + '\'' +
", title='" + this.title + '\'' +
", description='" + this.description + '\'' +
", url='" + this.url + '\'' +
", event='" + this.event + '\'' +
", eventKey='" + this.eventKey + '\'' +
", ticket='" + this.ticket + '\'' +
", latitude=" + this.latitude +
", longitude=" + this.longitude +
", precision=" + this.precision +
", recognition='" + this.recognition + '\'' +
", status='" + this.status + '\'' +
", totalCount=" + this.totalCount +
", filterCount=" + this.filterCount +
", sentCount=" + this.sentCount +
", errorCount=" + this.errorCount +
", scanCodeInfo=" + this.scanCodeInfo +
", sendPicsInfo=" + this.sendPicsInfo +
", sendLocationInfo=" + this.sendLocationInfo +
'}';
"agentId=" + this.agentId +
", toUserName='" + this.toUserName + '\'' +
", fromUserName='" + this.fromUserName + '\'' +
", createTime=" + this.createTime +
", msgType='" + this.msgType + '\'' +
", content='" + this.content + '\'' +
", msgId=" + this.msgId +
", picUrl='" + this.picUrl + '\'' +
", mediaId='" + this.mediaId + '\'' +
", format='" + this.format + '\'' +
", thumbMediaId='" + this.thumbMediaId + '\'' +
", locationX=" + this.locationX +
", locationY=" + this.locationY +
", scale=" + this.scale +
", label='" + this.label + '\'' +
", title='" + this.title + '\'' +
", description='" + this.description + '\'' +
", url='" + this.url + '\'' +
", event='" + this.event + '\'' +
", eventKey='" + this.eventKey + '\'' +
", ticket='" + this.ticket + '\'' +
", latitude=" + this.latitude +
", longitude=" + this.longitude +
", precision=" + this.precision +
", recognition='" + this.recognition + '\'' +
", status='" + this.status + '\'' +
", totalCount=" + this.totalCount +
", filterCount=" + this.filterCount +
", sentCount=" + this.sentCount +
", errorCount=" + this.errorCount +
", scanCodeInfo=" + this.scanCodeInfo +
", sendPicsInfo=" + this.sendPicsInfo +
", sendLocationInfo=" + this.sendLocationInfo +
'}';
}
@XStreamAlias("ScanCodeInfo")

View File

@@ -2,7 +2,6 @@ package me.chanjar.weixin.cp.bean;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.util.xml.XStreamMediaIdConverter;

View File

@@ -1,14 +1,13 @@
package me.chanjar.weixin.cp.bean;
import java.util.ArrayList;
import java.util.List;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
import java.util.ArrayList;
import java.util.List;
@XStreamAlias("xml")
public class WxCpXmlOutNewsMessage extends WxCpXmlOutMessage {
private static final long serialVersionUID = -5796178637883178826L;

View File

@@ -2,7 +2,6 @@ package me.chanjar.weixin.cp.bean;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;

View File

@@ -2,7 +2,6 @@ package me.chanjar.weixin.cp.bean;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;

View File

@@ -2,7 +2,6 @@ package me.chanjar.weixin.cp.bean;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.util.xml.XStreamMediaIdConverter;

View File

@@ -4,6 +4,7 @@ package me.chanjar.weixin.cp.bean.article;
* <pre>
* Created by BinaryWang on 2017/3/27.
* </pre>
*
* @author Binary Wang
*/
public class MpnewsArticle {

View File

@@ -44,7 +44,7 @@ public class BaseBuilder<T> {
m.setToParty(this.toParty);
m.setToTag(this.toTag);
m.setSafe(
(this.safe == null || "".equals(this.safe)) ? WxConsts.CUSTOM_MSG_SAFE_NO : this.safe);
(this.safe == null || "".equals(this.safe)) ? WxConsts.CUSTOM_MSG_SAFE_NO : this.safe);
return m;
}

View File

@@ -1,47 +1,51 @@
/**
* 对公众平台发送给公众账号的消息加解密示例代码.
*
* @copyright Copyright (c) 1998-2014 Tencent Inc.
* <p>
* 针对org.apache.commons.codec.binary.Base64
* 需要导入架包commons-codec-1.9或commons-codec-1.8等其他版本)
* 官方下载地址http://commons.apache.org/proper/commons-codec/download_codec.cgi
*/
// ------------------------------------------------------------------------
/**
* 针对org.apache.commons.codec.binary.Base64
* 需要导入架包commons-codec-1.9或commons-codec-1.8等其他版本)
* 官方下载地址http://commons.apache.org/proper/commons-codec/download_codec.cgi
*/
package me.chanjar.weixin.cp.util.crypto;
import me.chanjar.weixin.common.util.crypto.WxCryptUtil;
import me.chanjar.weixin.cp.api.WxCpConfigStorage;
import org.apache.commons.codec.binary.Base64;
public class WxCpCryptUtil extends WxCryptUtil {
/**
* 构造函数
*
* @param wxCpConfigStorage
*/
public WxCpCryptUtil(WxCpConfigStorage wxCpConfigStorage) {
/*
* @param token 公众平台上开发者设置的token
* @param encodingAesKey 公众平台上开发者设置的EncodingAESKey
* @param appidOrCorpid 公众平台appid
*/
String encodingAesKey = wxCpConfigStorage.getAesKey();
String token = wxCpConfigStorage.getToken();
String corpId = wxCpConfigStorage.getCorpId();
this.token = token;
this.appidOrCorpid = corpId;
this.aesKey = Base64.decodeBase64(encodingAesKey + "=");
}
}
/**
* 对公众平台发送给公众账号的消息加解密示例代码.
*
* @copyright Copyright (c) 1998-2014 Tencent Inc.
* <p>
* 针对org.apache.commons.codec.binary.Base64
* 需要导入架包commons-codec-1.9或commons-codec-1.8等其他版本)
* 官方下载地址http://commons.apache.org/proper/commons-codec/download_codec.cgi
* <p>
* 针对org.apache.commons.codec.binary.Base64
* 需要导入架包commons-codec-1.9或commons-codec-1.8等其他版本)
* 官方下载地址http://commons.apache.org/proper/commons-codec/download_codec.cgi
*/
// ------------------------------------------------------------------------
/**
* 针对org.apache.commons.codec.binary.Base64
* 需要导入架包commons-codec-1.9或commons-codec-1.8等其他版本)
* 官方下载地址http://commons.apache.org/proper/commons-codec/download_codec.cgi
*/
package me.chanjar.weixin.cp.util.crypto;
import me.chanjar.weixin.common.util.crypto.WxCryptUtil;
import me.chanjar.weixin.cp.api.WxCpConfigStorage;
import org.apache.commons.codec.binary.Base64;
public class WxCpCryptUtil extends WxCryptUtil {
/**
* 构造函数
*
* @param wxCpConfigStorage
*/
public WxCpCryptUtil(WxCpConfigStorage wxCpConfigStorage) {
/*
* @param token 公众平台上开发者设置的token
* @param encodingAesKey 公众平台上开发者设置的EncodingAESKey
* @param appidOrCorpid 公众平台appid
*/
String encodingAesKey = wxCpConfigStorage.getAesKey();
String token = wxCpConfigStorage.getToken();
String corpId = wxCpConfigStorage.getCorpId();
this.token = token;
this.appidOrCorpid = corpId;
this.aesKey = Base64.decodeBase64(encodingAesKey + "=");
}
}

View File

@@ -39,7 +39,7 @@ public class WxCpDepartGsonAdapter implements JsonSerializer<WxCpDepart>, JsonDe
@Override
public WxCpDepart deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
throws JsonParseException {
WxCpDepart depart = new WxCpDepart();
JsonObject departJson = json.getAsJsonObject();
if (departJson.get("id") != null && !departJson.get("id").isJsonNull()) {

View File

@@ -93,7 +93,7 @@ public class WxCpMessageGsonAdapter implements JsonSerializer<WxCpMessage> {
JsonObject newsJsonObject = new JsonObject();
if (message.getMediaId() != null) {
newsJsonObject.addProperty("media_id", message.getMediaId());
}else {
} else {
JsonArray articleJsonArray = new JsonArray();
for (MpnewsArticle article : message.getMpnewsArticles()) {
JsonObject articleJson = new JsonObject();

View File

@@ -29,7 +29,7 @@ public class WxCpTagGsonAdapter implements JsonSerializer<WxCpTag>, JsonDeserial
@Override
public WxCpTag deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
throws JsonParseException {
JsonObject jsonObject = json.getAsJsonObject();
return new WxCpTag(GsonHelper.getString(jsonObject, "tagid"), GsonHelper.getString(jsonObject, "tagname"));
}

View File

@@ -21,7 +21,7 @@ public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, JsonSeri
@Override
public WxCpUser deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
throws JsonParseException {
JsonObject o = json.getAsJsonObject();
WxCpUser user = new WxCpUser();
user.setUserId(GsonHelper.getString(o, "userid"));
@@ -50,8 +50,8 @@ public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, JsonSeri
JsonArray attrJsonElements = o.get("extattr").getAsJsonObject().get("attrs").getAsJsonArray();
for (JsonElement attrJsonElement : attrJsonElements) {
WxCpUser.Attr attr = new WxCpUser.Attr(
GsonHelper.getString(attrJsonElement.getAsJsonObject(), "name"),
GsonHelper.getString(attrJsonElement.getAsJsonObject(), "value")
GsonHelper.getString(attrJsonElement.getAsJsonObject(), "name"),
GsonHelper.getString(attrJsonElement.getAsJsonObject(), "value")
);
user.getExtAttrs().add(attr);
}