|
19 | 19 | import org.slf4j.Logger;
|
20 | 20 | import org.slf4j.LoggerFactory;
|
21 | 21 |
|
| 22 | +import java.io.UnsupportedEncodingException; |
| 23 | +import java.net.URLDecoder; |
| 24 | +import java.util.HashMap; |
| 25 | +import java.util.Map; |
| 26 | + |
22 | 27 | /**
|
23 | 28 | * 会员卡相关接口的实现类
|
24 | 29 | *
|
@@ -237,7 +242,7 @@ public WxMpMemberCardUserInfoResult getUserInfo(String cardId, String code) thro
|
237 | 242 | jsonObject.addProperty("code", code);
|
238 | 243 |
|
239 | 244 | String responseContent = this.getWxMpService().post(MEMBER_CARD_USER_INFO_GET, jsonObject.toString());
|
240 |
| - log.debug("{}",responseContent); |
| 245 | + log.debug("{}", responseContent); |
241 | 246 | JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
|
242 | 247 | return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement,
|
243 | 248 | new TypeToken<WxMpMemberCardUserInfoResult>() {
|
@@ -280,4 +285,91 @@ public MemberCardActivateUserFormResult setActivateUserForm(MemberCardActivateUs
|
280 | 285 | return MemberCardActivateUserFormResult.fromJson(responseContent);
|
281 | 286 | }
|
282 | 287 |
|
| 288 | + /** |
| 289 | + * 获取会员卡开卡插件参数(跳转型开卡组件需要参数) |
| 290 | + * |
| 291 | + * @param outStr |
| 292 | + * @return |
| 293 | + * @throws WxErrorException |
| 294 | + */ |
| 295 | + public ActivatePluginParam getActivatePluginParam(String cardId, String outStr) throws WxErrorException { |
| 296 | + JsonObject params = new JsonObject(); |
| 297 | + params.addProperty("card_id", cardId); |
| 298 | + params.addProperty("outer_str", outStr); |
| 299 | + String response = this.wxMpService.post(MEMBER_CARD_ACTIVATE_URL, GSON.toJson(params)); |
| 300 | + ActivatePluginParamResult result = GSON.fromJson(response, ActivatePluginParamResult.class); |
| 301 | + if (0 == result.getErrcode()) { |
| 302 | + String url = result.getUrl(); |
| 303 | + try { |
| 304 | + String decodedUrl = URLDecoder.decode(url, "UTF-8"); |
| 305 | + Map<String, String> resultMap = parseRequestUrl(decodedUrl); |
| 306 | + ActivatePluginParam activatePluginParam = new ActivatePluginParam(); |
| 307 | + activatePluginParam.setEncryptCardId(resultMap.get("encrypt_card_id")); |
| 308 | + activatePluginParam.setOuterStr(resultMap.get("outer_str")); |
| 309 | + activatePluginParam.setBiz(resultMap.get("biz")+"=="); |
| 310 | + return activatePluginParam; |
| 311 | + } catch (UnsupportedEncodingException e) { |
| 312 | + e.printStackTrace(); |
| 313 | + } |
| 314 | + } |
| 315 | + return null; |
| 316 | + } |
| 317 | + |
| 318 | + /** |
| 319 | + * 去掉url中的路径,留下请求参数部分 |
| 320 | + * |
| 321 | + * @param strURL url地址 |
| 322 | + * @return url请求参数部分 |
| 323 | + */ |
| 324 | + private static String truncateUrlPage(String strURL) { |
| 325 | + String strAllParam = null; |
| 326 | + String[] arrSplit = null; |
| 327 | + arrSplit = strURL.split("[?]"); |
| 328 | + if (strURL.length() > 1) { |
| 329 | + if (arrSplit.length > 1) { |
| 330 | + if (arrSplit[1] != null) { |
| 331 | + strAllParam = arrSplit[1]; |
| 332 | + } |
| 333 | + } |
| 334 | + } |
| 335 | + |
| 336 | + return strAllParam; |
| 337 | + } |
| 338 | + |
| 339 | + /** |
| 340 | + * 解析出url参数中的键值对 |
| 341 | + * 如 "index.jsp?Action=del&id=123",解析出Action:del,id:123存入map中 |
| 342 | + * |
| 343 | + * @param URL url地址 |
| 344 | + * @return url请求参数部分 |
| 345 | + */ |
| 346 | + public static Map<String, String> parseRequestUrl(String URL) { |
| 347 | + Map<String, String> mapRequest = new HashMap<String, String>(); |
| 348 | + |
| 349 | + String[] arrSplit = null; |
| 350 | + |
| 351 | + String strUrlParam = truncateUrlPage(URL); |
| 352 | + if (strUrlParam == null) { |
| 353 | + return mapRequest; |
| 354 | + } |
| 355 | + arrSplit = strUrlParam.split("[&]"); |
| 356 | + for (String strSplit : arrSplit) { |
| 357 | + String[] arrSplitEqual = null; |
| 358 | + arrSplitEqual = strSplit.split("[=]"); |
| 359 | + |
| 360 | + //解析出键值 |
| 361 | + if (arrSplitEqual.length > 1) { |
| 362 | + //正确解析 |
| 363 | + mapRequest.put(arrSplitEqual[0], arrSplitEqual[1]); |
| 364 | + |
| 365 | + } else { |
| 366 | + if (arrSplitEqual[0] != "") { |
| 367 | + //只有参数没有值,不加入 |
| 368 | + mapRequest.put(arrSplitEqual[0], ""); |
| 369 | + } |
| 370 | + } |
| 371 | + } |
| 372 | + return mapRequest; |
| 373 | + } |
| 374 | + |
283 | 375 | }
|
0 commit comments