Browse Source

修复用户标签id类型不一致的问题 #175

master
Binary Wang 7 years ago
parent
commit
0ff63ba3cb
3 changed files with 20 additions and 6 deletions
  1. +16
    -2
      weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/GsonHelper.java
  2. +3
    -3
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUser.java
  3. +1
    -1
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpUserGsonAdapter.java

+ 16
- 2
weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/GsonHelper.java View File

@@ -9,13 +9,13 @@
package me.chanjar.weixin.common.util.json; package me.chanjar.weixin.common.util.json;




import java.util.List;

import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;


import java.util.List;



public class GsonHelper { public class GsonHelper {


@@ -130,6 +130,20 @@ public class GsonHelper {
return result.toArray(new Integer[0]); return result.toArray(new Integer[0]);
} }


public static Long[] getLongArray(JsonObject o, String string) {
JsonArray jsonArray = getAsJsonArray(o.getAsJsonArray(string));
if (jsonArray == null) {
return null;
}

List<Long> result = Lists.newArrayList();
for (int i = 0; i < jsonArray.size(); i++) {
result.add(jsonArray.get(i).getAsLong());
}

return result.toArray(new Long[0]);
}

public static JsonArray getAsJsonArray(JsonElement element) { public static JsonArray getAsJsonArray(JsonElement element) {
return element == null ? null : element.getAsJsonArray(); return element == null ? null : element.getAsJsonArray();
} }


+ 3
- 3
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpUser.java View File

@@ -32,7 +32,7 @@ public class WxMpUser implements Serializable {
private Integer sexId; private Integer sexId;
private String remark; private String remark;
private Integer groupId; private Integer groupId;
private Integer[] tagIds;
private Long[] tagIds;


public Boolean getSubscribe() { public Boolean getSubscribe() {
return this.subscribe; return this.subscribe;
@@ -150,11 +150,11 @@ public class WxMpUser implements Serializable {
this.groupId = groupId; this.groupId = groupId;
} }


public Integer[] getTagIds() {
public Long[] getTagIds() {
return this.tagIds; return this.tagIds;
} }


public void setTagIds(Integer[] tagIds) {
public void setTagIds(Long[] tagIds) {
this.tagIds = tagIds; this.tagIds = tagIds;
} }




+ 1
- 1
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpUserGsonAdapter.java View File

@@ -36,7 +36,7 @@ public class WxMpUserGsonAdapter implements JsonDeserializer<WxMpUser> {
Integer sexId = GsonHelper.getInteger(o, "sex"); Integer sexId = GsonHelper.getInteger(o, "sex");
wxMpUser.setRemark(GsonHelper.getString(o, "remark")); wxMpUser.setRemark(GsonHelper.getString(o, "remark"));
wxMpUser.setGroupId(GsonHelper.getInteger(o, "groupid")); wxMpUser.setGroupId(GsonHelper.getInteger(o, "groupid"));
wxMpUser.setTagIds(GsonHelper.getIntArray(o, "tagid_list"));
wxMpUser.setTagIds(GsonHelper.getLongArray(o, "tagid_list"));
wxMpUser.setSexId(sexId); wxMpUser.setSexId(sexId);
if (new Integer(1).equals(sexId)) { if (new Integer(1).equals(sexId)) {
wxMpUser.setSex("男"); wxMpUser.setSex("男");


Loading…
Cancel
Save