🎨 【小程序】同城配送查询门店余额接口补充了几个遗漏属性,同时优化代码,避免可能出现的NPE问题

This commit is contained in:
GeXiangDong
2024-11-06 21:29:01 +08:00
committed by Binary Wang
parent 9c6fca77e6
commit 5c266d546f
3 changed files with 138 additions and 8 deletions

View File

@@ -302,7 +302,7 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
if (isApiSignatureRequired(url)) {
// 接口需要签名
log.debug("已经配置接口需要签名,接口{}将走加密访问路径", url);
JsonObject jsonObject = GSON.fromJson(postData, JsonObject.class);
JsonObject jsonObject = GSON.fromJson(postData == null ? "{}" : postData, JsonObject.class);
return postWithSignature(url, jsonObject);
} else {
return execute(SimplePostRequestExecutor.create(this), url, postData);
@@ -323,12 +323,12 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
@Override
public String post(String url, ToJson obj) throws WxErrorException {
return this.post(url, obj.toJson());
return this.post(url, obj == null ? "{}" : obj.toJson());
}
@Override
public String post(String url, JsonObject jsonObject) throws WxErrorException {
return this.post(url, jsonObject.toString());
return this.post(url, jsonObject == null ? "{}" : jsonObject.toString());
}
@Override
@@ -845,7 +845,12 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
new GsonBuilder()
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.create();
JsonObject jsonObject = gson.toJsonTree(obj).getAsJsonObject();
JsonObject jsonObject;
if (obj == null) {
jsonObject = gson.fromJson("{}", JsonObject.class);
} else {
jsonObject = gson.toJsonTree(obj).getAsJsonObject();
}
return this.postWithSignature(url, jsonObject);
}