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