mirror of
				https://gitee.com/binary/weixin-java-tools.git
				synced 2025-10-31 18:46:10 +08:00 
			
		
		
		
	修复部分可能造成resource leak的代码
This commit is contained in:
		| @ -1,12 +1,17 @@ | |||||||
| package me.chanjar.weixin.mp.api.impl; | package me.chanjar.weixin.mp.api.impl; | ||||||
|  |  | ||||||
|  | import java.security.NoSuchAlgorithmException; | ||||||
|  | import java.util.Arrays; | ||||||
|  |  | ||||||
|  | import org.slf4j.Logger; | ||||||
|  | import org.slf4j.LoggerFactory; | ||||||
|  |  | ||||||
| import com.google.gson.JsonElement; | import com.google.gson.JsonElement; | ||||||
| import com.google.gson.JsonObject; | import com.google.gson.JsonObject; | ||||||
| import com.google.gson.JsonParser; | import com.google.gson.JsonParser; | ||||||
| import com.google.gson.JsonPrimitive; | import com.google.gson.JsonPrimitive; | ||||||
| import com.google.gson.internal.Streams; |  | ||||||
| import com.google.gson.reflect.TypeToken; | import com.google.gson.reflect.TypeToken; | ||||||
| import com.google.gson.stream.JsonReader; |  | ||||||
| import me.chanjar.weixin.common.bean.WxCardApiSignature; | import me.chanjar.weixin.common.bean.WxCardApiSignature; | ||||||
| import me.chanjar.weixin.common.bean.result.WxError; | import me.chanjar.weixin.common.bean.result.WxError; | ||||||
| import me.chanjar.weixin.common.exception.WxErrorException; | import me.chanjar.weixin.common.exception.WxErrorException; | ||||||
| @ -17,12 +22,6 @@ import me.chanjar.weixin.mp.api.WxMpCardService; | |||||||
| import me.chanjar.weixin.mp.api.WxMpService; | import me.chanjar.weixin.mp.api.WxMpService; | ||||||
| import me.chanjar.weixin.mp.bean.result.WxMpCardResult; | import me.chanjar.weixin.mp.bean.result.WxMpCardResult; | ||||||
| import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | ||||||
| import org.slf4j.Logger; |  | ||||||
| import org.slf4j.LoggerFactory; |  | ||||||
|  |  | ||||||
| import java.io.StringReader; |  | ||||||
| import java.security.NoSuchAlgorithmException; |  | ||||||
| import java.util.Arrays; |  | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Created by Binary Wang on 2016/7/27. |  * Created by Binary Wang on 2016/7/27. | ||||||
| @ -76,7 +75,7 @@ public class WxMpCardServiceImpl implements WxMpCardService { | |||||||
|         if (this.wxMpService.getWxMpConfigStorage().isCardApiTicketExpired()) { |         if (this.wxMpService.getWxMpConfigStorage().isCardApiTicketExpired()) { | ||||||
|           String url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=wx_card"; |           String url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=wx_card"; | ||||||
|           String responseContent = this.wxMpService.execute(new SimpleGetRequestExecutor(), url, null); |           String responseContent = this.wxMpService.execute(new SimpleGetRequestExecutor(), url, null); | ||||||
|           JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent))); |           JsonElement tmpJsonElement = new JsonParser().parse(responseContent); | ||||||
|           JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject(); |           JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject(); | ||||||
|           String cardApiTicket = tmpJsonObject.get("ticket").getAsString(); |           String cardApiTicket = tmpJsonObject.get("ticket").getAsString(); | ||||||
|           int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt(); |           int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt(); | ||||||
| @ -136,7 +135,7 @@ public class WxMpCardServiceImpl implements WxMpCardService { | |||||||
|     JsonObject param = new JsonObject(); |     JsonObject param = new JsonObject(); | ||||||
|     param.addProperty("encrypt_code", encryptCode); |     param.addProperty("encrypt_code", encryptCode); | ||||||
|     String responseContent = this.wxMpService.post(url, param.toString()); |     String responseContent = this.wxMpService.post(url, param.toString()); | ||||||
|     JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent))); |     JsonElement tmpJsonElement = new JsonParser().parse(responseContent); | ||||||
|     JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject(); |     JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject(); | ||||||
|     JsonPrimitive jsonPrimitive = tmpJsonObject.getAsJsonPrimitive("code"); |     JsonPrimitive jsonPrimitive = tmpJsonObject.getAsJsonPrimitive("code"); | ||||||
|     return jsonPrimitive.getAsString(); |     return jsonPrimitive.getAsString(); | ||||||
| @ -158,7 +157,7 @@ public class WxMpCardServiceImpl implements WxMpCardService { | |||||||
|     param.addProperty("code", code); |     param.addProperty("code", code); | ||||||
|     param.addProperty("check_consume", checkConsume); |     param.addProperty("check_consume", checkConsume); | ||||||
|     String responseContent = this.wxMpService.post(url, param.toString()); |     String responseContent = this.wxMpService.post(url, param.toString()); | ||||||
|     JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent))); |     JsonElement tmpJsonElement = new JsonParser().parse(responseContent); | ||||||
|     return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement, |     return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement, | ||||||
|             new TypeToken<WxMpCardResult>() { |             new TypeToken<WxMpCardResult>() { | ||||||
|             }.getType()); |             }.getType()); | ||||||
| @ -217,7 +216,7 @@ public class WxMpCardServiceImpl implements WxMpCardService { | |||||||
|     param.addProperty("openid", openId); |     param.addProperty("openid", openId); | ||||||
|     param.addProperty("is_mark", isMark); |     param.addProperty("is_mark", isMark); | ||||||
|     String responseContent = this.wxMpService.post(url, param.toString()); |     String responseContent = this.wxMpService.post(url, param.toString()); | ||||||
|     JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent))); |     JsonElement tmpJsonElement = new JsonParser().parse(responseContent); | ||||||
|     WxMpCardResult cardResult = WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement, |     WxMpCardResult cardResult = WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement, | ||||||
|             new TypeToken<WxMpCardResult>() { }.getType()); |             new TypeToken<WxMpCardResult>() { }.getType()); | ||||||
|     if (!cardResult.getErrorCode().equals("0")) { |     if (!cardResult.getErrorCode().equals("0")) { | ||||||
|  | |||||||
| @ -1,10 +1,12 @@ | |||||||
| package me.chanjar.weixin.mp.api.impl; | package me.chanjar.weixin.mp.api.impl; | ||||||
|  |  | ||||||
|  | import java.util.List; | ||||||
|  |  | ||||||
| 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.reflect.TypeToken; | import com.google.gson.reflect.TypeToken; | ||||||
| import com.google.gson.stream.JsonReader; |  | ||||||
| import me.chanjar.weixin.common.exception.WxErrorException; | import me.chanjar.weixin.common.exception.WxErrorException; | ||||||
| import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor; | import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor; | ||||||
| import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; | import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; | ||||||
| @ -14,9 +16,6 @@ import me.chanjar.weixin.mp.api.WxMpService; | |||||||
| import me.chanjar.weixin.mp.bean.WxMpGroup; | import me.chanjar.weixin.mp.bean.WxMpGroup; | ||||||
| import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | ||||||
|  |  | ||||||
| import java.io.StringReader; |  | ||||||
| import java.util.List; |  | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Created by Binary Wang on 2016/7/21. |  * Created by Binary Wang on 2016/7/21. | ||||||
|  */ |  */ | ||||||
| @ -51,7 +50,7 @@ public class WxMpGroupServiceImpl implements WxMpGroupService { | |||||||
|      * 操蛋的微信API,创建时返回的是 { group : { id : ..., name : ...} } |      * 操蛋的微信API,创建时返回的是 { group : { id : ..., name : ...} } | ||||||
|      * 查询时返回的是 { groups : [ { id : ..., name : ..., count : ... }, ... ] } |      * 查询时返回的是 { groups : [ { id : ..., name : ..., count : ... }, ... ] } | ||||||
|      */ |      */ | ||||||
|     JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent))); |     JsonElement tmpJsonElement = new JsonParser().parse(responseContent); | ||||||
|     return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("groups"), |     return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("groups"), | ||||||
|             new TypeToken<List<WxMpGroup>>() { |             new TypeToken<List<WxMpGroup>>() { | ||||||
|             }.getType()); |             }.getType()); | ||||||
| @ -63,7 +62,7 @@ public class WxMpGroupServiceImpl implements WxMpGroupService { | |||||||
|     JsonObject o = new JsonObject(); |     JsonObject o = new JsonObject(); | ||||||
|     o.addProperty("openid", openid); |     o.addProperty("openid", openid); | ||||||
|     String responseContent = this.wxMpService.execute(new SimplePostRequestExecutor(), url, o.toString()); |     String responseContent = this.wxMpService.execute(new SimplePostRequestExecutor(), url, o.toString()); | ||||||
|     JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent))); |     JsonElement tmpJsonElement = new JsonParser().parse(responseContent); | ||||||
|     return GsonHelper.getAsLong(tmpJsonElement.getAsJsonObject().get("groupid")); |     return GsonHelper.getAsLong(tmpJsonElement.getAsJsonObject().get("groupid")); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 BinaryWang
					BinaryWang