Browse Source

修复下单端系统派单

master
前端-胡立永 1 month ago
parent
commit
544f634a87
11 changed files with 390 additions and 8 deletions
  1. +3
    -5
      CatmDogd-Mall-Front-test/src/views/model/AppletAmountLog/audit.vue
  2. +2
    -2
      ruoyi-admin/src/main/resources/application-druid-root.yml
  3. +8
    -0
      ruoyi-admin/src/main/resources/pay_weixin.properties
  4. +1
    -1
      ruoyi-catdog/src/main/java/com/ruoyi/applet/service/impl/AppletAmountService.java
  5. +4
    -0
      ruoyi-catdog/src/main/java/com/ruoyi/model/domain/AppletAmountLog.java
  6. +2
    -0
      ruoyi-catdog/src/main/java/com/ruoyi/model/service/impl/AppletAmountLogServiceImpl.java
  7. +21
    -0
      ruoyi-mall/pom.xml
  8. +26
    -0
      ruoyi-mall/src/main/java/com/cyl/h5/controller/PayNotifyController.java
  9. +200
    -0
      ruoyi-mall/src/main/java/com/cyl/wechat/pay/MpWxPayService.java
  10. +70
    -0
      ruoyi-mall/src/main/java/com/cyl/wechat/pay/config/WxPay.java
  11. +53
    -0
      ruoyi-mall/src/main/java/com/cyl/wechat/pay/config/WxPayConfiguration.java

+ 3
- 5
CatmDogd-Mall-Front-test/src/views/model/AppletAmountLog/audit.vue View File

@ -315,13 +315,11 @@ export default {
getList() {
this.loading = true;
// (type=1)
const params = { ...this.queryParams, type: 1 };
const params = { ...this.queryParams, type: 1, audit: true}
listAppletAmountLog(params).then(response => {
// auditStatusnameValue
this.AppletAmountLogList = response.rows.filter(item =>
item.auditStatus !== undefined && item.nameValue
);
this.total = this.AppletAmountLogList.length;
this.AppletAmountLogList = response.rows
this.total = response.length;
this.loading = false;
});
},


+ 2
- 2
ruoyi-admin/src/main/resources/application-druid-root.yml View File

@ -6,8 +6,8 @@ spring:
druid:
# 主库数据源 jdbc:mysql://localhost:3306/catmdogf?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&allowMultiQueries=true
master:
# url: jdbc:mysql://47.97.158.59:3306/catmdogf_test20250624?useUnicode=true&useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true
url: jdbc:mysql://47.97.158.59:3306/catmdogf_prod20250624?useUnicode=true&useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true
url: jdbc:mysql://47.97.158.59:3306/catmdogf_test20250624?useUnicode=true&useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true
# url: jdbc:mysql://47.97.158.59:3306/catmdogf_prod20250624?useUnicode=true&useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true
username: root
password: Qweruiop@123
# 从库数据源


+ 8
- 0
ruoyi-admin/src/main/resources/pay_weixin.properties View File

@ -0,0 +1,8 @@
pay.mchId=1665639691
pay.appId=wxd1a6ba7b5e17a5b6
pay.mchKey=19961022196901121965060120230731
pay.keyPath=classpath:apiclient_cert.pem
pay.notifyUrl=
pay.notifyUrlDev=
pay.notifyOneUrl=
pay.notifyUrlOneDev=

+ 1
- 1
ruoyi-catdog/src/main/java/com/ruoyi/applet/service/impl/AppletAmountService.java View File

@ -108,7 +108,7 @@ public class AppletAmountService {
request.transferSceneId = map.get("transferSceneId").toString();
request.openid = map.get("openid").toString();
request.userName = client.encrypt(map.get("userName").toString());
request.transferAmount = appletAmountLog.getAmount().longValue()*100;//单位为分
request.transferAmount = appletAmountLog.getAmount().multiply(new BigDecimal(100)).longValue();//单位为分
request.transferRemark = map.get("transferRemark").toString();
request.notifyUrl = map.get("notifyUrl").toString();
request.userRecvPerception = map.get("userRecvPerception").toString();


+ 4
- 0
ruoyi-catdog/src/main/java/com/ruoyi/model/domain/AppletAmountLog.java View File

@ -2,6 +2,7 @@ package com.ruoyi.model.domain;
import java.math.BigDecimal;
import com.baomidou.mybatisplus.annotation.TableField;
import com.cyl.manager.oms.domain.Order;
import com.cyl.manager.ums.domain.Member;
import lombok.Data;
@ -69,4 +70,7 @@ public class AppletAmountLog extends BaseEntity
@Excel(name = "金额关联订单")
private Long orderId;
@TableField(exist = false)
private Boolean audit;
}

+ 2
- 0
ruoyi-catdog/src/main/java/com/ruoyi/model/service/impl/AppletAmountLogServiceImpl.java View File

@ -67,6 +67,8 @@ public class AppletAmountLogServiceImpl extends ServiceImpl<AppletAmountLogMappe
.eq(appletAmountLog.getUserId() != null, AppletAmountLog::getUserId, appletAmountLog.getUserId())
.eq(appletAmountLog.getMoneyType() != null, AppletAmountLog::getMoneyType, appletAmountLog.getMoneyType())
.eq(appletAmountLog.getNameValue() != null, AppletAmountLog::getNameValue, appletAmountLog.getNameValue())
.orderByDesc(AppletAmountLog::getCreateTime)
.isNotNull(appletAmountLog.getAudit() != null, AppletAmountLog::getNameValue)
.list();
// return appletAmountLogMapper.selectAppletAmountLogList(appletAmountLog);


+ 21
- 0
ruoyi-mall/pom.xml View File

@ -11,6 +11,7 @@
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<weixin.version>3.5.0</weixin.version>
</properties>
<dependencies>
<dependency>
@ -28,11 +29,31 @@
<artifactId>ruoyi-system</artifactId>
<version>${ruoyi.version}</version>
</dependency>
<!-- 微信支付 -->
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-pay</artifactId>
<version>${weixin.version}</version>
</dependency>
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-miniapp</artifactId>
<version>${weixin.version}</version>
</dependency>
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-mp</artifactId>
<version>${weixin.version}</version>
</dependency>
<dependency>
<groupId>com.github.wechatpay-apiv3</groupId>
<artifactId>wechatpay-java</artifactId>
<version>0.2.9</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>


+ 26
- 0
ruoyi-mall/src/main/java/com/cyl/h5/controller/PayNotifyController.java View File

@ -5,6 +5,8 @@ import com.alibaba.fastjson.JSONObject;
import com.cyl.h5.pojo.dto.PayNotifyMessageDTO;
import com.cyl.h5.service.H5OrderService;
import com.cyl.wechat.WechatPayConfig;
import com.cyl.wechat.pay.MpWxPayService;
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.notification.NotificationConfig;
import com.wechat.pay.java.core.notification.NotificationParser;
@ -15,6 +17,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@ -22,6 +25,7 @@ import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* 订单表Controller
@ -37,6 +41,8 @@ public class PayNotifyController {
@Autowired
private H5OrderService h5OrderService;
@Autowired
private MpWxPayService mpWxPayService;
private final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
@ -70,6 +76,26 @@ public class PayNotifyController {
.timestamp(timestamp)
.body(requestBody.toString())
.build();
//新版本微信公钥的支付回调
try {
WxPayOrderNotifyResult notify = mpWxPayService.notify(requestBody.toString());
PayNotifyMessageDTO message = new PayNotifyMessageDTO();
message.setOutTradeNo(Long.valueOf(notify.getOutTradeNo()));
message.setMemberId(Long.valueOf(notify.getAttach()));
message.setTradeStatus(Transaction.TradeStateEnum.SUCCESS);
message.setPayTime(new Date());
message.setTradeNo(notify.getTransactionId());
h5OrderService.payCallBack(message);
return;
}catch (Exception e){
log.error("新版本微信公钥的支付回调异常:{}", e.getMessage());
}
log.info("【requestParam】" + JSONObject.toJSON(requestParam));
//初始化了 RSAAutoCertificateConfig
Config config = WechatPayConfig.getInstance();


+ 200
- 0
ruoyi-mall/src/main/java/com/cyl/wechat/pay/MpWxPayService.java View File

@ -0,0 +1,200 @@
package com.cyl.wechat.pay;
import com.cyl.wechat.pay.config.WxPay;
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
import com.github.binarywang.wxpay.constant.WxPayConstants;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.github.binarywang.wxpay.service.WxPayService;
import org.springframework.stereotype.Component;
import java.io.File;
@Component
public class MpWxPayService {
public boolean dev = true;
public WxPay wxPay;
public WxPayService wxPayService;
/**
* 生成二维码
* @param codeUrl
* @param logoFile
* @param sideLength
* @return
*/
public Object createScanPayQrcodeMode2(String codeUrl, File logoFile, Integer sideLength){
try {
byte[] scanPayQrcodeMode2 = wxPayService.createScanPayQrcodeMode2(codeUrl, null, null);
return scanPayQrcodeMode2;
} catch (Exception e) {
e.printStackTrace();
return e.getLocalizedMessage();
}
}
/**
* 扫码支付
* @param productName
* @param clientIp
* @param productId
* @param price
* @param orderNo
* @param openId
* @param body
* @return
*/
public Object createQrOrder(String productName, String clientIp,
String productId, Integer price, String orderNo, String body) {
WxPayUnifiedOrderRequest request = new WxPayUnifiedOrderRequest();
request.setDeviceInfo("WEB"); //设备号
request.setTradeType("NATIVE"); //交易类型
request.setBody(productName); //商品描述
request.setOutTradeNo(orderNo); //商户订单号
request.setDetail(productName); //商品详情
request.setTotalFee(price); //总金额|分计
request.setSpbillCreateIp(clientIp); //终端IP
request.setNotifyUrl(wxPay.notifyUrl);//设置回调路径
request.setProductId(productId); //商品id
if (dev) {
request.setTotalFee(price);
request.setNotifyUrl(wxPay.notifyUrlDev);
}
try {
Object order = wxPayService.unifiedOrder(request);
return order;
} catch (WxPayException e) {
e.printStackTrace();
return e.getLocalizedMessage();
}
}
/**
* 微信吊起支付
* @param productName
* @param clientIp
* @param productId
* @param price
* @param orderNo
* @param openId
* @param body
* @return
*/
public Object createOrder(String productName, String clientIp,
String productId, Integer price, String orderNo,
String openId, String body){
WxPayUnifiedOrderRequest request = new WxPayUnifiedOrderRequest();
request.setDeviceInfo("WEB"); //设备号
request.setTradeType("JSAPI"); //交易类型
request.setBody(productName); //商品描述
request.setOutTradeNo(orderNo); //商户订单号
request.setDetail(productName); //商品详情
request.setTotalFee(price); //总金额|分计
request.setSpbillCreateIp(clientIp); //终端IP
request.setNotifyUrl(wxPay.notifyOneUrl);//设置回调路径
request.setProductId(productId); //商品id
request.setOpenid(openId); //JSAPI OPENID
if (dev){
request.setTotalFee(price);
request.setNotifyUrl(wxPay.notifyUrlOneDev);
}
try {
Object order = wxPayService.createOrder(request);
return order;
} catch (WxPayException e) {
e.printStackTrace();
return e.getLocalizedMessage();
}
}
public WxPayOrderNotifyResult notify(String requestBody){
WxPayOrderNotifyResult notify = null;
try {
notify = wxPayService.parseOrderNotifyResult(requestBody);
} catch (WxPayException e) {
e.printStackTrace();
}
return notify;
}
public Object createAppOrder(String productName, String clientIp,
String productId, Integer price,
String orderNo, String body,
String openid){
WxPayUnifiedOrderRequest request = new WxPayUnifiedOrderRequest();
request.setDeviceInfo("WEB");
request.setBody(productName);
request.setOutTradeNo(orderNo);
request.setDetail(productName);
request.setTotalFee(price);
request.setSpbillCreateIp(clientIp);
request.setNotifyUrl(wxPay.notifyUrl);
request.setTradeType(WxPayConstants.TradeType.JSAPI);
request.setProductId(productId);
request.setAppid(wxPay.appId);
request.setOpenid(openid);
if (dev){
request.setTotalFee(price);
request.setNotifyUrl(wxPay.notifyUrlDev);
request.setAppid(wxPay.appId);
request.setOpenid(openid);
}
try {
Object order = wxPayService.createOrder(request);
return order;
} catch (WxPayException e) {
e.printStackTrace();
return e.getLocalizedMessage();
}
}
public Object createWebOrder(String productName, String clientIp,
String productId, Integer price,
String orderNo, String body,
String openid){
WxPayUnifiedOrderRequest request = new WxPayUnifiedOrderRequest();
request.setDeviceInfo("WEB");
request.setBody(productName);
request.setOutTradeNo(orderNo);
request.setDetail(productName);
request.setTotalFee(price);
request.setSpbillCreateIp(clientIp);
request.setNotifyUrl(wxPay.notifyUrl);
request.setTradeType(WxPayConstants.TradeType.MWEB);
request.setProductId(productId);
request.setAppid(wxPay.appId);
request.setOpenid(openid);
if (dev){
request.setTotalFee(price);
request.setNotifyUrl(wxPay.notifyUrlDev);
request.setAppid(wxPay.appId);
request.setOpenid(openid);
}
try {
Object order = wxPayService.createOrder(request);
return order;
} catch (WxPayException e) {
e.printStackTrace();
return e.getLocalizedMessage();
}
}
public WxPayOrderNotifyResult appNotify(String requestBody){
WxPayOrderNotifyResult notify = null;
try {
notify = wxPayService.parseOrderNotifyResult(requestBody);
} catch (WxPayException e) {
e.printStackTrace();
}
return notify;
}
}

+ 70
- 0
ruoyi-mall/src/main/java/com/cyl/wechat/pay/config/WxPay.java View File

@ -0,0 +1,70 @@
package com.cyl.wechat.pay.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
@Data
@Component
@PropertySource("classpath:pay_weixin.properties")
@ConfigurationProperties(prefix = "pay")
public class WxPay {
/**
* 微信支付mchId
*/
public String mchId;
/**
* app支付appId JS支付openId
*/
public String appId;
/**
* 微信支付mchKey
*/
public String mchKey;
/**
* 回调地址
*/
public String notifyUrl;
/**
* 回调地址dev
*/
public String notifyUrlDev;
/**
* 回调地址
*/
public String notifyOneUrl;
/**
* 回调地址dev
*/
public String notifyUrlOneDev;
/**
* 签名类型
*/
public String signType;
/**
* 支付证书路径
*/
public String keyPath;
/**
* 回调地址
*/
public String notifyOrderUrl;
/**
* 回调地址dev
*/
public String notifyOrderUrlDev;
}

+ 53
- 0
ruoyi-mall/src/main/java/com/cyl/wechat/pay/config/WxPayConfiguration.java View File

@ -0,0 +1,53 @@
package com.cyl.wechat.pay.config;
import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.constant.WxPayConstants;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.annotation.Resource;
@Configuration
@RequiredArgsConstructor
@ConditionalOnClass(WxPayService.class)
public class WxPayConfiguration {
@Resource
private WxPay wxPay;
@Bean
public WxPayService wxMpPayService() {
WxPayConfig payConfig = new WxPayConfig();
payConfig.setAppId(wxPay.appId);
payConfig.setMchId(wxPay.mchId);
payConfig.setMchKey(wxPay.mchKey);
payConfig.setKeyPath(wxPay.keyPath);
payConfig.setSignType(WxPayConstants.SignType.MD5);
WxPayService wxPayService = new WxPayServiceImpl();
wxPayService.setConfig(payConfig);
return wxPayService;
}
// @Bean("saboxWxPayService")
// public WxPayService saboxWxPayService(){
// WxPayConfig payConfig = new WxPayConfig();
// WxPayService wxPayService = new WxPayServiceImpl();
// String sandboxSignKey = null;
// try {
// wxPayService.setConfig(payConfig);
// sandboxSignKey = wxPayService.getSandboxSignKey();
// } catch (WxPayException e) {
// e.printStackTrace();
// }
// payConfig.setUseSandboxEnv(true);
// payConfig.setMchKey(sandboxSignKey);
// wxPayService.setConfig(payConfig);
// return wxPayService;
// }
}

Loading…
Cancel
Save