Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

调用微信支付createOrderV3接口,出现:数据查询结果为空 报错 #3408

Open
limingAlex1314 opened this issue Nov 4, 2024 · 3 comments

Comments

@limingAlex1314
Copy link

调用微信支付v3下单接口,支付单生成了,但是出现调用https://api.mch.weixin.qq.com/v3/merchant-service/complaint-notifications接口记录,并提示:数据查询结果为空

WxJava 模块名: weixin-java-pay
WxJava 版本号:4.5.3.B
代码:
private R createWxOrder(UnionBaseRequest request, PayConfig payConfig) throws WxPayException {
WxPayService wxPayService = new WxPayServiceImpl();
WxPayConfig wxPayConfig = new WxPayConfig();
wxPayConfig.setAppId(request.getSubAppId());
wxPayConfig.setMchId(payConfig.getMchId());
wxPayConfig.setApiV3Key(payConfig.getApiV3Key());
if (StringUtils.isNotBlank(payConfig.getPrivateCertContent())) {
wxPayConfig.setPrivateCertContent(payConfig.getPrivateCertContent().getBytes());
}
if (StringUtils.isNotBlank(payConfig.getPrivateKeyContent())) {
wxPayConfig.setPrivateKeyContent(payConfig.getPrivateKeyContent().getBytes());
}
wxPayConfig.setPrivateKeyPath(payConfig.getPrivateKeyPath());
wxPayConfig.setPrivateCertPath(payConfig.getPrivateCertPath());
wxPayService.setConfig(wxPayConfig);

	WxPayUnifiedOrderV3Request v3Request = new WxPayUnifiedOrderV3Request();

	String orderDesc = request.getOrderDesc();

	v3Request.setDescription(orderDesc);
	String merOrderId = request.getMerOrderId();
	if (StringUtils.isNotEmpty(merOrderId) && merOrderId.startsWith(UnionPayConstants.ORDER_ID_PREFIX)) {
		merOrderId = merOrderId.replace(UnionPayConstants.ORDER_ID_PREFIX, "");
	}
	v3Request.setOutTradeNo(merOrderId);
	v3Request.setNotifyUrl(wxPayConfigProperties.getNotifyUrl() + "/" + payConfig.getTenantId());

	WxPayUnifiedOrderV3Request.Amount amount = new WxPayUnifiedOrderV3Request.Amount();
	amount.setTotal(request.getTotalAmount().intValue());
	amount.setCurrency("CNY");
	v3Request.setAmount(amount);

	WxPayUnifiedOrderV3Request.Payer payer = new WxPayUnifiedOrderV3Request.Payer();
	payer.setOpenid(request.getOpenId());
	v3Request.setPayer(payer);

	v3Request.setAttach(request.getSubAppId());
	v3Request.setTimeExpire(DateUtil.format(DateUtil.parse(request.getExpireTime(), "yyyy-MM-dd HH:mm:ss"), "yyyy-MM-dd'T'HH:mm:ssXXX"));

	WxPayUnifiedOrderV3Result.JsapiResult jsapiResult = ((UnionPayController) AopContext.currentProxy()).createOrderV3(v3Request, wxPayService);
	log.info("微信支付jsapiResult:{}", JSON.toJSONString(jsapiResult));
	JSONObject miniPayRequest = new JSONObject();
	JSONObject payParam = new JSONObject();
	payParam.put("appId", jsapiResult.getAppId());
	payParam.put("timeStamp", jsapiResult.getTimeStamp());
	payParam.put("package", jsapiResult.getPackageValue());
	payParam.put("paySign", jsapiResult.getPaySign());
	payParam.put("signType", jsapiResult.getSignType());
	payParam.put("nonceStr", jsapiResult.getNonceStr());
	miniPayRequest.put("miniPayRequest", payParam);

	String miniPayUrl = payConfig.getMiniPayUrl();
	if (StringUtils.isNotEmpty(miniPayUrl)) {
		try {
			miniPayUrl = miniPayUrl + "?payDataStr=" + URLEncoder.encode(payParam.toJSONString(), StandardCharsets.UTF_8.toString());
		} catch (UnsupportedEncodingException e) {
			log.error("", e);
		}
		miniPayRequest.put("miniPayUrl", miniPayUrl);
	}

	return R.ok(miniPayRequest);
}

@auditlog(obsType = "现金(微信)", stage = "付款(拉起)")
public WxPayUnifiedOrderV3Result.JsapiResult createOrderV3(WxPayUnifiedOrderV3Request v3Request, WxPayService wxPayService) throws WxPayException {
return wxPayService.createOrderV3(TradeTypeEnum.JSAPI, v3Request);
}

日志:
日志

@limingAlex1314
Copy link
Author

发现了问题,只要序列化wxPayService,就会发生这个问题:
JSON.toJSONString(wxPayService)
具体原因还没查到

@binarywang
Copy link
Owner

为什么要序列化service对象?

@limingAlex1314
Copy link
Author

limingAlex1314 commented Nov 6, 2024

@around(value = "@annotation(auditLog)")
@SneakyThrows
public Object around(ProceedingJoinPoint joinPoint, AuditLog auditLog) {
Object object = joinPoint.proceed();
Object[] args = joinPoint.getArgs();
AuditLogFlagEnum flag = auditLog.flag();
AuditLogVo auditLogVo = new AuditLogVo();
auditLogVo.setFlagId(flag.getFlagId());
auditLogVo.setTime(LocalDateTime.now());
auditLogVo.setMallId(TenantContextHolder.getMallId());
auditLogVo.setUserId(TenantContextHolder.getUserId());
auditLogVo.setTraceId(TenantContextHolder.getRequestId());
auditLogVo.setObsType(auditLog.obsType());
auditLogVo.setObsId(TenantContextHolder.getObsId());
auditLogVo.setStage(auditLog.stage());
if (ArrayUtil.isNotEmpty(args)) {
auditLogVo.setReq(JSON.toJSONString(args));
}
auditLogVo.setResp(JSON.toJSONString(object));
log.info("desc={}, data={}", flag.getName(), JSON.toJSONString(auditLogVo));
return object;
}
在审计日志切面中序列化了整个入参,本来只想打印WxPayUnifiedOrderV3Request的,没有指定打印的入参,导致把WxPayService 也序列化了,问题可以解决,只要不序列化WxPayService 就可以,但是想知道为啥序列化WxPayService 会出现上面的那个问题?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants