修复部分导致warning的代码

This commit is contained in:
BinaryWang 2016-08-22 16:07:41 +08:00
parent a7846f9da8
commit f2e251a09d

View File

@ -3,8 +3,7 @@ package me.chanjar.weixin.mp.api.impl;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.internal.Streams; import com.google.gson.JsonParser;
import com.google.gson.stream.JsonReader;
import me.chanjar.weixin.common.bean.WxAccessToken; import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.bean.WxJsapiSignature; import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.common.bean.result.WxError; import me.chanjar.weixin.common.bean.result.WxError;
@ -29,11 +28,12 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
public class WxMpServiceImpl implements WxMpService { public class WxMpServiceImpl implements WxMpService {
private static final JsonParser JSON_PARSER = new JsonParser();
protected final Logger log = LoggerFactory.getLogger(WxMpServiceImpl.class); protected final Logger log = LoggerFactory.getLogger(WxMpServiceImpl.class);
/** /**
@ -141,7 +141,7 @@ public class WxMpServiceImpl implements WxMpService {
if (this.wxMpConfigStorage.isJsapiTicketExpired()) { if (this.wxMpConfigStorage.isJsapiTicketExpired()) {
String url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi"; String url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi";
String responseContent = execute(new SimpleGetRequestExecutor(), url, null); String responseContent = execute(new SimpleGetRequestExecutor(), url, null);
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent))); JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent);
JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject(); JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject();
String jsapiTicket = tmpJsonObject.get("ticket").getAsString(); String jsapiTicket = tmpJsonObject.get("ticket").getAsString();
int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt(); int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt();
@ -224,7 +224,7 @@ public class WxMpServiceImpl implements WxMpService {
o.addProperty("action", "long2short"); o.addProperty("action", "long2short");
o.addProperty("long_url", long_url); o.addProperty("long_url", long_url);
String responseContent = execute(new SimplePostRequestExecutor(), url, o.toString()); String responseContent = execute(new SimplePostRequestExecutor(), url, o.toString());
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent))); JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent);
return tmpJsonElement.getAsJsonObject().get("short_url").getAsString(); return tmpJsonElement.getAsJsonObject().get("short_url").getAsString();
} }
@ -232,7 +232,7 @@ public class WxMpServiceImpl implements WxMpService {
public String templateSend(WxMpTemplateMessage templateMessage) throws WxErrorException { public String templateSend(WxMpTemplateMessage templateMessage) throws WxErrorException {
String url = "https://api.weixin.qq.com/cgi-bin/message/template/send"; String url = "https://api.weixin.qq.com/cgi-bin/message/template/send";
String responseContent = execute(new SimplePostRequestExecutor(), url, templateMessage.toJson()); String responseContent = execute(new SimplePostRequestExecutor(), url, templateMessage.toJson());
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent))); JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent);
final JsonObject jsonObject = tmpJsonElement.getAsJsonObject(); final JsonObject jsonObject = tmpJsonElement.getAsJsonObject();
if (jsonObject.get("errcode").getAsInt() == 0){ if (jsonObject.get("errcode").getAsInt() == 0){
return jsonObject.get("msgid").getAsString(); return jsonObject.get("msgid").getAsString();
@ -356,7 +356,7 @@ public class WxMpServiceImpl implements WxMpService {
public String[] getCallbackIP() throws WxErrorException { public String[] getCallbackIP() throws WxErrorException {
String url = "https://api.weixin.qq.com/cgi-bin/getcallbackip"; String url = "https://api.weixin.qq.com/cgi-bin/getcallbackip";
String responseContent = get(url, null); String responseContent = get(url, null);
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent))); JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent);
JsonArray ipList = tmpJsonElement.getAsJsonObject().get("ip_list").getAsJsonArray(); JsonArray ipList = tmpJsonElement.getAsJsonObject().get("ip_list").getAsJsonArray();
String[] ipArray = new String[ipList.size()]; String[] ipArray = new String[ipList.size()];
for (int i = 0; i < ipList.size(); i++) { for (int i = 0; i < ipList.size(); i++) {