diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java index 493c196e4..b91404bf7 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java @@ -199,15 +199,9 @@ public class WxCpUserGsonAdapter implements JsonDeserializer, JsonSeri @Override public JsonElement serialize(WxCpUser user, Type typeOfSrc, JsonSerializationContext context) { JsonObject o = new JsonObject(); - if (user.getUserId() != null) { - o.addProperty("userid", user.getUserId()); - } - if (user.getNewUserId() != null) { - o.addProperty("new_userid", user.getNewUserId()); - } - if (user.getName() != null) { - o.addProperty("name", user.getName()); - } + this.addProperty(o, "userid", user.getUserId()); + this.addProperty(o, "new_userid", user.getNewUserId()); + this.addProperty(o, "name", user.getName()); if (user.getDepartIds() != null) { JsonArray jsonArray = new JsonArray(); for (Long departId : user.getDepartIds()) { @@ -224,9 +218,7 @@ public class WxCpUserGsonAdapter implements JsonDeserializer, JsonSeri o.add("order", jsonArray); } - if (user.getPosition() != null) { - o.addProperty("position", user.getPosition()); - } + this.addProperty(o, "position", user.getPosition()); if (user.getPositions() != null) { JsonArray jsonArray = new JsonArray(); @@ -236,42 +228,20 @@ public class WxCpUserGsonAdapter implements JsonDeserializer, JsonSeri o.add("positions", jsonArray); } - if (user.getMobile() != null) { - o.addProperty("mobile", user.getMobile()); - } + this.addProperty(o, "mobile", user.getMobile()); if (user.getGender() != null) { o.addProperty("gender", user.getGender().getCode()); } - if (user.getEmail() != null) { - o.addProperty("email", user.getEmail()); - } - if (user.getBizMail() != null) { - o.addProperty("biz_mail", user.getBizMail()); - } - if (user.getAvatar() != null) { - o.addProperty("avatar", user.getAvatar()); - } - if (user.getThumbAvatar() != null) { - o.addProperty("thumb_avatar", user.getThumbAvatar()); - } - if (user.getAddress() != null) { - o.addProperty("address", user.getAddress()); - } - if (user.getAvatarMediaId() != null) { - o.addProperty("avatar_mediaid", user.getAvatarMediaId()); - } - if (user.getStatus() != null) { - o.addProperty("status", user.getStatus()); - } - if (user.getEnable() != null) { - o.addProperty("enable", user.getEnable()); - } - if (user.getAlias() != null) { - o.addProperty("alias", user.getAlias()); - } - if (user.getIsLeader() != null) { - o.addProperty("isleader", user.getIsLeader()); - } + this.addProperty(o, "email", user.getEmail()); + this.addProperty(o, "biz_mail", user.getBizMail()); + this.addProperty(o, "avatar", user.getAvatar()); + this.addProperty(o, "thumb_avatar", user.getThumbAvatar()); + this.addProperty(o, "address", user.getAddress()); + this.addProperty(o, "avatar_mediaid", user.getAvatarMediaId()); + this.addProperty(o, "status", user.getStatus()); + this.addProperty(o, "enable", user.getEnable()); + this.addProperty(o, "alias", user.getAlias()); + this.addProperty(o, "isleader", user.getIsLeader()); if (user.getIsLeaderInDept() != null && user.getIsLeaderInDept().length > 0) { JsonArray ary = new JsonArray(); for (int item : user.getIsLeaderInDept()) { @@ -279,24 +249,14 @@ public class WxCpUserGsonAdapter implements JsonDeserializer, JsonSeri } o.add("is_leader_in_dept", ary); } - if (user.getHideMobile() != null) { - o.addProperty("hide_mobile", user.getHideMobile()); - } - if (user.getEnglishName() != null) { - o.addProperty("english_name", user.getEnglishName()); - } - if (user.getTelephone() != null) { - o.addProperty("telephone", user.getTelephone()); - } - if (user.getQrCode() != null) { - o.addProperty("qr_code", user.getQrCode()); - } + this.addProperty(o, "hide_mobile", user.getHideMobile()); + this.addProperty(o, "english_name", user.getEnglishName()); + this.addProperty(o, "telephone", user.getTelephone()); + this.addProperty(o, "qr_code", user.getQrCode()); if (user.getToInvite() != null) { o.addProperty("to_invite", user.getToInvite()); } - if (user.getMainDepartment() != null) { - o.addProperty("main_department", user.getMainDepartment()); - } + this.addProperty(o, "main_department", user.getMainDepartment()); if (!user.getExtAttrs().isEmpty()) { JsonArray attrsJsonArray = new JsonArray(); @@ -326,16 +286,12 @@ public class WxCpUserGsonAdapter implements JsonDeserializer, JsonSeri o.add(EXTRA_ATTR, attrsJson); } - if (user.getExternalPosition() != null) { - o.addProperty(EXTERNAL_POSITION, user.getExternalPosition()); - } + this.addProperty(o, EXTERNAL_POSITION, user.getExternalPosition()); JsonObject attrsJson = new JsonObject(); o.add(EXTERNAL_PROFILE, attrsJson); - if (user.getExternalCorpName() != null) { - attrsJson.addProperty(EXTERNAL_CORP_NAME, user.getExternalCorpName()); - } + this.addProperty(attrsJson, EXTERNAL_CORP_NAME, user.getExternalCorpName()); if (user.getWechatChannels() != null) { attrsJson.add(WECHAT_CHANNELS, GsonHelper.buildJsonObject("nickname", user.getWechatChannels().getNickname(), "status", user.getWechatChannels().getStatus())); @@ -374,4 +330,16 @@ public class WxCpUserGsonAdapter implements JsonDeserializer, JsonSeri return o; } + private void addProperty(JsonObject object, String property, Integer value) { + if (value != null) { + object.addProperty(property, value); + } + } + + private void addProperty(JsonObject object, String property, String value) { + if (value != null) { + object.addProperty(property, value); + } + } + } diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaSecCheckService.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaSecCheckService.java index a22061a00..b7721b4e7 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaSecCheckService.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaSecCheckService.java @@ -23,7 +23,7 @@ public interface WxMaSecCheckService { * 应用场景举例: * 1)图片智能鉴黄:涉及拍照的工具类应用(如美拍,识图类应用)用户拍照上传检测;电商类商品上架图片检测;媒体类用户文章里的图片检测等; * 2)敏感人脸识别:用户头像;媒体类用户文章里的图片检测;社交类用户上传的图片检测等。频率限制:单个 appId 调用上限为 1000 次/分钟,100,000 次/天 - * 详情请见: https://developers.weixin.qq.com/miniprogram/dev/api/open-api/sec-check/imgSecCheck.html + * 详情请见: https://developers.weixin.qq.com/miniprogram/dev/api/open-api/sec-check/imgSecCheck.html * * * @param file the file @@ -48,7 +48,7 @@ public interface WxMaSecCheckService { * 用户个人资料违规文字检测; * 媒体新闻类用户发表文章,评论内容检测; * 游戏类用户编辑上传的素材(如答题类小游戏用户上传的问题及答案)检测等。 频率限制:单个 appId 调用上限为 4000 次/分钟,2,000,000 次/天* - * 详情请见: https://developers.weixin.qq.com/miniprogram/dev/api/open-api/sec-check/msgSecCheck.html + * 详情请见: https://developers.weixin.qq.com/miniprogram/dev/api/open-api/sec-check/msgSecCheck.html * * * @param msgString the msg string @@ -61,9 +61,9 @@ public interface WxMaSecCheckService { /** *
    * 检查一段文本是否含有违法违规内容(新版本接口,主要是request和response做了参数优化)
-   * 详情请见: https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/sec-check/security.msgSecCheck.html
+   * 详情请见: https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/sec-check/security.msgSecCheck.html
    * 
- * @param msgRequest + * @param msgRequest request * @return WxMaMsgSecCheckCheckResponse * @throws WxErrorException the wx error exception */ @@ -79,7 +79,7 @@ public interface WxMaSecCheckService { * 频率限制: * 单个 appId 调用上限为 2000 次/分钟,200,000 次/天;文件大小限制:单个文件大小不超过10M * 详情请见: - * https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/sec-check/security.mediaCheckAsync.html + * https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/sec-check/security.mediaCheckAsync.html * * * @param mediaUrl 要检测的多媒体url @@ -89,7 +89,6 @@ public interface WxMaSecCheckService { */ WxMaMediaAsyncCheckResult mediaCheckAsync(String mediaUrl, int mediaType) throws WxErrorException; - /** *
    * 异步校验图片/音频是否含有违法违规内容。(新版本接口,主要对request和respone做了参数优化)
@@ -100,14 +99,14 @@ public interface WxMaSecCheckService {
    * 频率限制:
    * 单个 appId 调用上限为 2000 次/分钟,200,000 次/天;文件大小限制:单个文件大小不超过10M
    * 详情请见:
-   * https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/sec-check/security.mediaCheckAsync.html
+   * https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/sec-check/security.mediaCheckAsync.html
    * 
* - * @param medisRequest + * @param request 请求 * @return wx ma media async check result * @throws WxErrorException the wx error exception */ - WxMaMediaAsyncCheckResult mediaCheckAsync(WxMaMediaSecCheckCheckRequest medisRequest) throws WxErrorException; + WxMaMediaAsyncCheckResult mediaCheckAsync(WxMaMediaSecCheckCheckRequest request) throws WxErrorException; } diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaSecCheckServiceImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaSecCheckServiceImpl.java index 837674eb6..dc69b3f7f 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaSecCheckServiceImpl.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaSecCheckServiceImpl.java @@ -85,8 +85,8 @@ public class WxMaSecCheckServiceImpl implements WxMaSecCheckService { } @Override - public WxMaMediaAsyncCheckResult mediaCheckAsync(WxMaMediaSecCheckCheckRequest medisRequest) throws WxErrorException { - String response = this.service.post(MEDIA_CHECK_ASYNC_URL,medisRequest); + public WxMaMediaAsyncCheckResult mediaCheckAsync(WxMaMediaSecCheckCheckRequest request) throws WxErrorException { + String response = this.service.post(MEDIA_CHECK_ASYNC_URL, request); parseErrorResponse(response); return WxMaGsonBuilder.create().fromJson(response,WxMaMediaAsyncCheckResult.class); } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMerchantInvoiceServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMerchantInvoiceServiceImpl.java index 11883cded..4631a2e2c 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMerchantInvoiceServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMerchantInvoiceServiceImpl.java @@ -1,7 +1,9 @@ package me.chanjar.weixin.mp.api.impl; import com.google.common.collect.ImmutableMap; +import com.google.gson.FieldNamingPolicy; import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; import lombok.AllArgsConstructor; import me.chanjar.weixin.common.error.WxErrorException; @@ -97,7 +99,7 @@ public class WxMpMerchantInvoiceServiceImpl implements WxMpMerchantInvoiceServic */ private T doCommonInvoiceHttpPost(WxMpApiUrl url, Object data, Class resultClass) throws WxErrorException { String json = ""; - final Gson gson = WxMpGsonBuilder.create(); + final Gson gson = this.createGson(); if (data != null) { json = gson.toJson(data); } @@ -108,4 +110,10 @@ public class WxMpMerchantInvoiceServiceImpl implements WxMpMerchantInvoiceServic return gson.fromJson(responseText, resultClass); } + + private Gson createGson() { + GsonBuilder gsonBuilder = new GsonBuilder(); + gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES); + return gsonBuilder.create(); + } } diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/auth/WxOpenAuthorizerInfo.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/auth/WxOpenAuthorizerInfo.java index 1c1dce8ff..b22b66ecb 100644 --- a/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/auth/WxOpenAuthorizerInfo.java +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/auth/WxOpenAuthorizerInfo.java @@ -23,6 +23,15 @@ public class WxOpenAuthorizerInfo implements Serializable { private Map businessInfo; private String alias; private String qrcodeUrl; + /** + * 帐号状态 + * 类型 说明 + * 1 正常 + * 14 已注销 + * 16 已封禁 + * 18 已告警 + * 19 已冻结 + */ private Integer accountStatus; /** * 账号介绍 @@ -35,7 +44,8 @@ public class WxOpenAuthorizerInfo implements Serializable { private MiniProgramInfo miniProgramInfo; @Data - public class MiniProgramInfo { + public static class MiniProgramInfo implements Serializable { + private static final long serialVersionUID = 8857028017332191988L; @SerializedName("visit_status") private Integer visitStatus; /** @@ -45,13 +55,15 @@ public class WxOpenAuthorizerInfo implements Serializable { private List categories; @Data - public class Category { + public static class Category implements Serializable { + private static final long serialVersionUID = -5771529867281696141L; private String first; private String second; } @Data - public class Network { + public static class Network implements Serializable { + private static final long serialVersionUID = -18932624803859857L; @SerializedName("RequestDomain") private List requestDomain; @SerializedName("WsRequestDomain") diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/json/WxOpenAuthorizerInfoGsonAdapter.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/json/WxOpenAuthorizerInfoGsonAdapter.java index 54991b09d..b9dbf49c1 100644 --- a/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/json/WxOpenAuthorizerInfoGsonAdapter.java +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/util/json/WxOpenAuthorizerInfoGsonAdapter.java @@ -12,6 +12,11 @@ import java.util.Map; * @author 007 */ public class WxOpenAuthorizerInfoGsonAdapter implements JsonDeserializer { + + private static final String VERIFY_TYPE_INFO = "verify_type_info"; + private static final String SERVICE_TYPE_INFO = "service_type_info"; + private static final String MINI_PROGRAM_INFO = "MiniProgramInfo"; + @Override public WxOpenAuthorizerInfo deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { WxOpenAuthorizerInfo authorizationInfo = new WxOpenAuthorizerInfo(); @@ -23,21 +28,22 @@ public class WxOpenAuthorizerInfoGsonAdapter implements JsonDeserializer businessInfo = WxOpenGsonBuilder.create().fromJson(jsonObject.get("business_info"), new TypeToken>() { }.getType()); authorizationInfo.setBusinessInfo(businessInfo); - if (jsonObject.has("MiniProgramInfo")) { - WxOpenAuthorizerInfo.MiniProgramInfo miniProgramInfo = WxOpenGsonBuilder.create().fromJson(jsonObject.get("MiniProgramInfo"), + if (jsonObject.has(MINI_PROGRAM_INFO)) { + WxOpenAuthorizerInfo.MiniProgramInfo miniProgramInfo = WxOpenGsonBuilder.create().fromJson(jsonObject.get(MINI_PROGRAM_INFO), new TypeToken() { }.getType()); authorizationInfo.setMiniProgramInfo(miniProgramInfo);