|
3 | 3 | import com.google.gson.JsonArray;
|
4 | 4 | import com.google.gson.JsonElement;
|
5 | 5 | 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; |
8 | 7 | import me.chanjar.weixin.common.bean.WxAccessToken;
|
9 | 8 | import me.chanjar.weixin.common.bean.WxJsapiSignature;
|
10 | 9 | import me.chanjar.weixin.common.bean.result.WxError;
|
|
29 | 28 | import org.slf4j.LoggerFactory;
|
30 | 29 |
|
31 | 30 | import java.io.IOException;
|
32 |
| -import java.io.StringReader; |
33 | 31 | import java.security.NoSuchAlgorithmException;
|
34 | 32 |
|
35 | 33 | public class WxMpServiceImpl implements WxMpService {
|
36 | 34 |
|
| 35 | + private static final JsonParser JSON_PARSER = new JsonParser(); |
| 36 | + |
37 | 37 | protected final Logger log = LoggerFactory.getLogger(WxMpServiceImpl.class);
|
38 | 38 |
|
39 | 39 | /**
|
@@ -141,7 +141,7 @@ public String getJsapiTicket(boolean forceRefresh) throws WxErrorException {
|
141 | 141 | if (this.wxMpConfigStorage.isJsapiTicketExpired()) {
|
142 | 142 | String url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi";
|
143 | 143 | String responseContent = execute(new SimpleGetRequestExecutor(), url, null);
|
144 |
| - JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent))); |
| 144 | + JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent); |
145 | 145 | JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject();
|
146 | 146 | String jsapiTicket = tmpJsonObject.get("ticket").getAsString();
|
147 | 147 | int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt();
|
@@ -224,15 +224,15 @@ public String shortUrl(String long_url) throws WxErrorException {
|
224 | 224 | o.addProperty("action", "long2short");
|
225 | 225 | o.addProperty("long_url", long_url);
|
226 | 226 | 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); |
228 | 228 | return tmpJsonElement.getAsJsonObject().get("short_url").getAsString();
|
229 | 229 | }
|
230 | 230 |
|
231 | 231 | @Override
|
232 | 232 | public String templateSend(WxMpTemplateMessage templateMessage) throws WxErrorException {
|
233 | 233 | String url = "https://api.weixin.qq.com/cgi-bin/message/template/send";
|
234 | 234 | 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); |
236 | 236 | final JsonObject jsonObject = tmpJsonElement.getAsJsonObject();
|
237 | 237 | if (jsonObject.get("errcode").getAsInt() == 0){
|
238 | 238 | return jsonObject.get("msgid").getAsString();
|
@@ -356,7 +356,7 @@ public boolean oauth2validateAccessToken(WxMpOAuth2AccessToken oAuth2AccessToken
|
356 | 356 | public String[] getCallbackIP() throws WxErrorException {
|
357 | 357 | String url = "https://api.weixin.qq.com/cgi-bin/getcallbackip";
|
358 | 358 | String responseContent = get(url, null);
|
359 |
| - JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent))); |
| 359 | + JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent); |
360 | 360 | JsonArray ipList = tmpJsonElement.getAsJsonObject().get("ip_list").getAsJsonArray();
|
361 | 361 | String[] ipArray = new String[ipList.size()];
|
362 | 362 | for (int i = 0; i < ipList.size(); i++) {
|
|
0 commit comments