mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-04-05 17:38:05 +08:00
🎨 优化部分文档,重构部分代码
This commit is contained in:
parent
bd821c80c1
commit
5d0364f6d2
@ -199,15 +199,9 @@ public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, 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<WxCpUser>, 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<WxCpUser>, 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<WxCpUser>, 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<WxCpUser>, 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<WxCpUser>, 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
* 详情请见: <a href="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</a>
|
||||
* </pre>
|
||||
*
|
||||
* @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
|
||||
* 详情请见: <a href="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</a>
|
||||
* </pre>
|
||||
*
|
||||
* @param msgString the msg string
|
||||
@ -61,9 +61,9 @@ public interface WxMaSecCheckService {
|
||||
/**
|
||||
* <pre>
|
||||
* 检查一段文本是否含有违法违规内容(新版本接口,主要是request和response做了参数优化)
|
||||
* 详情请见: https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/sec-check/security.msgSecCheck.html
|
||||
* 详情请见: <a href="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</a>
|
||||
* </pre>
|
||||
* @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
|
||||
* <a href="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</a>
|
||||
* </pre>
|
||||
*
|
||||
* @param mediaUrl 要检测的多媒体url
|
||||
@ -89,7 +89,6 @@ public interface WxMaSecCheckService {
|
||||
*/
|
||||
WxMaMediaAsyncCheckResult mediaCheckAsync(String mediaUrl, int mediaType) throws WxErrorException;
|
||||
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 异步校验图片/音频是否含有违法违规内容。(新版本接口,主要对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
|
||||
* <a href="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</a>
|
||||
* </pre>
|
||||
*
|
||||
* @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;
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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> T doCommonInvoiceHttpPost(WxMpApiUrl url, Object data, Class<T> 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();
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,15 @@ public class WxOpenAuthorizerInfo implements Serializable {
|
||||
private Map<String, Integer> 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<Category> 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<String> requestDomain;
|
||||
@SerializedName("WsRequestDomain")
|
||||
|
@ -12,6 +12,11 @@ import java.util.Map;
|
||||
* @author <a href="https://github.com/007gzs">007</a>
|
||||
*/
|
||||
public class WxOpenAuthorizerInfoGsonAdapter implements JsonDeserializer<WxOpenAuthorizerInfo> {
|
||||
|
||||
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<WxOpenA
|
||||
authorizationInfo.setPrincipalName(GsonHelper.getString(jsonObject, "principal_name"));
|
||||
authorizationInfo.setAlias(GsonHelper.getString(jsonObject, "alias"));
|
||||
authorizationInfo.setQrcodeUrl(GsonHelper.getString(jsonObject, "qrcode_url"));
|
||||
authorizationInfo.setAccountStatus(GsonHelper.getInteger(jsonObject, "account_status"));
|
||||
authorizationInfo.setSignature(GsonHelper.getString(jsonObject, "signature"));
|
||||
authorizationInfo.setAccountStatus(GsonHelper.getInteger(jsonObject, "account_status"));
|
||||
|
||||
if (jsonObject.has("service_type_info")) {
|
||||
authorizationInfo.setServiceTypeInfo(GsonHelper.getInteger(jsonObject.getAsJsonObject("service_type_info"), "id"));
|
||||
if (jsonObject.has(SERVICE_TYPE_INFO)) {
|
||||
authorizationInfo.setServiceTypeInfo(GsonHelper.getInteger(jsonObject.getAsJsonObject(SERVICE_TYPE_INFO), "id"));
|
||||
}
|
||||
if (jsonObject.has("verify_type_info")) {
|
||||
authorizationInfo.setVerifyTypeInfo(GsonHelper.getInteger(jsonObject.getAsJsonObject("verify_type_info"), "id"));
|
||||
if (jsonObject.has(VERIFY_TYPE_INFO)) {
|
||||
authorizationInfo.setVerifyTypeInfo(GsonHelper.getInteger(jsonObject.getAsJsonObject(VERIFY_TYPE_INFO), "id"));
|
||||
}
|
||||
Map<String, Integer> businessInfo = WxOpenGsonBuilder.create().fromJson(jsonObject.get("business_info"),
|
||||
new TypeToken<Map<String, Integer>>() {
|
||||
}.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<WxOpenAuthorizerInfo.MiniProgramInfo>() {
|
||||
}.getType());
|
||||
authorizationInfo.setMiniProgramInfo(miniProgramInfo);
|
||||
|
Loading…
Reference in New Issue
Block a user