mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
批量格式化代码
This commit is contained in:
@@ -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 + "=");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user