微信查询订单

This commit is contained in:
gong
2026-01-14 11:28:00 +08:00
parent e8be5dee9d
commit e798781ca0
3 changed files with 65 additions and 10 deletions

View File

@@ -11,6 +11,7 @@ import com.czg.PayCst;
import com.czg.dto.req.PayParamsDto;
import com.czg.exception.CzgException;
import com.czg.third.alipay.dto.config.AlipayConfigDto;
import com.czg.third.wechat.dto.config.WechatPayConfigDto;
import lombok.extern.slf4j.Slf4j;
import java.math.BigDecimal;
@@ -82,6 +83,10 @@ public class AlipayIsvPayManager {
}
}
public static Map<String, Object> queryOrder(AlipayConfigDto configDto, String orderNo, String subMerchantId) {
return new HashMap<>();
}
/**
* 金额转换
*/

View File

@@ -195,6 +195,53 @@ public class WechatPayManager {
}
}
/**
* 查询订单
* @param configDto 配置
* @param orderNo 订单号
* @param subMerchantId 子商户号
* SUCCESS支付成功
* REFUND转入退款
* NOTPAY未支付
* CLOSED已关闭
* REVOKED已撤销仅付款码支付会返回
* USERPAYING用户支付中仅付款码支付会返回
* PAYERROR支付失败仅付款码支付会返回
*/
public static Map<String, Object> queryOrder(WechatPayConfigDto configDto, String orderNo, String subMerchantId) {
try {
if (configDto == null) {
configDto = WechatPayConfigDto.getDefaultConfig();
}
String resp = WechatReqUtils.getReq(configDto, "/v3/pay/partner/transactions/out-trade-no/" + orderNo,
Map.of("sp_mchid", configDto.getMerchantId(), "sub_mchid", subMerchantId));
log.info("微信查询订单,订单号:{} 响应:{}", orderNo, resp);
JSONObject res = new JSONObject();
res.put("orderNo", orderNo);
JSONObject object = JSONObject.parseObject(resp);
String tradeState = object.getString("trade_state");
res.put("message", object.getString("trade_state_desc"));
if (PAY_SUCCESS.equals(tradeState)) {
res.put("status", "TRADE_SUCCESS");
return res;
}
if ("USERPAYING".equals(tradeState)) {
res.put("status", "TRADE_AWAIT");
return res;
}
res.put("status", "TRADE_FAIL");
return res;
} catch (Exception e) {
log.error("微信查询订单异常: orderNo = {}, e = {}", orderNo, e.getMessage());
throw new CzgException("微信查询订单异常");
}
}
/**
* 将String转换为InputStream
* @param str 待转换的字符串
@@ -231,14 +278,17 @@ public class WechatPayManager {
}
public static void main(String[] args) {
barPay(null, new PayParamsDto()
.setMerchantId("1738216504")
.setOrderNo("sa101293120sss1")
.setTitle("1213")
.setBody("1213")
.setAmount(1L)
.setAppId("wxd88fffa983758a30")
.setClientIp("127.0.0.1")
.setBarCode("130013153082460022"));
// barPay(null, new PayParamsDto()
// .setMerchantId("1738216504")
// .setOrderNo("sa101293120sss1")
// .setTitle("1213")
// .setBody("1213")
// .setAmount(1L)
// .setAppId("wxd88fffa983758a30")
// .setClientIp("127.0.0.1")
// .setBarCode("130013153082460022"));
Map<String, Object> sss1 = queryOrder(null, "sa101293120sss1", "1738216504");
System.out.println(sss1);
}
}

View File

@@ -71,7 +71,7 @@ public class WechatReqUtils {
log.info("微信支付请求url = {} \nauthorization: {}", request.getUrl(), authorization);
HttpResponse response = request.execute();
String s = response.body();
log.info("微信支付请求url = {}\n\tmethod: {}\n\tbody: {}\n\tresp: {}", url, method, body, s);
log.info("微信支付请求:\n\turl = {}\n\tmethod: {}\n\tbody: {}\n\tresp: {}", url, method, body, s);
return s;
}