Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:Wechat-Group/weixin-java-tools i…
Browse files Browse the repository at this point in the history
…nto develop

* 'develop' of github.com:Wechat-Group/weixin-java-tools:
  发布临时测试版本2.7.6.BETA
  binarywang#178 实现查询代金券批次和信息的接口
  增加会员卡管理服务的`更新会员信息`接口的实现 (binarywang#283)
  binarywang#281 消息路由器增加对EventKey正则表达式匹配的支持
  binarywang#178 实现发送代金券接口
  新增会员卡相关接口 (binarywang#280)
  binarywang#279 统一下单接口参数对象WxPayUnifiedOrderRequest增加fingerprint属性
  update travis settings
  • Loading branch information
comeonc committed Jul 19, 2017
2 parents a956dbd + 66c7ae3 commit fd508b2
Show file tree
Hide file tree
Showing 38 changed files with 2,983 additions and 86 deletions.
20 changes: 10 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
language: java
sudo: false
install: true
addons:
sonarcloud:
token:
secure: "834110c7191f97ecb226970c46dcaff8e681da5a"
#sudo: false
#install: true
#addons:
# sonarcloud:
# token:
# secure: "834110c7191f97ecb226970c46dcaff8e681da5a"

jdk:
- oraclejdk8
#script: "mvn clean package -Dmaven.test.skip=true"
script: "mvn clean package -Dmaven.test.skip=true"

script:
- mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent package sonar:sonar
#script:
# - mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent package sonar:sonar

branches:
only:
Expand All @@ -20,7 +20,7 @@ branches:
cache:
directories:
- '$HOME/.m2/repository'
- '$HOME/.sonar/cache'
# - '$HOME/.sonar/cache'

notifications:
email:
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-parent</artifactId>
<version>2.7.5.BETA</version>
<version>2.7.6.BETA</version>
<packaging>pom</packaging>
<name>WeiXin Java Tools - Parent</name>
<description>微信公众号、企业号上级POM</description>
Expand Down
2 changes: 1 addition & 1 deletion weixin-java-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-parent</artifactId>
<version>2.7.5.BETA</version>
<version>2.7.6.BETA</version>
</parent>

<artifactId>weixin-java-common</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion weixin-java-cp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-parent</artifactId>
<version>2.7.5.BETA</version>
<version>2.7.6.BETA</version>
</parent>

<artifactId>weixin-java-cp</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpXmlMessage;
import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -27,6 +28,8 @@ public class WxCpMessageRouterRule {

private String eventKey;

private String eventKeyRegex;

private String content;

private String rContent;
Expand Down Expand Up @@ -95,6 +98,14 @@ public WxCpMessageRouterRule eventKey(String eventKey) {
return this;
}

/**
* 如果eventKey匹配该正则表达式
*/
public WxCpMessageRouterRule eventKeyRegex(String regex) {
this.eventKeyRegex = regex;
return this;
}

/**
* 如果content等于某值
*
Expand Down Expand Up @@ -207,17 +218,17 @@ protected boolean test(WxCpXmlMessage wxMessage) {
&&
(this.agentId == null || this.agentId.equals(wxMessage.getAgentId()))
&&
(this.msgType == null || this.msgType.equals(wxMessage.getMsgType()))
(this.msgType == null || this.msgType.equalsIgnoreCase(wxMessage.getMsgType()))
&&
(this.event == null || this.event.equalsIgnoreCase(wxMessage.getEvent()))
&&
(this.event == null || this.event.equals(wxMessage.getEvent()))
(this.eventKey == null || this.eventKey.equalsIgnoreCase(wxMessage.getEventKey()))
&&
(this.eventKey == null || this.eventKey.equals(wxMessage.getEventKey()))
(this.eventKeyRegex == null || Pattern.matches(this.eventKeyRegex, StringUtils.trimToEmpty(wxMessage.getEventKey())))
&&
(this.content == null || this.content
.equals(wxMessage.getContent() == null ? null : wxMessage.getContent().trim()))
(this.content == null || this.content.equals(StringUtils.trimToNull(wxMessage.getContent())))
&&
(this.rContent == null || Pattern
.matches(this.rContent, wxMessage.getContent() == null ? "" : wxMessage.getContent().trim()))
(this.rContent == null || Pattern.matches(this.rContent, StringUtils.trimToEmpty(wxMessage.getContent())))
&&
(this.matcher == null || this.matcher.match(wxMessage))
;
Expand Down
2 changes: 1 addition & 1 deletion weixin-java-miniapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-parent</artifactId>
<version>2.7.5.BETA</version>
<version>2.7.6.BETA</version>
</parent>
<artifactId>weixin-java-miniapp</artifactId>
<name>WeiXin Java Tools - MiniApp</name>
Expand Down
2 changes: 1 addition & 1 deletion weixin-java-mp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-parent</artifactId>
<version>2.7.5.BETA</version>
<version>2.7.6.BETA</version>
</parent>
<artifactId>weixin-java-mp</artifactId>
<name>WeiXin Java Tools - MP</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package me.chanjar.weixin.mp.api;

import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardActivatedMessage;
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([email protected])
* @version 2017/7/8
*/
public interface WxMpMemberCardService {

/**
* 得到WxMpService
*/
WxMpService getWxMpService();

/**
* 会员卡激活接口
*
* @param activatedMessage 激活所需参数
* @return 调用返回的JSON字符串。
* @throws WxErrorException 接口调用失败抛出的异常
*/
String activateMemberCard(WxMpMemberCardActivatedMessage activatedMessage) throws WxErrorException;

/**
* 拉取会员信息接口
*
* @param cardId 会员卡的CardId,微信分配
* @param code 领取会员的会员卡Code
* @return 会员信息的结果对象
* @throws WxErrorException 接口调用失败抛出的异常
*/
WxMpMemberCardUserInfoResult getUserInfo(String cardId, String code) throws WxErrorException;

/**
* 当会员持卡消费后,支持开发者调用该接口更新会员信息。会员卡交易后的每次信息变更需通过该接口通知微信,便于后续消息通知及其他扩展功能。
*
* 1.开发者可以同时传入add_bonus和bonus解决由于同步失败带来的幂等性问题。同时传入add_bonus和bonus时
* add_bonus作为积分变动消息中的变量值,而bonus作为卡面上的总积分额度显示。余额变动同理。
* 2.开发者可以传入is_notify_bonus控制特殊的积分对账变动不发送消息,余额变动同理。
*
* @param updateUserMessage 更新会员信息所需字段消息
* @return 调用返回的JSON字符串。
* @throws WxErrorException 接口调用失败抛出的异常
*/
WxMpMemberCardUpdateResult updateUserMemberCard(WxMpMemberCardUpdateMessage updateUserMessage) throws WxErrorException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -26,6 +27,8 @@ public class WxMpMessageRouterRule {

private String eventKey;

private String eventKeyRegex;

private String content;

private String rContent;
Expand Down Expand Up @@ -74,6 +77,14 @@ public WxMpMessageRouterRule eventKey(String eventKey) {
return this;
}

/**
* 如果eventKey匹配该正则表达式
*/
public WxMpMessageRouterRule eventKeyRegex(String regex) {
this.eventKeyRegex = regex;
return this;
}

/**
* 如果content等于某值
*/
Expand Down Expand Up @@ -170,17 +181,17 @@ protected boolean test(WxMpXmlMessage wxMessage) {
return
(this.fromUser == null || this.fromUser.equals(wxMessage.getFromUser()))
&&
(this.msgType == null || this.msgType.toLowerCase().equals((wxMessage.getMsgType() == null ? null : wxMessage.getMsgType().toLowerCase())))
(this.msgType == null || this.msgType.equalsIgnoreCase(wxMessage.getMsgType()))
&&
(this.event == null || this.event.equalsIgnoreCase(wxMessage.getEvent()))
&&
(this.event == null || this.event.toLowerCase().equals((wxMessage.getEvent() == null ? null : wxMessage.getEvent().toLowerCase())))
(this.eventKey == null || this.eventKey.equalsIgnoreCase(wxMessage.getEventKey()))
&&
(this.eventKey == null || this.eventKey.toLowerCase().equals((wxMessage.getEventKey() == null ? null : wxMessage.getEventKey().toLowerCase())))
(this.eventKeyRegex == null || Pattern.matches(this.eventKeyRegex, StringUtils.trimToEmpty(wxMessage.getEventKey())))
&&
(this.content == null || this.content
.equals(wxMessage.getContent() == null ? null : wxMessage.getContent().trim()))
(this.content == null || this.content.equals(StringUtils.trimToNull(wxMessage.getContent())))
&&
(this.rContent == null || Pattern
.matches(this.rContent, wxMessage.getContent() == null ? "" : wxMessage.getContent().trim()))
(this.rContent == null || Pattern.matches(this.rContent, StringUtils.trimToEmpty(wxMessage.getContent())))
&&
(this.matcher == null || this.matcher.match(wxMessage))
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,13 @@ public interface WxMpService {
*/
WxMpShakeService getShakeService();

/**
* 返回会员卡相关接口方法的实现类对象,以方便调用其各个接口
*
* @return WxMpMemberCardService
*/
WxMpMemberCardService getMemberCardService();

/**
* 初始化http请求对象
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public abstract class AbstractWxMpServiceImpl<H, P> implements WxMpService, Requ
private WxMpTemplateMsgService templateMsgService = new WxMpTemplateMsgServiceImpl(this);
private WxMpDeviceService deviceService = new WxMpDeviceServiceImpl(this);
private WxMpShakeService shakeService = new WxMpShakeServiceImpl(this);
private WxMpMemberCardService memberCardService = new WxMpMemberCardServiceImpl(this);

private int retrySleepMillis = 1000;
private int maxRetryTimes = 5;
Expand Down Expand Up @@ -406,6 +407,11 @@ public WxMpShakeService getShakeService() {
return this.shakeService;
}

@Override
public WxMpMemberCardService getMemberCardService() {
return this.memberCardService;
}

@Override
public RequestHttp getRequestHttp() {
return this;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package me.chanjar.weixin.mp.api.impl;

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 me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpMemberCardService;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardActivatedMessage;
import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardUpdateMessage;
import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardUpdateResult;
import me.chanjar.weixin.mp.bean.membercard.WxMpMemberCardUserInfoResult;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* 会员卡相关接口的实现类
*
* @author YuJian([email protected])
* @version 2017/7/8
*/
public class WxMpMemberCardServiceImpl implements WxMpMemberCardService {

private final Logger log = LoggerFactory.getLogger(WxMpMemberCardServiceImpl.class);

private static final String MEMBER_CARD_ACTIVATE = "https://api.weixin.qq.com/card/membercard/activate";
private static final String MEMBER_CARD_USER_INFO_GET = "https://api.weixin.qq.com/card/membercard/userinfo/get";
private static final String MEMBER_CARD_UPDATE_USER = "https://api.weixin.qq.com/card/membercard/updateuser";

private WxMpService wxMpService;

private static final Gson GSON = new Gson();

WxMpMemberCardServiceImpl(WxMpService wxMpService) {
this.wxMpService = wxMpService;
}

/**
* 得到WxMpService
*/
@Override
public WxMpService getWxMpService() {
return this.wxMpService;
}

/**
* 会员卡激活接口
*
* @param activatedMessage 激活所需参数
* @return 调用返回的JSON字符串。
* @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();
jsonObject.addProperty("card_id", cardId);
jsonObject.addProperty("code",code);

String responseContent = this.getWxMpService().post(MEMBER_CARD_USER_INFO_GET, jsonObject.toString());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement,
new TypeToken<WxMpMemberCardUserInfoResult>() {
}.getType());
}

/**
* 当会员持卡消费后,支持开发者调用该接口更新会员信息。会员卡交易后的每次信息变更需通过该接口通知微信,便于后续消息通知及其他扩展功能。
*
* 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 {

String responseContent = this.getWxMpService().post(MEMBER_CARD_UPDATE_USER, GSON.toJson(updateUserMessage));

JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement,
new TypeToken<WxMpMemberCardUpdateResult>() {
}.getType());
}
}
Loading

0 comments on commit fd508b2

Please sign in to comment.