Skip to content

Commit f2e251a

Browse files
committed
修复部分导致warning的代码
1 parent a7846f9 commit f2e251a

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
import com.google.gson.JsonArray;
44
import com.google.gson.JsonElement;
55
import com.google.gson.JsonObject;
6-
import com.google.gson.internal.Streams;
7-
import com.google.gson.stream.JsonReader;
6+
import com.google.gson.JsonParser;
87
import me.chanjar.weixin.common.bean.WxAccessToken;
98
import me.chanjar.weixin.common.bean.WxJsapiSignature;
109
import me.chanjar.weixin.common.bean.result.WxError;
@@ -29,11 +28,12 @@
2928
import org.slf4j.LoggerFactory;
3029

3130
import java.io.IOException;
32-
import java.io.StringReader;
3331
import java.security.NoSuchAlgorithmException;
3432

3533
public class WxMpServiceImpl implements WxMpService {
3634

35+
private static final JsonParser JSON_PARSER = new JsonParser();
36+
3737
protected final Logger log = LoggerFactory.getLogger(WxMpServiceImpl.class);
3838

3939
/**
@@ -141,7 +141,7 @@ public String getJsapiTicket(boolean forceRefresh) throws WxErrorException {
141141
if (this.wxMpConfigStorage.isJsapiTicketExpired()) {
142142
String url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi";
143143
String responseContent = execute(new SimpleGetRequestExecutor(), url, null);
144-
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
144+
JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent);
145145
JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject();
146146
String jsapiTicket = tmpJsonObject.get("ticket").getAsString();
147147
int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt();
@@ -224,15 +224,15 @@ public String shortUrl(String long_url) throws WxErrorException {
224224
o.addProperty("action", "long2short");
225225
o.addProperty("long_url", long_url);
226226
String responseContent = execute(new SimplePostRequestExecutor(), url, o.toString());
227-
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
227+
JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent);
228228
return tmpJsonElement.getAsJsonObject().get("short_url").getAsString();
229229
}
230230

231231
@Override
232232
public String templateSend(WxMpTemplateMessage templateMessage) throws WxErrorException {
233233
String url = "https://api.weixin.qq.com/cgi-bin/message/template/send";
234234
String responseContent = execute(new SimplePostRequestExecutor(), url, templateMessage.toJson());
235-
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
235+
JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent);
236236
final JsonObject jsonObject = tmpJsonElement.getAsJsonObject();
237237
if (jsonObject.get("errcode").getAsInt() == 0){
238238
return jsonObject.get("msgid").getAsString();
@@ -356,7 +356,7 @@ public boolean oauth2validateAccessToken(WxMpOAuth2AccessToken oAuth2AccessToken
356356
public String[] getCallbackIP() throws WxErrorException {
357357
String url = "https://api.weixin.qq.com/cgi-bin/getcallbackip";
358358
String responseContent = get(url, null);
359-
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
359+
JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent);
360360
JsonArray ipList = tmpJsonElement.getAsJsonObject().get("ip_list").getAsJsonArray();
361361
String[] ipArray = new String[ipList.size()];
362362
for (int i = 0; i < ipList.size(); i++) {

0 commit comments

Comments
 (0)