Skip to content

Commit

Permalink
#320 增加“拉取订单评价数据“接口方法
Browse files Browse the repository at this point in the history
  • Loading branch information
binarywang committed Sep 2, 2017
1 parent 4347033 commit a5c6126
Show file tree
Hide file tree
Showing 8 changed files with 292 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@ public abstract class WxPayBaseRequest {
@XStreamAlias("sign")
protected String sign;

/**
* <pre>
* 签名类型
* sign_type
* 否
* String(32)
* HMAC-SHA256
* 签名类型,目前支持HMAC-SHA256和MD5
* </pre>
*/
@XStreamAlias("sign_type")
private String signType;

/**
* 将单位为元转换为单位为分
*
Expand Down Expand Up @@ -187,6 +200,14 @@ public void setSubMchId(String subMchId) {
this.subMchId = subMchId;
}

public String getSignType() {
return signType;
}

public void setSignType(String signType) {
this.signType = signType;
}

@Override
public String toString() {
return ToStringUtils.toSimpleString(this);
Expand Down Expand Up @@ -230,9 +251,8 @@ public void checkAndSign(WxPayConfig config) throws WxPayException {
if (StringUtils.isBlank(getNonceStr())) {
this.setNonceStr(String.valueOf(System.currentTimeMillis()));
}

//设置签名字段的值
this.setSign(SignUtils.createSign(this, config.getMchKey()));
this.setSign(SignUtils.createSign(this, config.getMchKey(), this.signType));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package com.github.binarywang.wxpay.bean.request;

import com.github.binarywang.wxpay.exception.WxPayException;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import me.chanjar.weixin.common.annotation.Required;

/**
* <pre>
* 拉取订单评价数据接口的请求参数封装类
* Created by BinaryWang on 2017/9/2.
* </pre>
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
@XStreamAlias("xml")
public class WxPayQueryCommentRequest extends WxPayBaseRequest {
/**
* <pre>
* 字段名:开始时间
* 变量名:begin_time
* 是否必填:是
* 类型:String(19)
* 示例值:20170724000000
* 描述:按用户评论时间批量拉取的起始时间,格式为yyyyMMddHHmmss
* </pre>
*/
@Required
@XStreamAlias("begin_time")
private String beginTime;

/**
* <pre>
* 字段名:结束时间
* 变量名:end_time
* 是否必填:是
* 类型:String(19)
* 示例值:20170725000000
* 描述:按用户评论时间批量拉取的结束时间,格式为yyyyMMddHHmmss
* </pre>
*/
@Required
@XStreamAlias("end_time")
private String endTime;

/**
* <pre>
* 字段名:位移
* 变量名:offset
* 是否必填:是
* 类型:uint(64)
* 示例值:0
* 描述:指定从某条记录的下一条开始返回记录。接口调用成功时,会返回本次查询最后一条数据的offset。商户需要翻页时,应该把本次调用返回的offset 作为下次调用的入参。注意offset是评论数据在微信支付后台保存的索引,未必是连续的
* </pre>
*/
@Required
@XStreamAlias("offset")
private Integer offset;

/**
* <pre>
* 字段名:条数
* 变量名:limit
* 是否必填:否
* 类型:uint(32)
* 示例值:100
* 描述:一次拉取的条数, 最大值是200,默认是200
* </pre>
*/
@XStreamAlias("limit")
private Integer limit;

/**
* 检查约束情况
*/
@Override
protected void checkConstraints() throws WxPayException {

}

public String getBeginTime() {
return beginTime;
}

public void setBeginTime(String beginTime) {
this.beginTime = beginTime;
}

public String getEndTime() {
return endTime;
}

public void setEndTime(String endTime) {
this.endTime = endTime;
}

public Integer getOffset() {
return offset;
}

public void setOffset(Integer offset) {
this.offset = offset;
}

public Integer getLimit() {
return limit;
}

public void setLimit(Integer limit) {
this.limit = limit;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.github.binarywang.wxpay.constant;

import java.text.SimpleDateFormat;

/**
* <pre>
* 微信支付常量类
Expand All @@ -9,6 +11,12 @@
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
public class WxPayConstants {

/**
* 拉取订单评价数据接口的参数中日期格式
*/
public static final SimpleDateFormat QUERY_COMMENT_DATE_FORMAT = new SimpleDateFormat("yyyyMMddHHmmss");

/**
* 校验用户姓名选项,企业付款时使用
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.github.binarywang.wxpay.exception.WxPayException;

import java.io.File;
import java.util.Date;
import java.util.Map;

/**
Expand Down Expand Up @@ -115,8 +116,8 @@ WxPayRefundQueryResult refundQuery(String transactionId, String outTradeNo, Stri
throws WxPayException;

/**
* @deprecated use WxPayService#parseOrderNotifyResult(String) instead
* @see WxPayService#parseOrderNotifyResult(String)
* @deprecated use WxPayService#parseOrderNotifyResult(String) instead
*/
@Deprecated
WxPayOrderNotifyResult getOrderNotifyResult(String xmlData) throws WxPayException;
Expand Down Expand Up @@ -389,4 +390,23 @@ WxPayRefundQueryResult refundQuery(String transactionId, String outTradeNo, Stri
* 获取微信请求数据,方便接口调用方获取处理
*/
WxPayApiData getWxApiData();

/**
* <pre>
* 拉取订单评价数据
* 商户可以通过该接口拉取用户在微信支付交易记录中针对你的支付记录进行的评价内容。商户可结合商户系统逻辑对该内容数据进行存储、分析、展示、客服回访以及其他使用。如商户业务对评价内容有依赖,可主动引导用户进入微信支付交易记录进行评价。
* 注意:
* 1. 该内容所有权为提供内容的微信用户,商户在使用内容的过程中应遵从用户意愿
* 2. 一次最多拉取200条评价数据,可根据时间区间分批次拉取
* 3. 接口只能拉取最近三个月以内的评价数据
* 接口链接:https://api.mch.weixin.qq.com/billcommentsp/batchquerycomment
* 是否需要证书:需要
* 文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_17&index=10
* </pre>
* @param beginDate 开始时间
* @param endDate 结束时间
* @param offset 位移
* @param limit 条数
*/
String queryComment(Date beginDate, Date endDate, Integer offset, Integer limit) throws WxPayException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.*;

import static com.github.binarywang.wxpay.constant.WxPayConstants.QUERY_COMMENT_DATE_FORMAT;

/**
* <pre>
Expand Down Expand Up @@ -237,7 +236,7 @@ public <T> T createOrder(WxPayUnifiedOrderRequest request) throws WxPayException
configMap.put("appid", appId);

payResult = WxPayAppOrderResult.newBuilder()
.sign(SignUtils.createSign(configMap, this.getConfig().getMchKey()))
.sign(SignUtils.createSign(configMap, this.getConfig().getMchKey(), null))
.prepayId(prepayId)
.partnerId(partnerId)
.appId(appId)
Expand All @@ -256,7 +255,7 @@ public <T> T createOrder(WxPayUnifiedOrderRequest request) throws WxPayException
.signType(SignType.MD5)
.build();
((WxPayMpOrderResult) payResult)
.setPaySign(SignUtils.createSign(payResult, this.getConfig().getMchKey()));
.setPaySign(SignUtils.createSign(payResult, this.getConfig().getMchKey(), null));
break;
}
}
Expand Down Expand Up @@ -303,7 +302,7 @@ public Map<String, String> getPayInfo(WxPayUnifiedOrderRequest request) throws W
configMap.put("noncestr", nonceStr);
configMap.put("appid", appId);
// 此map用于客户端与微信服务器交互
payInfo.put("sign", SignUtils.createSign(configMap, this.getConfig().getMchKey()));
payInfo.put("sign", SignUtils.createSign(configMap, this.getConfig().getMchKey(), null));
payInfo.put("prepayId", prepayId);
payInfo.put("partnerId", partnerId);
payInfo.put("appId", appId);
Expand All @@ -317,7 +316,7 @@ public Map<String, String> getPayInfo(WxPayUnifiedOrderRequest request) throws W
payInfo.put("nonceStr", nonceStr);
payInfo.put("package", "prepay_id=" + prepayId);
payInfo.put("signType", SignType.MD5);
payInfo.put("paySign", SignUtils.createSign(payInfo, this.getConfig().getMchKey()));
payInfo.put("paySign", SignUtils.createSign(payInfo, this.getConfig().getMchKey(), null));
}

return payInfo;
Expand Down Expand Up @@ -364,7 +363,7 @@ public String createScanPayQrcodeMode1(String productId) {
params.put("time_stamp", String.valueOf(System.currentTimeMillis() / 1000));//这里需要秒,10位数字
params.put("nonce_str", String.valueOf(System.currentTimeMillis()));

String sign = SignUtils.createSign(params, this.getConfig().getMchKey());
String sign = SignUtils.createSign(params, this.getConfig().getMchKey(), null);
params.put("sign", sign);

for (String key : params.keySet()) {
Expand Down Expand Up @@ -411,15 +410,13 @@ public WxPayBillResult downloadBill(String billDate, String billType, String tar
String url = this.getPayBaseUrl() + "/pay/downloadbill";
String responseContent = this.post(url, request.toXML(), false);
if (responseContent.startsWith("<")) {
WxPayCommonResult result = WxPayBaseResult.fromXML(responseContent, WxPayCommonResult.class);
result.checkResult(this);
return null;
throw WxPayException.from(WxPayBaseResult.fromXML(responseContent, WxPayCommonResult.class));
} else {
return billInformationDeal(responseContent);
return this.handleBillInformation(responseContent);
}
}

private WxPayBillResult billInformationDeal(String responseContent) {
private WxPayBillResult handleBillInformation(String responseContent) {
WxPayBillResult wxPayBillResult = new WxPayBillResult();

String listStr = "";
Expand Down Expand Up @@ -597,4 +594,25 @@ public WxPayApiData getWxApiData() {
wxApiData.remove();
}
}

@Override
public String queryComment(Date beginDate, Date endDate, Integer offset, Integer limit) throws WxPayException {
WxPayQueryCommentRequest request = new WxPayQueryCommentRequest();
request.setBeginTime(QUERY_COMMENT_DATE_FORMAT.format(beginDate));
request.setEndTime(QUERY_COMMENT_DATE_FORMAT.format(endDate));
request.setOffset(offset);
request.setLimit(limit);
request.setSignType(SignType.HMAC_SHA256);

request.checkAndSign(this.getConfig());

String url = this.getPayBaseUrl() + "/billcommentsp/batchquerycomment";

String responseContent = this.post(url, request.toXML(), true);
if (responseContent.startsWith("<")) {
throw WxPayException.from(WxPayBaseResult.fromXML(responseContent, WxPayCommonResult.class));
}

return responseContent;
}
}

0 comments on commit a5c6126

Please sign in to comment.