#320 增加“拉取订单评价数据“接口方法

This commit is contained in:
Binary Wang
2017-09-02 23:48:33 +08:00
parent 434703327b
commit a5c61268ef
8 changed files with 292 additions and 31 deletions

View File

@@ -10,6 +10,7 @@ import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.exception.WxPayException;
import java.io.File;
import java.util.Date;
import java.util.Map;
/**
@@ -115,8 +116,8 @@ public interface WxPayService {
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;
@@ -389,4 +390,23 @@ public interface WxPayService {
* 获取微信请求数据,方便接口调用方获取处理
*/
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;
}

View File

@@ -23,10 +23,9 @@ import org.slf4j.Logger;
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>
@@ -237,7 +236,7 @@ public abstract class WxPayServiceAbstractImpl implements WxPayService {
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)
@@ -256,7 +255,7 @@ public abstract class WxPayServiceAbstractImpl implements WxPayService {
.signType(SignType.MD5)
.build();
((WxPayMpOrderResult) payResult)
.setPaySign(SignUtils.createSign(payResult, this.getConfig().getMchKey()));
.setPaySign(SignUtils.createSign(payResult, this.getConfig().getMchKey(), null));
break;
}
}
@@ -303,7 +302,7 @@ public abstract class WxPayServiceAbstractImpl implements WxPayService {
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);
@@ -317,7 +316,7 @@ public abstract class WxPayServiceAbstractImpl implements WxPayService {
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;
@@ -364,7 +363,7 @@ public abstract class WxPayServiceAbstractImpl implements WxPayService {
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()) {
@@ -411,15 +410,13 @@ public abstract class WxPayServiceAbstractImpl implements WxPayService {
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 = "";
@@ -597,4 +594,25 @@ public abstract class WxPayServiceAbstractImpl implements WxPayService {
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;
}
}