feat: wx pay update
This commit is contained in:
@@ -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<String, String> 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<String, String> 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);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user