From 84276dec05574d38d3e8423882b7c4466e520d8d Mon Sep 17 00:00:00 2001 From: zk Date: Mon, 18 May 2026 17:11:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BE=AE=E4=BF=A1=E5=B0=81?= =?UTF-8?q?=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/MemberProductService.java | 9 ------- .../src/main/resources/application-local.yml | 6 ++--- .../org/jiayunet/wxPay/WxJsPayAbility.java | 2 +- .../jiayunet/wxPay/WxNativePayAbility.java | 27 ++++++++++++++----- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/client-api/src/main/java/org/jiayunet/service/MemberProductService.java b/client-api/src/main/java/org/jiayunet/service/MemberProductService.java index dc408b7..fdb01f3 100644 --- a/client-api/src/main/java/org/jiayunet/service/MemberProductService.java +++ b/client-api/src/main/java/org/jiayunet/service/MemberProductService.java @@ -15,7 +15,6 @@ import org.jiayunet.tool.UserSecurityTool; import org.jiayunet.wxPay.WxNativePayAbility; import org.jiayunet.alipay.AlipayPagePayAbility; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.Assert; @@ -58,12 +57,6 @@ public class MemberProductService { @Autowired private PayAlipayFlowMapper payAlipayFlowMapper; - @Value("${wx_pay.merchant_id:}") - private String merchantId; - - @Value("${app.wx.app_id:}") - private String appId; - /** * 商品列表 *

查询上架商品,按sort_order排序

@@ -169,8 +162,6 @@ public class MemberProductService { payWechatFlowMapper.insert(flow); PrepayRequest request = new PrepayRequest(); - request.setAppid(appId); - request.setMchid(merchantId); request.setDescription(product.getProductName()); request.setOutTradeNo(orderNo); Amount amount = new Amount(); diff --git a/client-api/src/main/resources/application-local.yml b/client-api/src/main/resources/application-local.yml index b57ac72..0e92077 100644 --- a/client-api/src/main/resources/application-local.yml +++ b/client-api/src/main/resources/application-local.yml @@ -24,6 +24,7 @@ email: wx_pay: # status close:关闭 open:打开 status: close + app_id: your_app_id merchant_id: ${MERCHANT_ID:your_merchant_id} private_key: ${WX_PRIVATE_KEY:your_private_key} merchant_serial_number: ${MERCHANT_SERIAL_NUMBER:your_merchant_serial_number} @@ -74,10 +75,7 @@ app: interval_time: 20 limit_number: 20 - # 微信小程序 - wx: - app_id: wx7d75957cbd35e36b - app_secret: d70ef5baa4b9c046f396736d9a42cdc3 + #开放接口 ignore: diff --git a/common/src/main/java/org/jiayunet/wxPay/WxJsPayAbility.java b/common/src/main/java/org/jiayunet/wxPay/WxJsPayAbility.java index 675d1c2..1cb5806 100644 --- a/common/src/main/java/org/jiayunet/wxPay/WxJsPayAbility.java +++ b/common/src/main/java/org/jiayunet/wxPay/WxJsPayAbility.java @@ -55,7 +55,7 @@ public class WxJsPayAbility { /** * 小程序id */ - @Value("${app.wx.app_id}") + @Value("${wx_pay.app_id}") private String appId; diff --git a/common/src/main/java/org/jiayunet/wxPay/WxNativePayAbility.java b/common/src/main/java/org/jiayunet/wxPay/WxNativePayAbility.java index 110d79f..a92bcb6 100644 --- a/common/src/main/java/org/jiayunet/wxPay/WxNativePayAbility.java +++ b/common/src/main/java/org/jiayunet/wxPay/WxNativePayAbility.java @@ -26,18 +26,31 @@ public class WxNativePayAbility { */ @Value("${wx_pay.notify_domain}") private String notifyDomain; + /** + * 商户号 + */ + @Value("${wx_pay.merchant_id}") + private String merchantId; + /** + * 应用id(与商户号绑定的appId,用于微信支付) + */ + @Value("${wx_pay.app_id}") + private String appId; /** - * 预支付 - * @param request 请求头 - * @return + * 预支付(自动填充appId、merchantId、notifyUrl) + * + * @param paramRequest 请求参数(调用方只需设置业务字段:description、outTradeNo、amount等) + * @return codeUrl 二维码链接 */ - public String prepay(PrepayRequest request) { + public String prepay(PrepayRequest paramRequest) { try { - request.setNotifyUrl(notifyDomain+"/public/wxNotify/pay"); - log.info("以默认设置支付回调地址为:{}",request.getNotifyUrl()); - PrepayResponse prepay = nativePayService.prepay(request); + paramRequest.setNotifyUrl(notifyDomain + "/public/wxNotify/pay"); + log.info("以默认设置支付回调地址为:{}", paramRequest.getNotifyUrl()); + paramRequest.setAppid(appId); + paramRequest.setMchid(merchantId); + PrepayResponse prepay = nativePayService.prepay(paramRequest); return prepay.getCodeUrl(); } catch (Exception e) { log.error("nativePay支付下单出现异常,错误信息:{}", e.getMessage());