mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
🆕 #3066 【微信支付】增加服务商模式V3查询订单的接口支持
This commit is contained in:
@@ -412,6 +412,53 @@ public interface WxPayService {
|
||||
*/
|
||||
WxPayOrderQueryV3Result queryOrderV3(WxPayOrderQueryV3Request request) throws WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 服务商模式查询订单
|
||||
* 详见 <a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_1_2.shtml">https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_1_2.shtml</a>
|
||||
* 商户可以通过查询订单接口主动查询订单状态,完成下一步的业务逻辑。查询订单状态可通过微信支付订单号或商户订单号两种方式查询
|
||||
* 注意:
|
||||
* 查询订单可通过微信支付订单号和商户订单号两种方式查询,两种查询方式返回结果相同
|
||||
* 需要调用查询接口的情况:
|
||||
* ◆ 当商户后台、网络、服务器等出现异常,商户系统最终未接收到支付通知。
|
||||
* ◆ 调用支付接口后,返回系统错误或未知交易状态情况。
|
||||
* ◆ 调用付款码支付API,返回USERPAYING的状态。
|
||||
* ◆ 调用关单或撤销接口API之前,需确认支付状态。
|
||||
* 接口地址:
|
||||
* https://api.mch.weixin.qq.com/v3/pay/partner/transactions/id/{transaction_id}
|
||||
* https://api.mch.weixin.qq.com/v3/pay/partner/transactions/out-trade-no/{out_trade_no}
|
||||
* </pre>
|
||||
*
|
||||
* @param transactionId 微信订单号
|
||||
* @param outTradeNo 商户系统内部的订单号,当没提供transactionId时需要传这个。
|
||||
* @return the wx pay order query result
|
||||
* @throws WxPayException the wx pay exception
|
||||
*/
|
||||
WxPayPartnerOrderQueryV3Result queryPartnerOrderV3(String transactionId, String outTradeNo) throws WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 服务商模式查询订单
|
||||
* 详见 <a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_1_2.shtml">https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_1_2.shtml</a>
|
||||
* 商户可以通过查询订单接口主动查询订单状态,完成下一步的业务逻辑。查询订单状态可通过微信支付订单号或商户订单号两种方式查询
|
||||
* 注意:
|
||||
* 查询订单可通过微信支付订单号和商户订单号两种方式查询,两种查询方式返回结果相同
|
||||
* 需要调用查询接口的情况:
|
||||
* ◆ 当商户后台、网络、服务器等出现异常,商户系统最终未接收到支付通知。
|
||||
* ◆ 调用支付接口后,返回系统错误或未知交易状态情况。
|
||||
* ◆ 调用付款码支付API,返回USERPAYING的状态。
|
||||
* ◆ 调用关单或撤销接口API之前,需确认支付状态。
|
||||
* 接口地址:
|
||||
* https://api.mch.weixin.qq.com/v3/pay/partner/transactions/id/{transaction_id}
|
||||
* https://api.mch.weixin.qq.com/v3/pay/partner/transactions/out-trade-no/{out_trade_no}
|
||||
* </pre>
|
||||
*
|
||||
* @param request 查询订单请求对象
|
||||
* @return the wx pay order query result
|
||||
* @throws WxPayException the wx pay exception
|
||||
*/
|
||||
WxPayPartnerOrderQueryV3Result queryPartnerOrderV3(WxPayPartnerOrderQueryV3Request request) throws WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 合单查询订单API
|
||||
@@ -602,7 +649,6 @@ public interface WxPayService {
|
||||
* @param tradeType the trade type
|
||||
* @param request 请求对象,注意一些参数如spAppid、spMchid等不用设置,方法内会自动从配置对象中获取到(前提是对应配置中已经设置)
|
||||
* @return the wx pay unified order result
|
||||
* @throws WxPayException the wx pay exception
|
||||
*/
|
||||
WxPayUnifiedOrderV3Result unifiedPartnerOrderV3(PartnerTradeTypeEnum tradeType, WxPayPartnerUnifiedOrderV3Request request) throws WxPayException;
|
||||
|
||||
|
||||
@@ -498,6 +498,31 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
|
||||
return GSON.fromJson(response, WxPayOrderQueryV3Result.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxPayPartnerOrderQueryV3Result queryPartnerOrderV3(String transactionId, String outTradeNo) throws WxPayException {
|
||||
WxPayPartnerOrderQueryV3Request request = new WxPayPartnerOrderQueryV3Request();
|
||||
request.setOutTradeNo(StringUtils.trimToNull(outTradeNo));
|
||||
request.setTransactionId(StringUtils.trimToNull(transactionId));
|
||||
return this.queryPartnerOrderV3(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxPayPartnerOrderQueryV3Result queryPartnerOrderV3(WxPayPartnerOrderQueryV3Request request) throws WxPayException {
|
||||
if (StringUtils.isBlank(request.getSpMchId())) {
|
||||
request.setSpMchId(this.getConfig().getMchId());
|
||||
}
|
||||
if (StringUtils.isBlank(request.getSubMchId())) {
|
||||
request.setSubMchId(this.getConfig().getSubMchId());
|
||||
}
|
||||
String url = String.format("%s/v3/pay/partner/transactions/out-trade-no/%s", this.getPayBaseUrl(), request.getOutTradeNo());
|
||||
if (Objects.isNull(request.getOutTradeNo())) {
|
||||
url = String.format("%s/v3/pay/partner/transactions/id/%s", this.getPayBaseUrl(), request.getTransactionId());
|
||||
}
|
||||
String query = String.format("?sp_mchid=%s&sub_mchid=%s", request.getSpMchId(), request.getSubMchId());
|
||||
String response = this.getV3(url + query);
|
||||
return GSON.fromJson(response, WxPayPartnerOrderQueryV3Result.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CombineQueryResult queryCombine(String combineOutTradeNo) throws WxPayException {
|
||||
String url = String.format("%s/v3/combine-transactions/out-trade-no/%s", this.getPayBaseUrl(), combineOutTradeNo);
|
||||
@@ -691,15 +716,34 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
|
||||
WxPayUnifiedOrderV3Result result = this.unifiedPartnerOrderV3(tradeType, request);
|
||||
//获取应用ID
|
||||
String appId = StringUtils.isBlank(request.getSubAppid()) ? request.getSpAppid() : request.getSubAppid();
|
||||
return result.getPartnerPayInfo(tradeType, appId, request.getSubMchId(), this.getConfig().getPrivateKey());
|
||||
return result.getPayInfo(tradeType.getDirectConnTrade(), appId, request.getSubMchId(), this.getConfig().getPrivateKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxPayUnifiedOrderV3Result unifiedPartnerOrderV3(PartnerTradeTypeEnum tradeType, WxPayPartnerUnifiedOrderV3Request request) throws WxPayException {
|
||||
WxPayUnifiedOrderV3Result result = this.unifiedPartnerOrderV3(tradeType, request);
|
||||
//获取应用ID
|
||||
String appId = StringUtils.isBlank(request.getSubAppid()) ? request.getSpAppid() : request.getSubAppid();
|
||||
return result.getPartnerPayInfo(tradeType, appId, request.getSubMchId(), this.getConfig().getPrivateKey());
|
||||
if (StringUtils.isBlank(request.getSpAppid())) {
|
||||
request.setSpAppid(this.getConfig().getAppId());
|
||||
}
|
||||
|
||||
if (StringUtils.isBlank(request.getSpMchId())) {
|
||||
request.setSpMchId(this.getConfig().getMchId());
|
||||
}
|
||||
|
||||
if (StringUtils.isBlank(request.getNotifyUrl())) {
|
||||
request.setNotifyUrl(this.getConfig().getNotifyUrl());
|
||||
}
|
||||
|
||||
if (StringUtils.isBlank(request.getSubAppid())) {
|
||||
request.setSubAppid(this.getConfig().getSubAppId());
|
||||
}
|
||||
|
||||
if (StringUtils.isBlank(request.getSubMchId())) {
|
||||
request.setSubMchId(this.getConfig().getSubMchId());
|
||||
}
|
||||
|
||||
String url = this.getPayBaseUrl() + tradeType.getPartnerUrl();
|
||||
String response = this.postV3(url, GSON.toJson(request));
|
||||
return GSON.fromJson(response, WxPayUnifiedOrderV3Result.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user