1
1
package me .chanjar .weixin .mp .api .impl ;
2
2
3
+ import java .security .NoSuchAlgorithmException ;
4
+ import java .util .Arrays ;
5
+
6
+ import org .slf4j .Logger ;
7
+ import org .slf4j .LoggerFactory ;
8
+
3
9
import com .google .gson .JsonElement ;
4
10
import com .google .gson .JsonObject ;
5
11
import com .google .gson .JsonParser ;
6
12
import com .google .gson .JsonPrimitive ;
7
- import com .google .gson .internal .Streams ;
8
13
import com .google .gson .reflect .TypeToken ;
9
- import com . google . gson . stream . JsonReader ;
14
+
10
15
import me .chanjar .weixin .common .bean .WxCardApiSignature ;
11
16
import me .chanjar .weixin .common .bean .result .WxError ;
12
17
import me .chanjar .weixin .common .exception .WxErrorException ;
17
22
import me .chanjar .weixin .mp .api .WxMpService ;
18
23
import me .chanjar .weixin .mp .bean .result .WxMpCardResult ;
19
24
import me .chanjar .weixin .mp .util .json .WxMpGsonBuilder ;
20
- import org .slf4j .Logger ;
21
- import org .slf4j .LoggerFactory ;
22
-
23
- import java .io .StringReader ;
24
- import java .security .NoSuchAlgorithmException ;
25
- import java .util .Arrays ;
26
25
27
26
/**
28
27
* Created by Binary Wang on 2016/7/27.
@@ -76,7 +75,7 @@ public String getCardApiTicket(boolean forceRefresh) throws WxErrorException {
76
75
if (this .wxMpService .getWxMpConfigStorage ().isCardApiTicketExpired ()) {
77
76
String url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=wx_card" ;
78
77
String responseContent = this .wxMpService .execute (new SimpleGetRequestExecutor (), url , null );
79
- JsonElement tmpJsonElement = Streams . parse ( new JsonReader ( new StringReader (responseContent )) );
78
+ JsonElement tmpJsonElement = new JsonParser (). parse (responseContent );
80
79
JsonObject tmpJsonObject = tmpJsonElement .getAsJsonObject ();
81
80
String cardApiTicket = tmpJsonObject .get ("ticket" ).getAsString ();
82
81
int expiresInSeconds = tmpJsonObject .get ("expires_in" ).getAsInt ();
@@ -136,7 +135,7 @@ public String decryptCardCode(String encryptCode) throws WxErrorException {
136
135
JsonObject param = new JsonObject ();
137
136
param .addProperty ("encrypt_code" , encryptCode );
138
137
String responseContent = this .wxMpService .post (url , param .toString ());
139
- JsonElement tmpJsonElement = Streams . parse ( new JsonReader ( new StringReader (responseContent )) );
138
+ JsonElement tmpJsonElement = new JsonParser (). parse (responseContent );
140
139
JsonObject tmpJsonObject = tmpJsonElement .getAsJsonObject ();
141
140
JsonPrimitive jsonPrimitive = tmpJsonObject .getAsJsonPrimitive ("code" );
142
141
return jsonPrimitive .getAsString ();
@@ -158,7 +157,7 @@ public WxMpCardResult queryCardCode(String cardId, String code, boolean checkCon
158
157
param .addProperty ("code" , code );
159
158
param .addProperty ("check_consume" , checkConsume );
160
159
String responseContent = this .wxMpService .post (url , param .toString ());
161
- JsonElement tmpJsonElement = Streams . parse ( new JsonReader ( new StringReader (responseContent )) );
160
+ JsonElement tmpJsonElement = new JsonParser (). parse (responseContent );
162
161
return WxMpGsonBuilder .INSTANCE .create ().fromJson (tmpJsonElement ,
163
162
new TypeToken <WxMpCardResult >() {
164
163
}.getType ());
@@ -217,7 +216,7 @@ public void markCardCode(String code, String cardId, String openId, boolean isMa
217
216
param .addProperty ("openid" , openId );
218
217
param .addProperty ("is_mark" , isMark );
219
218
String responseContent = this .wxMpService .post (url , param .toString ());
220
- JsonElement tmpJsonElement = Streams . parse ( new JsonReader ( new StringReader (responseContent )) );
219
+ JsonElement tmpJsonElement = new JsonParser (). parse (responseContent );
221
220
WxMpCardResult cardResult = WxMpGsonBuilder .INSTANCE .create ().fromJson (tmpJsonElement ,
222
221
new TypeToken <WxMpCardResult >() { }.getType ());
223
222
if (!cardResult .getErrorCode ().equals ("0" )) {
0 commit comments