问题
最近使用 微信V3 支付的JAVA 版本,调用 JSAPI 支付,报错:
httpResponseBody[{"code":"PARAM_ERROR","detail":{"location":null,"value":""},"message":"输入源“(null)”映射到值字段“子商户号/二级商户号”字符串规则校验失败,字符串必须匹配正则表达式“^[1-9]\\d*$”"}]
看了报错提示,修改了代码,传递了“子商户号/二级商户号”
request.setAppid(APP_ID);
request.setMchid(MERCHANT_ID);
request.setSubMchid("");
request.setSubAppid(APP_ID);
但是还是报错。
解决方法
相信很多人都是参考了 https://github.com/wechatpay-apiv3/wechatpay-java/blob/main/service/src/example/java/com/wechat/pay/java/service/payments/jsapi/JsapiServiceExtensionExample.java
的代码来实现的, 但是注意检查一下 自己的代码,是不是使用了 partnerpayments 包
import com.wechat.pay.java.service.partnerpayments.jsapi.JsapiServiceExtension;
import com.wechat.pay.java.service.partnerpayments.jsapi.model.Payer;
import com.wechat.pay.java.service.partnerpayments.jsapi.model.PrepayWithRequestPaymentResponse;
如果是的话,请改成 payments 包
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension; import com.wechat.pay.java.service.payments.jsapi.model.Payer; import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse;
修改过后问题解决。
一些代码截图