mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
code clean up for cp module
This commit is contained in:
@@ -2,6 +2,10 @@
|
||||
* 对公众平台发送给公众账号的消息加解密示例代码.
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
@@ -37,7 +37,7 @@ public class WxCpDepartGsonAdapter implements JsonSerializer<WxCpDepart>, JsonDe
|
||||
}
|
||||
|
||||
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()) {
|
||||
|
||||
@@ -16,9 +16,7 @@ import me.chanjar.weixin.cp.bean.WxCpMessage;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Daniel Qian
|
||||
*
|
||||
*/
|
||||
public class WxCpMessageGsonAdapter implements JsonSerializer<WxCpMessage> {
|
||||
|
||||
@@ -83,7 +81,7 @@ public class WxCpMessageGsonAdapter implements JsonSerializer<WxCpMessage> {
|
||||
newsJsonObject.add("articles", articleJsonArray);
|
||||
messageJson.add("news", newsJsonObject);
|
||||
}
|
||||
|
||||
|
||||
return messageJson;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ public class WxCpTagGsonAdapter implements JsonSerializer<WxCpTag>, JsonDeserial
|
||||
}
|
||||
|
||||
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"));
|
||||
}
|
||||
|
||||
@@ -20,13 +20,13 @@ import java.lang.reflect.Type;
|
||||
public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, JsonSerializer<WxCpUser> {
|
||||
|
||||
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"));
|
||||
user.setName(GsonHelper.getString(o, "name"));
|
||||
|
||||
if(o.get("department") != null) {
|
||||
if (o.get("department") != null) {
|
||||
JsonArray departJsonArray = o.get("department").getAsJsonArray();
|
||||
Integer[] departIds = new Integer[departJsonArray.size()];
|
||||
int i = 0;
|
||||
@@ -49,8 +49,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);
|
||||
}
|
||||
|
||||
@@ -29,16 +29,16 @@ public class XStreamTransformer {
|
||||
|
||||
/**
|
||||
* 注册扩展消息的解析器
|
||||
* @param clz 类型
|
||||
*
|
||||
* @param clz 类型
|
||||
* @param xStream xml解析器
|
||||
*/
|
||||
public static void register(Class clz,XStream xStream){
|
||||
CLASS_2_XSTREAM_INSTANCE.put(clz,xStream);
|
||||
*/
|
||||
public static void register(Class clz, XStream xStream) {
|
||||
CLASS_2_XSTREAM_INSTANCE.put(clz, xStream);
|
||||
}
|
||||
|
||||
/**
|
||||
* pojo -> xml
|
||||
*
|
||||
*/
|
||||
public static <T> String toXml(Class<T> clazz, T object) {
|
||||
return CLASS_2_XSTREAM_INSTANCE.get(clazz).toXML(object);
|
||||
|
||||
Reference in New Issue
Block a user