diff --git a/wfc-modules/wfc-payment/pom.xml b/wfc-modules/wfc-payment/pom.xml
index 5e819a5..abc8860 100644
--- a/wfc-modules/wfc-payment/pom.xml
+++ b/wfc-modules/wfc-payment/pom.xml
@@ -82,6 +82,13 @@
20.0.0
+
+
+ com.github.binarywang
+ weixin-java-pay
+ 4.6.0
+
+
diff --git a/wfc-modules/wfc-payment/src/main/java/org/wfc/payment/config/WWxPayConfig.java b/wfc-modules/wfc-payment/src/main/java/org/wfc/payment/config/WWxPayConfig.java
new file mode 100644
index 0000000..eb2ed0a
--- /dev/null
+++ b/wfc-modules/wfc-payment/src/main/java/org/wfc/payment/config/WWxPayConfig.java
@@ -0,0 +1,78 @@
+package org.wfc.payment.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Configuration;
+import com.github.binarywang.wxpay.service.WxPayService;
+import com.github.binarywang.wxpay.config.WxPayConfig;
+// import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
+import org.wfc.payment.service.impl.WxPayServiceImpl;
+import org.wfc.payment.service.IWxPayService;
+
+@Configuration
+public class WWxPayConfig extends WxPayConfig {
+ private boolean useSandboxEnv;
+ public void setUseSandboxEnv(boolean useSandboxEnv) {
+ this.useSandboxEnv = useSandboxEnv;
+ }
+
+ public boolean isUseSandboxEnv() {
+ return useSandboxEnv;
+ }
+
+ @Value("${wx.pay.appId}")
+ private String appId;
+ @Value("${wx.pay.mchId}")
+ private String mchId;
+ @Value("${wx.pay.mchKey}")
+ private String mchKey;
+ @Value("${wx.pay.keyPath}")
+ private String keyPath;
+
+ public void setAppId(String appId) {
+ this.appId = appId;
+ }
+
+ public void setMchId(String mchId) {
+ this.mchId = mchId;
+ }
+
+ public void setMchKey(String mchKey) {
+ this.mchKey = mchKey;
+ }
+
+ public void setKeyPath(String keyPath) {
+ this.keyPath = keyPath;
+ }
+
+ // private String getSandboxSignKey() {
+ // try {
+ // WXPayConfigImpl config = new WXPayConfigImpl();
+ // Map params = new HashMap<>();
+ // params.put("mch_id", config.getMchID());
+ // params.put("nonce_str", WXPayUtil.generateNonceStr());
+ // params.put("sign", WXPayUtil.generateSignature(params, config.getKey()));
+ // String strXML = wxPay.requestWithoutCert("/sandboxnew/pay/getsignkey", params, this.getHttpConnectTimeoutMs(), this.getHttpReadTimeoutMs());
+ // Map result = WXPayUtil.xmlToMap(strXML);
+ // if ("SUCCESS".equals(result.get("return_code"))) {
+ // return result.get("sandbox_signkey");
+ // } else {
+ // // 处理错误情况
+ // }
+ // } catch (Exception e) {
+ // // 处理异常
+ // }
+ // return null;
+ // }
+
+ @Bean
+ public IWxPayService wxPayService() throws Exception {
+ WWxPayConfig config = new WWxPayConfig();
+ config.setAppId(appId);
+ config.setMchId(mchId);
+ config.setMchKey(mchKey);
+ config.setKeyPath(keyPath);
+ config.setUseSandboxEnv(true); // 启用沙箱环境
+ return new WxPayServiceImpl(config);
+ }
+}
\ No newline at end of file
diff --git a/wfc-modules/wfc-payment/src/main/java/org/wfc/payment/controller/WechatPayController.java b/wfc-modules/wfc-payment/src/main/java/org/wfc/payment/controller/WechatPayController.java
deleted file mode 100644
index 2671919..0000000
--- a/wfc-modules/wfc-payment/src/main/java/org/wfc/payment/controller/WechatPayController.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package org.wfc.payment.controller;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-import org.wfc.common.core.web.controller.BaseController;
-import org.wfc.common.core.web.domain.AjaxResult;
-import org.wfc.common.log.annotation.Log;
-import org.wfc.common.log.enums.BusinessType;
-import org.wfc.common.security.annotation.RequiresPermissions;
-import org.wfc.payment.domain.WechatPay;
-import org.wfc.payment.service.IWechatPayService;
-
-
-/**
- * Paypal controller
- *
- * @author wfc
- */
-@RestController
-@RequestMapping("/wechatpay")
-public class WechatPayController extends BaseController
-{
- @Autowired
- private IWechatPayService wechatpayService;
-
- /**
- * WechatPay
- */
- @RequiresPermissions("payment:wechatpayInfo:query")
- @Log(title = "wechatpay info management", businessType = BusinessType.OTHER)
- @GetMapping("/{userId}")
- public AjaxResult query(@PathVariable Long userId) {
- return success(wechatpayService.selectWechatPayInfoByUserId(userId));
- }
-
- /**
- * WechatPay
- */
- @RequiresPermissions("payment:wechatpayInfo:add")
- @Log(title = "wechatpay info management", businessType = BusinessType.INSERT)
- @PostMapping("/{wechatpay}")
- public AjaxResult add(@PathVariable WechatPay wechatpay)
- {
- return toAjax(wechatpayService.insertWechatPayInfo(wechatpay));
- }
-
- /**
- * WechatPay
- */
- @RequiresPermissions("payment:wechatpayInfo:edit")
- @Log(title = "wechatpay info management", businessType = BusinessType.UPDATE)
- @PutMapping("/{id}")
- public AjaxResult edit(@PathVariable Long id) {
- return toAjax(wechatpayService.updateWechatPayInfoById(id));
- }
-
- /**
- * WechatPay
- */
- @RequiresPermissions("payment:wechatpayInfo:remove")
- @Log(title = "wechatpay info management", businessType = BusinessType.DELETE)
- @DeleteMapping("/{id}")
- public AjaxResult remove(@PathVariable Long id) {
- wechatpayService.deleteWechatPayInfoById(id);
- return success();
- }
-}
diff --git a/wfc-modules/wfc-payment/src/main/java/org/wfc/payment/controller/WxPayController.java b/wfc-modules/wfc-payment/src/main/java/org/wfc/payment/controller/WxPayController.java
new file mode 100644
index 0000000..6fc7dce
--- /dev/null
+++ b/wfc-modules/wfc-payment/src/main/java/org/wfc/payment/controller/WxPayController.java
@@ -0,0 +1,36 @@
+package org.wfc.payment.controller;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import org.wfc.common.core.web.controller.BaseController;
+import org.wfc.common.core.web.domain.AjaxResult;
+import org.wfc.common.log.annotation.Log;
+import org.wfc.common.log.enums.BusinessType;
+import org.wfc.common.security.annotation.RequiresPermissions;
+import org.wfc.payment.domain.WxPay;
+import org.wfc.payment.service.IWxPayService;
+import org.springframework.web.bind.annotation.RequestBody;
+import com.github.binarywang.wxpay.exception.WxPayException;
+import com.github.binarywang.wxpay.service.WxPayService;
+import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
+import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse;
+
+@RestController
+@RequestMapping("/wxpay")
+public class WxPayController extends BaseController {
+ @Autowired
+ private WxPayService wxPayService;
+
+ @PostMapping("/notify")
+ public String payNotify(@RequestBody String xmlData) throws WxPayException {
+ WxPayOrderNotifyResult result = wxPayService.parseOrderNotifyResult(xmlData);
+ // 处理支付结果
+ return WxPayNotifyResponse.success("WeChat pay successfully");
+ }
+}
\ No newline at end of file
diff --git a/wfc-modules/wfc-payment/src/main/java/org/wfc/payment/domain/WechatPay.java b/wfc-modules/wfc-payment/src/main/java/org/wfc/payment/domain/WxPay.java
similarity index 99%
rename from wfc-modules/wfc-payment/src/main/java/org/wfc/payment/domain/WechatPay.java
rename to wfc-modules/wfc-payment/src/main/java/org/wfc/payment/domain/WxPay.java
index e0ab4d5..4905212 100644
--- a/wfc-modules/wfc-payment/src/main/java/org/wfc/payment/domain/WechatPay.java
+++ b/wfc-modules/wfc-payment/src/main/java/org/wfc/payment/domain/WxPay.java
@@ -12,7 +12,7 @@ import javax.validation.constraints.Size;
*
* @author wfc
*/
-public class WechatPay extends BaseEntity
+public class WxPay extends BaseEntity
{
private static final long serialVersionUID = 1L;
diff --git a/wfc-modules/wfc-payment/src/main/java/org/wfc/payment/mapper/WechatPayMapper.java b/wfc-modules/wfc-payment/src/main/java/org/wfc/payment/mapper/WechatPayMapper.java
deleted file mode 100644
index 435f706..0000000
--- a/wfc-modules/wfc-payment/src/main/java/org/wfc/payment/mapper/WechatPayMapper.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package org.wfc.payment.mapper;
-
-import org.wfc.payment.domain.WechatPay;
-
-/**
- * Paypal mapper
- *
- * @author wfc
- */
-public interface WechatPayMapper
-{
- /**
- * select wechatpay info by user id
- *
- * @param userId user id
- * @return wechatpay information
- */
- public WechatPay selectWechatPayInfoByUserId(Long userId);
-
- /**
- * select WechatPay pay information by user ID
- *
- * @param userId user ID
- * @return WechatPay pay information
- */
- public int insertWechatPayInfo(WechatPay wechatpay);
-
- /**
- * select WechatPay pay information by user ID
- *
- * @param userId user ID
- * @return WechatPay pay information
- */
- public int updateWechatPayInfoById(Long id);
-
- /**
- * select WechatPay pay information by user ID
- *
- * @param userId user ID
- * @return WechatPay pay information
- */
- public void deleteWechatPayInfoById(Long id);
-}
diff --git a/wfc-modules/wfc-payment/src/main/java/org/wfc/payment/mapper/WxPayMapper.java b/wfc-modules/wfc-payment/src/main/java/org/wfc/payment/mapper/WxPayMapper.java
new file mode 100644
index 0000000..dba8bb7
--- /dev/null
+++ b/wfc-modules/wfc-payment/src/main/java/org/wfc/payment/mapper/WxPayMapper.java
@@ -0,0 +1,43 @@
+package org.wfc.payment.mapper;
+
+import org.wfc.payment.domain.WxPay;
+
+/**
+ * Paypal mapper
+ *
+ * @author wfc
+ */
+public interface WxPayMapper
+{
+ /**
+ * select wxpay info by user id
+ *
+ * @param userId user id
+ * @return wxpay information
+ */
+ public WxPay selectWxPayInfoByUserId(Long userId);
+
+ /**
+ * select WxPay pay information by user ID
+ *
+ * @param userId user ID
+ * @return WxPay pay information
+ */
+ public int insertWxPayInfo(WxPay wxpay);
+
+ /**
+ * select WxPay pay information by user ID
+ *
+ * @param userId user ID
+ * @return WxPay pay information
+ */
+ public int updateWxPayInfoById(Long id);
+
+ /**
+ * select WxPay pay information by user ID
+ *
+ * @param userId user ID
+ * @return WxPay pay information
+ */
+ public void deleteWxPayInfoById(Long id);
+}
diff --git a/wfc-modules/wfc-payment/src/main/java/org/wfc/payment/service/IWechatPayService.java b/wfc-modules/wfc-payment/src/main/java/org/wfc/payment/service/IWechatPayService.java
deleted file mode 100644
index 1e560d9..0000000
--- a/wfc-modules/wfc-payment/src/main/java/org/wfc/payment/service/IWechatPayService.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package org.wfc.payment.service;
-
-import org.wfc.payment.domain.WechatPay;
-
-/**
- * Paypal pay service layer
- *
- * @author wfc
- */
-public interface IWechatPayService
-{
- /**
- * select WechatPay pay information by user ID
- *
- * @param userId user ID
- * @return WechatPay pay information
- */
- public WechatPay selectWechatPayInfoByUserId(Long userId);
-
- /**
- * select WechatPay pay information by user ID
- *
- * @param userId user ID
- * @return WechatPay pay information
- */
- public int insertWechatPayInfo(WechatPay wechatpay);
-
- /**
- * select WechatPay pay information by user ID
- *
- * @param userId user ID
- * @return WechatPay pay information
- */
- public int updateWechatPayInfoById(Long id);
-
- /**
- * select WechatPay pay information by user ID
- *
- * @param userId user ID
- * @return WechatPay pay information
- */
- public void deleteWechatPayInfoById(Long id);
-}
diff --git a/wfc-modules/wfc-payment/src/main/java/org/wfc/payment/service/IWxPayService.java b/wfc-modules/wfc-payment/src/main/java/org/wfc/payment/service/IWxPayService.java
new file mode 100644
index 0000000..317714c
--- /dev/null
+++ b/wfc-modules/wfc-payment/src/main/java/org/wfc/payment/service/IWxPayService.java
@@ -0,0 +1,10 @@
+package org.wfc.payment.service;
+
+import java.math.BigDecimal;
+import org.wfc.payment.domain.WxPay;
+import com.github.binarywang.wxpay.exception.WxPayException;
+import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderResult;
+
+public interface IWxPayService {
+ public WxPayUnifiedOrderResult createOrder(String orderId, BigDecimal amount) throws WxPayException;
+}
\ No newline at end of file
diff --git a/wfc-modules/wfc-payment/src/main/java/org/wfc/payment/service/impl/WechatPayServiceImpl.java b/wfc-modules/wfc-payment/src/main/java/org/wfc/payment/service/impl/WechatPayServiceImpl.java
deleted file mode 100644
index 2edca8c..0000000
--- a/wfc-modules/wfc-payment/src/main/java/org/wfc/payment/service/impl/WechatPayServiceImpl.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package org.wfc.payment.service.impl;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import org.wfc.payment.mapper.WechatPayMapper;
-import org.wfc.payment.service.IWechatPayService;
-import org.wfc.payment.domain.WechatPay;
-
-/**
- * WechatPay service implementation
- *
- * @author wfc
- */
-@Service
-public class WechatPayServiceImpl implements IWechatPayService
-{
- @Autowired
- private WechatPayMapper wechatpayMapper;
-
- /**
- * Select Paypal information by user ID
- *
- * @param userId user ID
- * @return 结果
- */
- @Override
- public WechatPay selectWechatPayInfoByUserId(Long userId) {
- return wechatpayMapper.selectWechatPayInfoByUserId(userId);
- }
-
- /**
- * Select Paypal information by user ID
- *
- * @param userId user ID
- * @return 结果
- */
- @Override
- public int insertWechatPayInfo(WechatPay wechatpay) {
- return wechatpayMapper.insertWechatPayInfo(wechatpay);
- }
-
- /**
- * Select Paypal information by user ID
- *
- * @param userId user ID
- * @return 结果
- */
- @Override
- public int updateWechatPayInfoById(Long id) {
- return wechatpayMapper.updateWechatPayInfoById(id);
- }
-
- /**
- * update credit card
- *
- * @param creditCard User ID
- * @return void
- */
- @Override
- public void deleteWechatPayInfoById(Long id) {
- wechatpayMapper.deleteWechatPayInfoById(id);
- }
-}
diff --git a/wfc-modules/wfc-payment/src/main/java/org/wfc/payment/service/impl/WxPayServiceImpl.java b/wfc-modules/wfc-payment/src/main/java/org/wfc/payment/service/impl/WxPayServiceImpl.java
new file mode 100644
index 0000000..e6d8e0c
--- /dev/null
+++ b/wfc-modules/wfc-payment/src/main/java/org/wfc/payment/service/impl/WxPayServiceImpl.java
@@ -0,0 +1,43 @@
+package org.wfc.payment.service.impl;
+
+import java.math.BigDecimal;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.wfc.payment.mapper.WxPayMapper;
+import org.wfc.payment.service.IWxPayService;
+import org.wfc.payment.domain.WxPay;
+import org.wfc.payment.config.WWxPayConfig;
+import com.github.binarywang.wxpay.bean.request.BaseWxPayRequest;
+import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
+import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderResult;
+import com.github.binarywang.wxpay.exception.WxPayException;
+import com.github.binarywang.wxpay.service.WxPayService;
+
+/**
+ * WxPay service implementation
+ *
+ * @author wfc
+ */
+@Service
+public class WxPayServiceImpl implements IWxPayService
+{
+ @Autowired
+ private WxPayService wxPayService;
+
+ @Autowired
+ private WWxPayConfig config;
+
+ public WxPayServiceImpl(WWxPayConfig config) {
+ this.config = config;
+ }
+
+ public WxPayUnifiedOrderResult createOrder(String orderId, BigDecimal amount) throws WxPayException {
+ WxPayUnifiedOrderRequest request = new WxPayUnifiedOrderRequest();
+ request.setOutTradeNo(orderId);
+ request.setTotalFee(BaseWxPayRequest.yuanToFen(amount.toString()));
+ request.setBody("Order Payment");
+ request.setTradeType("JSAPI");
+ request.setNotifyUrl("https://wfc-modules-payment:/wxpay/notify");
+ return wxPayService.unifiedOrder(request);
+ }
+}
diff --git a/wfc-modules/wfc-payment/src/main/resources/application.yml b/wfc-modules/wfc-payment/src/main/resources/application.yml
index e802ea5..d7b8532 100644
--- a/wfc-modules/wfc-payment/src/main/resources/application.yml
+++ b/wfc-modules/wfc-payment/src/main/resources/application.yml
@@ -42,6 +42,13 @@ spring:
# url:
# driver-class-name:
+wx:
+ pay:
+ appId: app_id
+ mchId: merchant_id
+ mchKey: merchant_key
+ keyPath: /path/to/your/apiclient_key.pem
+
# mybatis-plus配置
mybatis-plus:
# 搜索指定包别名
diff --git a/wfc-modules/wfc-payment/src/main/resources/mapper/payment/WechatPayMapper.xml b/wfc-modules/wfc-payment/src/main/resources/mapper/payment/WxPayMapper.xml
similarity index 89%
rename from wfc-modules/wfc-payment/src/main/resources/mapper/payment/WechatPayMapper.xml
rename to wfc-modules/wfc-payment/src/main/resources/mapper/payment/WxPayMapper.xml
index e8cadcd..54181a7 100644
--- a/wfc-modules/wfc-payment/src/main/resources/mapper/payment/WechatPayMapper.xml
+++ b/wfc-modules/wfc-payment/src/main/resources/mapper/payment/WxPayMapper.xml
@@ -2,9 +2,9 @@
-
+
-
+
@@ -23,13 +23,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
-
+
select d.dept_id, d.parent_id, d.ancestors, d.remark, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time
from sys_dept d
-