mirror of
				https://gitee.com/binary/weixin-java-tools.git
				synced 2025-10-31 02:28:25 +08:00 
			
		
		
		
	#856 修复会员卡有效期判断问题
This commit is contained in:
		| @ -1,11 +1,20 @@ | ||||
| package me.chanjar.weixin.mp.api; | ||||
|  | ||||
| import me.chanjar.weixin.common.error.WxErrorException; | ||||
| import me.chanjar.weixin.mp.bean.card.*; | ||||
| import me.chanjar.weixin.mp.bean.membercard.*; | ||||
| import me.chanjar.weixin.mp.bean.card.CardUpdateResult; | ||||
| import me.chanjar.weixin.mp.bean.card.MemberCardActivateUserFormRequest; | ||||
| import me.chanjar.weixin.mp.bean.card.MemberCardActivateUserFormResult; | ||||
| import me.chanjar.weixin.mp.bean.card.MemberCardUpdateRequest; | ||||
| import me.chanjar.weixin.mp.bean.card.WxMpCardCreateResult; | ||||
| import me.chanjar.weixin.mp.bean.membercard.ActivatePluginParam; | ||||
| import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardActivatedMessage; | ||||
| import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardCreateMessage; | ||||
| import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardUpdateMessage; | ||||
| import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardUpdateResult; | ||||
| import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardUserInfoResult; | ||||
|  | ||||
| /** | ||||
|  * 会员卡相关接口 | ||||
|  * 会员卡相关接口. | ||||
|  * | ||||
|  * @author YuJian(mgcnrx11 @ gmail.com) | ||||
|  * @author yuanqixun | ||||
| @ -18,46 +27,38 @@ public interface WxMpMemberCardService { | ||||
|   String MEMBER_CARD_USER_INFO_GET = "https://api.weixin.qq.com/card/membercard/userinfo/get"; | ||||
|   String MEMBER_CARD_UPDATE_USER = "https://api.weixin.qq.com/card/membercard/updateuser"; | ||||
|   /** | ||||
|    * 会员卡激活之微信开卡接口(wx_activate=true情况调用) | ||||
|    * 会员卡激活之微信开卡接口(wx_activate=true情况调用). | ||||
|    */ | ||||
|   String MEMBER_CARD_ACTIVATEUSERFORM = "https://api.weixin.qq.com/card/membercard/activateuserform/set"; | ||||
|  | ||||
|   /** | ||||
|    * 获取会员卡开卡插件参数 | ||||
|    * 获取会员卡开卡插件参数. | ||||
|    */ | ||||
|   String MEMBER_CARD_ACTIVATE_URL = "https://api.weixin.qq.com/card/membercard/activate/geturl"; | ||||
|  | ||||
|   /** | ||||
|    * 会员卡信息更新 | ||||
|    * 会员卡信息更新. | ||||
|    */ | ||||
|   String MEMBER_CARD_UPDATE = "https://api.weixin.qq.com/card/update"; | ||||
|  | ||||
|  | ||||
|   /** | ||||
|    * 得到WxMpService | ||||
|    * 得到WxMpService. | ||||
|    */ | ||||
|   WxMpService getWxMpService(); | ||||
|  | ||||
|   /** | ||||
|    * 会员卡创建接口 | ||||
|    * | ||||
|    * @param createJson | ||||
|    * @return | ||||
|    * @throws WxErrorException | ||||
|    * 会员卡创建接口. | ||||
|    */ | ||||
|   WxMpCardCreateResult createMemberCard(String createJson) throws WxErrorException; | ||||
|  | ||||
|   /** | ||||
|    * 会员卡创建接口 | ||||
|    * | ||||
|    * @param createMessageMessage | ||||
|    * @return WxMpCardCreateResult | ||||
|    * @throws WxErrorException | ||||
|    * 会员卡创建接口. | ||||
|    */ | ||||
|   WxMpCardCreateResult createMemberCard(WxMpMemberCardCreateMessage createMessageMessage) throws WxErrorException; | ||||
|  | ||||
|   /** | ||||
|    * 会员卡激活接口 | ||||
|    * 会员卡激活接口. | ||||
|    * | ||||
|    * @param activatedMessage 激活所需参数 | ||||
|    * @return 返回json字符串 | ||||
| @ -66,7 +67,7 @@ public interface WxMpMemberCardService { | ||||
|   String activateMemberCard(WxMpMemberCardActivatedMessage activatedMessage) throws WxErrorException; | ||||
|  | ||||
|   /** | ||||
|    * 拉取会员信息接口 | ||||
|    * 拉取会员信息接口. | ||||
|    * | ||||
|    * @param cardId 会员卡的CardId,微信分配 | ||||
|    * @param code   领取会员的会员卡Code | ||||
| @ -76,10 +77,10 @@ public interface WxMpMemberCardService { | ||||
|   WxMpMemberCardUserInfoResult getUserInfo(String cardId, String code) throws WxErrorException; | ||||
|  | ||||
|   /** | ||||
|    * 当会员持卡消费后,支持开发者调用该接口更新会员信息。会员卡交易后的每次信息变更需通过该接口通知微信,便于后续消息通知及其他扩展功能。 | ||||
|    * <p> | ||||
|    * 1.开发者可以同时传入add_bonus和bonus解决由于同步失败带来的幂等性问题。同时传入add_bonus和bonus时 | ||||
|    * add_bonus作为积分变动消息中的变量值,而bonus作为卡面上的总积分额度显示。余额变动同理。 | ||||
|    * 当会员持卡消费后,支持开发者调用该接口更新会员信息. | ||||
|    * 会员卡交易后的每次信息变更需通过该接口通知微信,便于后续消息通知及其他扩展功能。 | ||||
|    * 1.开发者可以同时传入add_bonus和bonus解决由于同步失败带来的幂等性问题。 | ||||
|    * 同时传入add_bonus和bonus时 add_bonus作为积分变动消息中的变量值,而bonus作为卡面上的总积分额度显示。余额变动同理。 | ||||
|    * 2.开发者可以传入is_notify_bonus控制特殊的积分对账变动不发送消息,余额变动同理。 | ||||
|    * | ||||
|    * @param updateUserMessage 更新会员信息所需字段消息 | ||||
| @ -89,29 +90,17 @@ public interface WxMpMemberCardService { | ||||
|   WxMpMemberCardUpdateResult updateUserMemberCard(WxMpMemberCardUpdateMessage updateUserMessage) throws WxErrorException; | ||||
|  | ||||
|   /** | ||||
|    * 设置会员卡激活的字段(会员卡设置:wx_activate=true 时需要) | ||||
|    * | ||||
|    * @param userFormRequest | ||||
|    * @return | ||||
|    * @throws WxErrorException | ||||
|    * 设置会员卡激活的字段(会员卡设置:wx_activate=true 时需要). | ||||
|    */ | ||||
|   MemberCardActivateUserFormResult setActivateUserForm(MemberCardActivateUserFormRequest userFormRequest) throws WxErrorException; | ||||
|  | ||||
|   /** | ||||
|    * 获取会员卡开卡插件参数(跳转型开卡组件需要参数) | ||||
|    * | ||||
|    * @param cardId | ||||
|    * @param outStr | ||||
|    * @return | ||||
|    * @throws WxErrorException | ||||
|    * 获取会员卡开卡插件参数(跳转型开卡组件需要参数). | ||||
|    */ | ||||
|   ActivatePluginParam getActivatePluginParam(String cardId, String outStr) throws WxErrorException; | ||||
|  | ||||
|   /** | ||||
|    * 更新会员卡信息 | ||||
|    * @param memberCardUpdateRequest | ||||
|    * @return | ||||
|    * @throws WxErrorException | ||||
|    * 更新会员卡信息. | ||||
|    */ | ||||
|   CardUpdateResult updateCardInfo(MemberCardUpdateRequest memberCardUpdateRequest) throws WxErrorException; | ||||
| } | ||||
|  | ||||
| @ -5,20 +5,28 @@ import java.net.URLDecoder; | ||||
| import java.util.HashMap; | ||||
| import java.util.Map; | ||||
|  | ||||
| import me.chanjar.weixin.mp.bean.card.*; | ||||
| import org.apache.commons.lang3.StringUtils; | ||||
| import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
|  | ||||
| import com.google.gson.Gson; | ||||
| import com.google.gson.JsonElement; | ||||
| import com.google.gson.JsonObject; | ||||
| import com.google.gson.JsonParser; | ||||
| import com.google.gson.reflect.TypeToken; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import me.chanjar.weixin.common.error.WxErrorException; | ||||
| import me.chanjar.weixin.common.util.json.WxGsonBuilder; | ||||
| import me.chanjar.weixin.mp.api.WxMpMemberCardService; | ||||
| import me.chanjar.weixin.mp.api.WxMpService; | ||||
| import me.chanjar.weixin.mp.bean.card.AdvancedInfo; | ||||
| import me.chanjar.weixin.mp.bean.card.BaseInfo; | ||||
| import me.chanjar.weixin.mp.bean.card.CardUpdateResult; | ||||
| import me.chanjar.weixin.mp.bean.card.DateInfo; | ||||
| import me.chanjar.weixin.mp.bean.card.MemberCard; | ||||
| import me.chanjar.weixin.mp.bean.card.MemberCardActivateUserFormRequest; | ||||
| import me.chanjar.weixin.mp.bean.card.MemberCardActivateUserFormResult; | ||||
| import me.chanjar.weixin.mp.bean.card.MemberCardCreateRequest; | ||||
| import me.chanjar.weixin.mp.bean.card.MemberCardUpdateRequest; | ||||
| import me.chanjar.weixin.mp.bean.card.WxMpCardCreateResult; | ||||
| import me.chanjar.weixin.mp.bean.card.enums.BusinessServiceType; | ||||
| import me.chanjar.weixin.mp.bean.card.enums.CardColor; | ||||
| import me.chanjar.weixin.mp.bean.card.enums.DateInfoType; | ||||
| @ -37,10 +45,8 @@ import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; | ||||
|  * @author YuJian(mgcnrx11 @ gmail.com) | ||||
|  * @version 2017/7/8 | ||||
|  */ | ||||
| @Slf4j | ||||
| public class WxMpMemberCardServiceImpl implements WxMpMemberCardService { | ||||
|  | ||||
|   private final Logger log = LoggerFactory.getLogger(WxMpMemberCardServiceImpl.class); | ||||
|  | ||||
|   private WxMpService wxMpService; | ||||
|  | ||||
|   private static final Gson GSON = WxMpGsonBuilder.create(); | ||||
| @ -49,50 +55,37 @@ public class WxMpMemberCardServiceImpl implements WxMpMemberCardService { | ||||
|     this.wxMpService = wxMpService; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 得到WxMpService | ||||
|    */ | ||||
|   @Override | ||||
|   public WxMpService getWxMpService() { | ||||
|     return this.wxMpService; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 会员卡创建接口 | ||||
|    * | ||||
|    * @param createJson 创建json | ||||
|    * @return 调用返回的JSON字符串。 | ||||
|    * @throws WxErrorException 接口调用失败抛出的异常 | ||||
|    */ | ||||
|   @Override | ||||
|   public WxMpCardCreateResult createMemberCard(String createJson) throws WxErrorException { | ||||
|     WxMpMemberCardCreateMessage createMessage = WxGsonBuilder.create().fromJson(createJson, WxMpMemberCardCreateMessage.class); | ||||
|     WxMpMemberCardCreateMessage createMessage = WxGsonBuilder.create() | ||||
|       .fromJson(createJson, WxMpMemberCardCreateMessage.class); | ||||
|     return createMemberCard(createMessage); | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 会员卡创建接口 | ||||
|    * | ||||
|    * @param createMessageMessage 创建所需参数 | ||||
|    * @return WxMpCardCreateResult。 | ||||
|    * @throws WxErrorException 接口调用失败抛出的异常 | ||||
|    */ | ||||
|   @Override | ||||
|   public WxMpCardCreateResult createMemberCard(WxMpMemberCardCreateMessage createMessageMessage) throws WxErrorException { | ||||
|   public WxMpCardCreateResult createMemberCard(WxMpMemberCardCreateMessage createMessageMessage) | ||||
|     throws WxErrorException { | ||||
|     //校验请求对象合法性 | ||||
|     WxMpCardCreateResult validResult = validCheck(createMessageMessage); | ||||
|     if (!validResult.isSuccess()) | ||||
|     if (!validResult.isSuccess()) { | ||||
|       return validResult; | ||||
|     } | ||||
|  | ||||
|     String response = this.wxMpService.post(MEMBER_CARD_CREAET, GSON.toJson(createMessageMessage)); | ||||
|     return WxMpCardCreateResult.fromJson(response); | ||||
|   } | ||||
|  | ||||
|   private WxMpCardCreateResult validCheck(WxMpMemberCardCreateMessage createMessageMessage) throws WxErrorException { | ||||
|   private WxMpCardCreateResult validCheck(WxMpMemberCardCreateMessage createMessageMessage) { | ||||
|     if (createMessageMessage == null) { | ||||
|       return WxMpCardCreateResult.failure("对象不能为空"); | ||||
|     } | ||||
|     MemberCardCreateRequest cardCreateRequest = createMessageMessage.getCardCreateRequest(); | ||||
|     if (createMessageMessage == null) { | ||||
|     if (cardCreateRequest == null) { | ||||
|       return WxMpCardCreateResult.failure("会员卡对象不能为空"); | ||||
|     } | ||||
|     String cardType = cardCreateRequest.getCardType(); | ||||
| @ -105,17 +98,11 @@ public class WxMpMemberCardServiceImpl implements WxMpMemberCardService { | ||||
|       return WxMpCardCreateResult.failure("会员卡特权说明不能为空:prerogative"); | ||||
|     } | ||||
|     //卡片激活规则 | ||||
|     if (!memberCard.isAutoActivate() && !memberCard.isWxActivate() && StringUtils.isEmpty(memberCard.getActivateUrl())) { | ||||
|     if (!memberCard.isAutoActivate() && !memberCard.isWxActivate() | ||||
|       && StringUtils.isEmpty(memberCard.getActivateUrl())) { | ||||
|       return WxMpCardCreateResult.failure("会员卡激活方式为接口激活,activate_url不能为空"); | ||||
|     } | ||||
|  | ||||
|     //积分支持 | ||||
| //    if(memberCard.isSupplyBonus() && StringUtils.isEmpty(memberCard.getBonusUrl())){ | ||||
| //      return WxMpCardCreateResult.failure("会员卡支持积分,bonus_url不能为空"); | ||||
| //    } | ||||
| //    if(memberCard.isSupplyBonus() && memberCard.getBonusRule() == null){ | ||||
| //      return WxMpCardCreateResult.failure("会员卡支持积分,bonus_rule不能为空"); | ||||
| //    } | ||||
|     BaseInfo baseInfo = memberCard.getBaseInfo(); | ||||
|     if (baseInfo == null) { | ||||
|       return WxMpCardCreateResult.failure("会员卡基本信息对象base_info不能为空"); | ||||
| @ -188,16 +175,24 @@ public class WxMpMemberCardServiceImpl implements WxMpMemberCardService { | ||||
|     } | ||||
|  | ||||
|     //固定时长 | ||||
|     if (dateInfoType == DateInfoType.DATE_TYPE_FIX_TERM && (dateInfo.getFixedTerm() == null || dateInfo.getFixedBeginTerm() == null)) { | ||||
|       return WxMpCardCreateResult.failure("会员卡基本信息的使用日期为:" + dateInfoType.getDescription() + ",fixedTerm和fixedBeginTerm不能为空"); | ||||
|     if (dateInfoType == DateInfoType.DATE_TYPE_FIX_TERM | ||||
|       && (dateInfo.getFixedTerm() == null || dateInfo.getFixedBeginTerm() == null)) { | ||||
|       return WxMpCardCreateResult.failure(String.format("会员卡基本信息的使用日期为:%s,fixedTerm和fixedBeginTerm不能为空", | ||||
|         dateInfoType.getDescription())); | ||||
|     } | ||||
|  | ||||
|     //固定期限 | ||||
|     if (dateInfoType == DateInfoType.DATE_TYPE_FIX_TIME_RANGE && (dateInfo.getBeginTimestamp() == null || dateInfo.getEndTimestamp() == null)) { | ||||
|       return WxMpCardCreateResult.failure("会员卡基本信息的使用日期为:" + dateInfoType.getDescription() + ",beginTimestamp 和 endTimestamp 不能为空"); | ||||
|     if (dateInfoType == DateInfoType.DATE_TYPE_FIX_TIME_RANGE | ||||
|       && (dateInfo.getBeginTimestamp() == null || dateInfo.getEndTimestamp() == null)) { | ||||
|       return WxMpCardCreateResult.failure(String.format("会员卡基本信息的使用日期为:%s,beginTimestamp 和 endTimestamp 不能为空", | ||||
|         dateInfoType.getDescription())); | ||||
|     } | ||||
|     if (dateInfoType == DateInfoType.DATE_TYPE_FIX_TIME_RANGE && (dateInfo.getBeginTimestamp() < System.currentTimeMillis() || dateInfo.getEndTimestamp() < System.currentTimeMillis() || dateInfo.getBeginTimestamp() > dateInfo.getEndTimestamp())) { | ||||
|       return WxMpCardCreateResult.failure("会员卡基本信息的使用日期为:" + dateInfoType.getDescription() + ",beginTimestamp和endTimestamp的值不合法,请检查"); | ||||
|     if (dateInfoType == DateInfoType.DATE_TYPE_FIX_TIME_RANGE | ||||
|       && (dateInfo.getBeginTimestamp() * 1000 < System.currentTimeMillis() | ||||
|       || dateInfo.getEndTimestamp() * 1000 < System.currentTimeMillis() | ||||
|       || dateInfo.getBeginTimestamp() > dateInfo.getEndTimestamp())) { | ||||
|       return WxMpCardCreateResult.failure(String.format("会员卡基本信息的使用日期为:%s,beginTimestamp和endTimestamp的值不合法,请检查", | ||||
|         dateInfoType.getDescription())); | ||||
|     } | ||||
|  | ||||
|     if (!baseInfo.isUseAllLocations() && StringUtils.isBlank(baseInfo.getLocationIdList())) { | ||||
| @ -209,9 +204,8 @@ public class WxMpMemberCardServiceImpl implements WxMpMemberCardService { | ||||
|     if (advancedInfo != null) { | ||||
|       if (advancedInfo.getBusinessServiceList() != null) { | ||||
|         for (String bs : advancedInfo.getBusinessServiceList()) { | ||||
|           BusinessServiceType businessServiceType = null; | ||||
|           try { | ||||
|             businessServiceType = BusinessServiceType.valueOf(bs); | ||||
|             BusinessServiceType.valueOf(bs); | ||||
|           } catch (IllegalArgumentException ex) { | ||||
|             return WxMpCardCreateResult.failure("会员卡高级信息的商户服务:" + bs + " 不合法"); | ||||
|           } | ||||
| @ -222,26 +216,11 @@ public class WxMpMemberCardServiceImpl implements WxMpMemberCardService { | ||||
|     return WxMpCardCreateResult.success(); | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 会员卡激活接口 | ||||
|    * | ||||
|    * @param activatedMessage 激活所需参数 | ||||
|    * @return WxMpCardCreateResult。 | ||||
|    * @throws WxErrorException 接口调用失败抛出的异常 | ||||
|    */ | ||||
|   @Override | ||||
|   public String activateMemberCard(WxMpMemberCardActivatedMessage activatedMessage) throws WxErrorException { | ||||
|     return this.wxMpService.post(MEMBER_CARD_ACTIVATE, GSON.toJson(activatedMessage)); | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 拉取会员信息接口 | ||||
|    * | ||||
|    * @param cardId 会员卡的CardId,微信分配 | ||||
|    * @param code   领取会员的会员卡Code | ||||
|    * @return 会员信息的结果对象 | ||||
|    * @throws WxErrorException 接口调用失败抛出的异常 | ||||
|    */ | ||||
|   @Override | ||||
|   public WxMpMemberCardUserInfoResult getUserInfo(String cardId, String code) throws WxErrorException { | ||||
|     JsonObject jsonObject = new JsonObject(); | ||||
| @ -256,17 +235,6 @@ public class WxMpMemberCardServiceImpl implements WxMpMemberCardService { | ||||
|       }.getType()); | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 当会员持卡消费后,支持开发者调用该接口更新会员信息。会员卡交易后的每次信息变更需通过该接口通知微信,便于后续消息通知及其他扩展功能。 | ||||
|    * <p> | ||||
|    * 1.开发者可以同时传入add_bonus和bonus解决由于同步失败带来的幂等性问题。同时传入add_bonus和bonus时 | ||||
|    * add_bonus作为积分变动消息中的变量值,而bonus作为卡面上的总积分额度显示。余额变动同理。 | ||||
|    * 2.开发者可以传入is_notify_bonus控制特殊的积分对账变动不发送消息,余额变动同理。 | ||||
|    * | ||||
|    * @param updateUserMessage 更新会员信息所需字段消息 | ||||
|    * @return 调用返回的JSON字符串。 | ||||
|    * @throws WxErrorException 接口调用失败抛出的异常 | ||||
|    */ | ||||
|   @Override | ||||
|   public WxMpMemberCardUpdateResult updateUserMemberCard(WxMpMemberCardUpdateMessage updateUserMessage) | ||||
|     throws WxErrorException { | ||||
| @ -279,26 +247,13 @@ public class WxMpMemberCardServiceImpl implements WxMpMemberCardService { | ||||
|       }.getType()); | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 设置会员卡激活的字段(会员卡设置:wx_activate=true 时需要) | ||||
|    * | ||||
|    * @param userFormRequest | ||||
|    * @return | ||||
|    * @throws WxErrorException | ||||
|    */ | ||||
|   @Override | ||||
|   public MemberCardActivateUserFormResult setActivateUserForm(MemberCardActivateUserFormRequest userFormRequest) throws WxErrorException { | ||||
|     String responseContent = this.getWxMpService().post(MEMBER_CARD_ACTIVATEUSERFORM, GSON.toJson(userFormRequest)); | ||||
|     return MemberCardActivateUserFormResult.fromJson(responseContent); | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 获取会员卡开卡插件参数(跳转型开卡组件需要参数) | ||||
|    * | ||||
|    * @param outStr | ||||
|    * @return | ||||
|    * @throws WxErrorException | ||||
|    */ | ||||
|   @Override | ||||
|   public ActivatePluginParam getActivatePluginParam(String cardId, String outStr) throws WxErrorException { | ||||
|     JsonObject params = new JsonObject(); | ||||
|     params.addProperty("card_id", cardId); | ||||
| @ -313,7 +268,7 @@ public class WxMpMemberCardServiceImpl implements WxMpMemberCardService { | ||||
|         ActivatePluginParam activatePluginParam = new ActivatePluginParam(); | ||||
|         activatePluginParam.setEncryptCardId(resultMap.get("encrypt_card_id")); | ||||
|         activatePluginParam.setOuterStr(resultMap.get("outer_str")); | ||||
|         activatePluginParam.setBiz(resultMap.get("biz")+"=="); | ||||
|         activatePluginParam.setBiz(resultMap.get("biz") + "=="); | ||||
|         return activatePluginParam; | ||||
|       } catch (UnsupportedEncodingException e) { | ||||
|         e.printStackTrace(); | ||||
| @ -322,13 +277,6 @@ public class WxMpMemberCardServiceImpl implements WxMpMemberCardService { | ||||
|     return null; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 更新会员卡信息 | ||||
|    * | ||||
|    * @param memberCardUpdateRequest | ||||
|    * @return | ||||
|    * @throws WxErrorException | ||||
|    */ | ||||
|   @Override | ||||
|   public CardUpdateResult updateCardInfo(MemberCardUpdateRequest memberCardUpdateRequest) throws WxErrorException { | ||||
|     String response = this.wxMpService.post(MEMBER_CARD_UPDATE, GSON.toJson(memberCardUpdateRequest)); | ||||
| @ -336,15 +284,9 @@ public class WxMpMemberCardServiceImpl implements WxMpMemberCardService { | ||||
|     return result; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 去掉url中的路径,留下请求参数部分 | ||||
|    * | ||||
|    * @param strURL url地址 | ||||
|    * @return url请求参数部分 | ||||
|    */ | ||||
|   private static String truncateUrlPage(String strURL) { | ||||
|     String strAllParam = null; | ||||
|     String[] arrSplit = null; | ||||
|     String[] arrSplit; | ||||
|     arrSplit = strURL.split("[?]"); | ||||
|     if (strURL.length() > 1) { | ||||
|       if (arrSplit.length > 1) { | ||||
| @ -357,25 +299,18 @@ public class WxMpMemberCardServiceImpl implements WxMpMemberCardService { | ||||
|     return strAllParam; | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 解析出url参数中的键值对 | ||||
|    * 如 "index.jsp?Action=del&id=123",解析出Action:del,id:123存入map中 | ||||
|    * | ||||
|    * @param URL url地址 | ||||
|    * @return url请求参数部分 | ||||
|    */ | ||||
|   public static Map<String, String> parseRequestUrl(String URL) { | ||||
|     Map<String, String> mapRequest = new HashMap<String, String>(); | ||||
|   public static Map<String, String> parseRequestUrl(String url) { | ||||
|     Map<String, String> mapRequest = new HashMap<>(16); | ||||
|  | ||||
|     String[] arrSplit = null; | ||||
|     String[] arrSplit; | ||||
|  | ||||
|     String strUrlParam = truncateUrlPage(URL); | ||||
|     String strUrlParam = truncateUrlPage(url); | ||||
|     if (strUrlParam == null) { | ||||
|       return mapRequest; | ||||
|     } | ||||
|     arrSplit = strUrlParam.split("[&]"); | ||||
|     for (String strSplit : arrSplit) { | ||||
|       String[] arrSplitEqual = null; | ||||
|       String[] arrSplitEqual; | ||||
|       arrSplitEqual = strSplit.split("[=]"); | ||||
|  | ||||
|       //解析出键值 | ||||
| @ -384,7 +319,7 @@ public class WxMpMemberCardServiceImpl implements WxMpMemberCardService { | ||||
|         mapRequest.put(arrSplitEqual[0], arrSplitEqual[1]); | ||||
|  | ||||
|       } else { | ||||
|         if (arrSplitEqual[0] != "") { | ||||
|         if (!"".equals(arrSplitEqual[0])) { | ||||
|           //只有参数没有值,不加入 | ||||
|           mapRequest.put(arrSplitEqual[0], ""); | ||||
|         } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Binary Wang
					Binary Wang