ruoyi-api/ruoyi-api-account/pom.xml
@@ -28,7 +28,10 @@ </exclusion> </exclusions> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-seata</artifactId> </dependency> </dependencies> </project> ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/factory/AppUserFallbackFactory.java
@@ -7,6 +7,8 @@ import com.ruoyi.account.api.model.TAppUserAddress; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.dto.PointChangeDto; import io.seata.core.exception.TransactionException; import io.seata.tm.api.GlobalTransactionContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cloud.openfeign.FallbackFactory; @@ -36,7 +38,13 @@ @Override public R<TAppUser> getUserById(Long id) { throw new RuntimeException("根据id查询用户失败:"+throwable.getMessage()); // 手动进行全局事务回滚 try { GlobalTransactionContext.getCurrent().rollback(); } catch (TransactionException e) { throw new RuntimeException(e); } return R.fail("根据id查询用户失败:"+throwable.getMessage()); } @Override ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/factory/AppUserVipDetailFallbackFactory.java
@@ -4,6 +4,8 @@ import com.ruoyi.account.api.model.TAppUserVipDetail; import com.ruoyi.account.api.vo.GetAppUserVipDetail; import com.ruoyi.common.core.domain.R; import io.seata.core.exception.TransactionException; import io.seata.tm.api.GlobalTransactionContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cloud.openfeign.FallbackFactory; @@ -26,12 +28,24 @@ @Override public R<TAppUserVipDetail> getAppUserVipDetail(GetAppUserVipDetail getAppUserVipDetail) { throw new RuntimeException("获取用户当前有效的VIP明细调用失败:" + throwable.getMessage()); // 手动进行全局事务回滚 try { GlobalTransactionContext.getCurrent().rollback(); } catch (TransactionException e) { throw new RuntimeException(e); } return R.fail("获取用户当前有效的VIP明细调用失败:" + throwable.getMessage()); } @Override public void updateAppUserVipDetail(TAppUserVipDetail appUserVipDetail) { throw new RuntimeException(throwable.getMessage()); // 手动进行全局事务回滚 try { GlobalTransactionContext.getCurrent().rollback(); } catch (TransactionException e) { throw new RuntimeException(e); } R.fail(throwable.getMessage()); } }; } ruoyi-api/ruoyi-api-chargingPile/pom.xml
@@ -28,7 +28,10 @@ </exclusion> </exclusions> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-seata</artifactId> </dependency> </dependencies> </project> ruoyi-api/ruoyi-api-chargingPile/src/main/java/com/ruoyi/chargingPile/api/factory/AccountingStrategyDetailFallbackFactory.java
@@ -4,6 +4,8 @@ import com.ruoyi.chargingPile.api.feignClient.AccountingStrategyDetailClient; import com.ruoyi.chargingPile.api.model.TAccountingStrategyDetail; import com.ruoyi.common.core.domain.R; import io.seata.core.exception.TransactionException; import io.seata.tm.api.GlobalTransactionContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cloud.openfeign.FallbackFactory; @@ -42,7 +44,13 @@ @Override public R<List<TAccountingStrategyDetail>> getListByAccountingStrategyId(Integer id) { throw new RuntimeException("根据计费策略主表id策略明细失败:" + throwable.getMessage()); // 手动进行全局事务回滚 try { GlobalTransactionContext.getCurrent().rollback(); } catch (TransactionException e) { throw new RuntimeException(e); } return R.fail("根据计费策略主表id策略明细失败:" + throwable.getMessage()); } @Override ruoyi-api/ruoyi-api-chargingPile/src/main/java/com/ruoyi/chargingPile/api/factory/AccountingStrategyFallbackFactory.java
@@ -3,6 +3,8 @@ import com.ruoyi.chargingPile.api.feignClient.AccountingStrategyClient; import com.ruoyi.chargingPile.api.model.TAccountingStrategy; import com.ruoyi.common.core.domain.R; import io.seata.core.exception.TransactionException; import io.seata.tm.api.GlobalTransactionContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cloud.openfeign.FallbackFactory; @@ -25,7 +27,13 @@ @Override public R<TAccountingStrategy> getAccountingStrategyById(Integer id) { throw new RuntimeException("根据id查询计费策略失败:" + throwable.getMessage()); // 手动进行全局事务回滚 try { GlobalTransactionContext.getCurrent().rollback(); } catch (TransactionException e) { throw new RuntimeException(e); } return R.fail("根据id查询计费策略失败:" + throwable.getMessage()); } }; } ruoyi-api/ruoyi-api-chargingPile/src/main/java/com/ruoyi/chargingPile/api/factory/ChargingGunFallbackFactory.java
@@ -7,6 +7,8 @@ import com.ruoyi.chargingPile.api.model.TFaultMessage; import com.ruoyi.chargingPile.api.vo.SiteNameVO; import com.ruoyi.common.core.domain.R; import io.seata.core.exception.TransactionException; import io.seata.tm.api.GlobalTransactionContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cloud.openfeign.FallbackFactory; @@ -36,7 +38,13 @@ @Override public R<TChargingGun> getChargingGunById(Integer id) { throw new RuntimeException("根据id获取充电枪失败:" + throwable.getMessage()); // 手动进行全局事务回滚 try { GlobalTransactionContext.getCurrent().rollback(); } catch (TransactionException e) { throw new RuntimeException(e); } return R.fail("根据id获取充电枪失败:" + throwable.getMessage()); } @Override ruoyi-api/ruoyi-api-integration/pom.xml
@@ -32,7 +32,10 @@ </exclusion> </exclusions> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-seata</artifactId> </dependency> </dependencies> </project> ruoyi-api/ruoyi-api-integration/src/main/java/com/ruoyi/integration/api/factory/SendMessageFallbackFactory.java
@@ -6,6 +6,8 @@ import com.ruoyi.integration.api.model.ChargingHandshake; import com.ruoyi.integration.api.model.PlatformStartCharging; import com.ruoyi.integration.api.model.PlatformStopCharging; import io.seata.core.exception.TransactionException; import io.seata.tm.api.GlobalTransactionContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cloud.openfeign.FallbackFactory; @@ -29,12 +31,24 @@ @Override public String platformStartCharging(PlatformStartCharging platformStartCharging) { throw new RuntimeException("远程启机失败" + throwable.getMessage()); // 手动进行全局事务回滚 try { GlobalTransactionContext.getCurrent().rollback(); } catch (TransactionException e) { throw new RuntimeException(e); } return "远程启机失败"; } @Override public String platformStopCharging(PlatformStopCharging platformStopCharging) { throw new RuntimeException("远程停机失败" + throwable.getMessage()); // 手动进行全局事务回滚 try { GlobalTransactionContext.getCurrent().rollback(); } catch (TransactionException e) { throw new RuntimeException(e); } return "远程停机失败"; } }; } ruoyi-api/ruoyi-api-order/pom.xml
@@ -32,7 +32,10 @@ <groupId>com.ruoyi</groupId> <artifactId>ruoyi-api-other</artifactId> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-seata</artifactId> </dependency> </dependencies> </project> ruoyi-api/ruoyi-api-order/src/main/java/com/ruoyi/order/api/model/AccountingStrategyOrder.java
@@ -21,10 +21,6 @@ @TableName("t_accounting_strategy_order") public class AccountingStrategyOrder extends BasePojo { @ApiModelProperty(value = "主键") @TableField(value = "id") private Integer id; @ApiModelProperty(value = "站点id") @TableField("site_id") private Integer siteId; ruoyi-api/ruoyi-api-other/pom.xml
@@ -32,6 +32,10 @@ <groupId>com.ruoyi</groupId> <artifactId>ruoyi-api-account</artifactId> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-seata</artifactId> </dependency> </dependencies> </project> ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/factory/CouponFallbackFactory.java
@@ -5,6 +5,8 @@ import com.ruoyi.other.api.domain.TGoods; import com.ruoyi.other.api.feignClient.CouponClient; import com.ruoyi.other.api.feignClient.GoodsClient; import io.seata.core.exception.TransactionException; import io.seata.tm.api.GlobalTransactionContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cloud.openfeign.FallbackFactory; @@ -38,7 +40,13 @@ @Override public R updateCoupon(TCoupon coupon) { throw new RuntimeException("修改优惠券失败"); // 手动进行全局事务回滚 try { GlobalTransactionContext.getCurrent().rollback(); } catch (TransactionException e) { throw new RuntimeException(e); } return R.fail("修改优惠券失败"); } }; } ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/factory/GoodsFallbackFactory.java
@@ -3,6 +3,8 @@ import com.ruoyi.common.core.domain.R; import com.ruoyi.other.api.domain.TGoods; import com.ruoyi.other.api.feignClient.GoodsClient; import io.seata.core.exception.TransactionException; import io.seata.tm.api.GlobalTransactionContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cloud.openfeign.FallbackFactory; @@ -36,7 +38,13 @@ @Override public R updateGoods(TGoods goods) { throw new RuntimeException("修改商品异常"); // 手动进行全局事务回滚 try { GlobalTransactionContext.getCurrent().rollback(); } catch (TransactionException e) { throw new RuntimeException(e); } return R.fail("修改商品异常"); } }; } ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/factory/InvoiceTypeFallbackFactory.java
@@ -3,6 +3,8 @@ import com.ruoyi.common.core.domain.R; import com.ruoyi.other.api.domain.TInvoiceType; import com.ruoyi.other.api.feignClient.InvoiceTypeClient; import io.seata.core.exception.TransactionException; import io.seata.tm.api.GlobalTransactionContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cloud.openfeign.FallbackFactory; @@ -27,7 +29,13 @@ @Override public R<TInvoiceType> getInvoiceType(Integer id) { throw new RuntimeException(throwable.getMessage()); // 手动进行全局事务回滚 try { GlobalTransactionContext.getCurrent().rollback(); } catch (TransactionException e) { throw new RuntimeException(e); } return R.fail(throwable.getMessage()); } }; } ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/factory/UserSiteFallbackFactory.java
@@ -3,6 +3,8 @@ import com.ruoyi.common.core.domain.R; import com.ruoyi.other.api.domain.TUserSite; import com.ruoyi.other.api.feignClient.UserSiteClient; import io.seata.core.exception.TransactionException; import io.seata.tm.api.GlobalTransactionContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cloud.openfeign.FallbackFactory; @@ -31,12 +33,24 @@ @Override public R addUserSite(List<TUserSite> userSite) { throw new RuntimeException("添加用户站点失败:" + throwable.getMessage()); // 手动进行全局事务回滚 try { GlobalTransactionContext.getCurrent().rollback(); } catch (TransactionException e) { throw new RuntimeException(e); } return R.fail("添加用户站点失败:" + throwable.getMessage()); } @Override public R delUserSite(Long userId) { throw new RuntimeException("删除用户站点失败:" + throwable.getMessage()); // 手动进行全局事务回滚 try { GlobalTransactionContext.getCurrent().rollback(); } catch (TransactionException e) { throw new RuntimeException(e); } return R.fail("删除用户站点失败:" + throwable.getMessage()); } }; } ruoyi-api/ruoyi-api-payment/pom.xml
@@ -28,7 +28,10 @@ </exclusion> </exclusions> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-seata</artifactId> </dependency> </dependencies> </project> ruoyi-api/ruoyi-api-payment/src/main/java/com/ruoyi/payment/api/factory/AliPaymentFallbackFactory.java
@@ -7,6 +7,8 @@ import com.ruoyi.payment.api.vo.AliPaymentReq; import com.ruoyi.payment.api.vo.AliPaymentResp; import com.ruoyi.payment.api.vo.AliQueryOrder; import io.seata.core.exception.TransactionException; import io.seata.tm.api.GlobalTransactionContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cloud.openfeign.FallbackFactory; @@ -30,22 +32,46 @@ @Override public R<AliPaymentResp> payment(AliPaymentReq req) { throw new RuntimeException("调起支付宝小程序支付失败:" + throwable.getMessage()); // 手动进行全局事务回滚 try { GlobalTransactionContext.getCurrent().rollback(); } catch (TransactionException e) { throw new RuntimeException(e); } return R.fail("调起支付宝小程序支付失败:" + throwable.getMessage()); } @Override public R<AliQueryOrder> query(String outTradeNo) { throw new RuntimeException("查询支付订单失败:" + throwable.getMessage()); // 手动进行全局事务回滚 try { GlobalTransactionContext.getCurrent().rollback(); } catch (TransactionException e) { throw new RuntimeException(e); } return R.fail("查询支付订单失败:" + throwable.getMessage()); } @Override public void close(String outTradeNo) { throw new RuntimeException("关闭支付订单失败:" + throwable.getMessage()); // 手动进行全局事务回滚 try { GlobalTransactionContext.getCurrent().rollback(); } catch (TransactionException e) { throw new RuntimeException(e); } R.fail("关闭支付订单失败:" + throwable.getMessage()); } @Override public R<RefundResp> refund(RefundReq dto) { throw new RuntimeException("支付宝退款失败:" + throwable.getMessage()); // 手动进行全局事务回滚 try { GlobalTransactionContext.getCurrent().rollback(); } catch (TransactionException e) { throw new RuntimeException(e); } return R.fail("支付宝退款失败:" + throwable.getMessage()); } }; } ruoyi-api/ruoyi-api-payment/src/main/java/com/ruoyi/payment/api/factory/WxPaymentFallbackFactory.java
@@ -6,6 +6,8 @@ import com.ruoyi.payment.api.vo.NotifyV3PayDecodeRespBody; import com.ruoyi.payment.api.vo.PaymentOrder; import com.ruoyi.payment.api.vo.WxRefundNotifyResp; import io.seata.core.exception.TransactionException; import io.seata.tm.api.GlobalTransactionContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cloud.openfeign.FallbackFactory; @@ -31,12 +33,24 @@ @Override public R<NotifyV3PayDecodeRespBody> queryOrderInfo(String orderId) { throw new RuntimeException("查询支付订单信息失败:" + throwable.getMessage()); // 手动进行全局事务回滚 try { GlobalTransactionContext.getCurrent().rollback(); } catch (TransactionException e) { throw new RuntimeException(e); } return R.fail("查询支付订单信息失败:" + throwable.getMessage()); } @Override public R<Map<String, Object>> orderPay(PaymentOrder paymentOrder) { throw new RuntimeException("调起微信支付失败:" + throwable.getMessage()); // 手动进行全局事务回滚 try { GlobalTransactionContext.getCurrent().rollback(); } catch (TransactionException e) { throw new RuntimeException(e); } return R.fail("调起微信支付失败:" + throwable.getMessage()); } @Override @@ -51,13 +65,24 @@ @Override public void close(String outTradeNo) { throw new RuntimeException("关闭支付订单失败:" + throwable.getMessage()); // 手动进行全局事务回滚 try { GlobalTransactionContext.getCurrent().rollback(); } catch (TransactionException e) { throw new RuntimeException(e); } R.fail("关闭支付订单失败:" + throwable.getMessage()); } @Override public R<String> refundOrderR(WxPaymentRefundModel model) { // 手动进行全局事务回滚 try { GlobalTransactionContext.getCurrent().rollback(); } catch (TransactionException e) { throw new RuntimeException(e); } return R.fail("微信退款失败:" + throwable.getMessage()); } @Override ruoyi-api/ruoyi-api-system/pom.xml
@@ -28,6 +28,10 @@ </exclusion> </exclusions> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-seata</artifactId> </dependency> </dependencies> </project> ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/SysUserFallbackFactory.java
@@ -5,6 +5,8 @@ import com.ruoyi.system.api.domain.SysUser; import com.ruoyi.system.api.feignClient.SysUserClient; import com.ruoyi.system.api.model.*; import io.seata.core.exception.TransactionException; import io.seata.tm.api.GlobalTransactionContext; import org.springframework.cloud.openfeign.FallbackFactory; import org.springframework.stereotype.Component; @@ -27,7 +29,13 @@ @Override public R<Boolean> updateSysUser(SysUser sysUser) { throw new RuntimeException("更新用户失败:" + cause.getMessage()); // 手动进行全局事务回滚 try { GlobalTransactionContext.getCurrent().rollback(); } catch (TransactionException e) { throw new RuntimeException(e); } return R.fail("更新用户失败:" + cause.getMessage()); } @Override @@ -92,12 +100,24 @@ @Override public R addSysUser(SysUser user) { throw new RuntimeException("添加用户失败:" + cause.getMessage()); // 手动进行全局事务回滚 try { GlobalTransactionContext.getCurrent().rollback(); } catch (TransactionException e) { throw new RuntimeException(e); } return R.fail("添加用户失败:" + cause.getMessage()); } @Override public R resetPassword(SysUser user) { throw new RuntimeException("重置用户密码失败:" + cause.getMessage()); // 手动进行全局事务回滚 try { GlobalTransactionContext.getCurrent().rollback(); } catch (TransactionException e) { throw new RuntimeException(e); } return R.fail("重置用户密码失败:" + cause.getMessage()); } }; } ruoyi-auth/src/main/resources/bootstrap.yml
@@ -1,3 +1,7 @@ server: port: 9100 tomcat: basedir: /data/tomcat # Spring spring: profiles: @@ -8,6 +12,7 @@ name: ruoyi-auth main: allow-bean-definition-overriding: true allow-circular-references: true --- spring: config: @@ -36,9 +41,7 @@ # 共享配置 shared-configs: - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} --- seata: enabled: true application-id: ${spring.application.name} @@ -51,36 +54,57 @@ config: type: nacos nacos: # 开发环境 server-addr: 192.168.110.169:8848 namespace: b5290bc2-e3aa-4988-8a7d-9c07e4e073cb group: DEFAULT_GROUP data-id: seata-server.properties username: nacos password: nacos # 生产环境 # server-addr: 192.168.0.137:8848,192.168.0.123:8848 # namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a # group: DEFAULT_GROUP # data-id: seata-server.properties # username: nacos # password: nacos registry: type: nacos nacos: application: seata-server # 开发环境 server-addr: 192.168.110.169:8848 namespace: b5290bc2-e3aa-4988-8a7d-9c07e4e073cb group: DEFAULT_GROUP username: nacos password: nacos # 生产环境 # server-addr: 192.168.0.137:8848,192.168.0.123:8848 # namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a # group: DEFAULT_GROUP # username: nacos # password: nacos cloud: nacos: discovery: # 开发环境 server-addr: 192.168.110.169:8848 # nacos注册中心地址 namespace: b5290bc2-e3aa-4988-8a7d-9c07e4e073cb # 命名空间 group: DEFAULT_GROUP application: seata-server #Nacos 中 Seata 名称 username: nacos password: nacos # 生产环境 # server-addr: 192.168.0.137:8848,192.168.0.123:8848 # namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a # group: DEFAULT_GROUP # application: seata-server #Nacos 中 Seata 名称 # username: nacos # password: nacos sentinel: transport: dashboard: 127.0.0.1:8080 # Sentinel控制台地址 eager: true --- spring: config: @@ -90,14 +114,18 @@ nacos: discovery: # 服务注册地址 server-addr: 127.0.0.1:8848 server-addr: 192.168.0.137:8848,192.168.0.123:8848 service: ${spring.application.name} group: DEFAULT_GROUP namespace: 3452d750-b08d-4485-a1e9-4fb0548f1fc2 namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a username: nacos password: nacos config: # 配置中心地址 server-addr: 127.0.0.1:8848 namespace: 3452d750-b08d-4485-a1e9-4fb0548f1fc2 server-addr: 192.168.0.137:8848,192.168.0.123:8848 namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a username: nacos password: nacos group: DEFAULT_GROUP name: ${spring.application.name} # 配置文件格式 ruoyi-gateway/pom.xml
@@ -114,18 +114,6 @@ <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-api-account</artifactId> <version>3.6.2</version> <scope>compile</scope> </dependency> <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-api-system</artifactId> <version>3.6.2</version> <scope>compile</scope> </dependency> </dependencies> ruoyi-gateway/src/main/java/com/ruoyi/gateway/config/properties/AntiShakeProperties.java
New file @@ -0,0 +1,34 @@ package com.ruoyi.gateway.config.properties; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.context.annotation.Configuration; /** * @author ruoyi */ @Configuration @RefreshScope @ConfigurationProperties(prefix = "security.anti-shake") public class AntiShakeProperties { private Boolean enable; private Long interval; public Boolean getEnable() { return enable; } public void setEnable(Boolean enable) { this.enable = enable; } public Long getInterval() { return interval; } public void setInterval(Long interval) { this.interval = interval; } } ruoyi-gateway/src/main/java/com/ruoyi/gateway/config/properties/SignProperties.java
New file @@ -0,0 +1,27 @@ package com.ruoyi.gateway.config.properties; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.context.annotation.Configuration; import java.util.ArrayList; import java.util.List; /** * @author ruoyi */ @Configuration @RefreshScope @ConfigurationProperties(prefix = "security.sign") public class SignProperties { private Boolean enable; public Boolean getEnable() { return enable; } public void setEnable(Boolean enable) { this.enable = enable; } } ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/AuthFilter.java
@@ -1,5 +1,6 @@ package com.ruoyi.gateway.filter; import com.ruoyi.gateway.config.properties.AntiShakeProperties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -39,9 +40,12 @@ // 排除过滤的 uri 地址,nacos自行添加 @Autowired private IgnoreWhiteProperties ignoreWhite; @Autowired private AntiShakeProperties antiShakeProperties; @Autowired private RedisService redisService; @@ -59,7 +63,7 @@ try { antiShake(request); }catch (Exception e){ log.error("[重复提交]请求路径:{}", exchange.getRequest().getPath()); log.error(e.getMessage()); return ServletUtils.webFluxResponseWriter(exchange.getResponse(), e.getMessage(), HttpStatus.SUCCESS); } @@ -129,7 +133,7 @@ */ public void antiShake(ServerHttpRequest request) throws Exception{ HttpMethod method = request.getMethod(); if(HttpMethod.OPTIONS == method){ if(HttpMethod.OPTIONS == method || !antiShakeProperties.getEnable()){ return; } HttpHeaders headers = request.getHeaders(); @@ -155,8 +159,8 @@ Long old_timestamp = Long.valueOf(o.toString()); Long new_timestamp = Long.valueOf(timestamp); //两个请求时间差小于1秒,判定为重复提交 if((new_timestamp - old_timestamp) <= 500){ throw new RuntimeException("重复提交"); if((new_timestamp - old_timestamp) <= antiShakeProperties.getInterval()){ throw new RuntimeException(url + "----->重复提交"); }else{ cacheMap.put(url, timestamp); } ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/SignFilter.java
@@ -3,27 +3,21 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.ruoyi.common.core.constant.CacheConstants; import com.ruoyi.common.core.constant.HttpStatus; import com.ruoyi.common.core.constant.SecurityConstants; import com.ruoyi.common.core.constant.TokenConstants; import com.ruoyi.common.core.utils.JwtUtils; import com.ruoyi.common.core.utils.ServletUtils; import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.redis.service.RedisService; import com.ruoyi.gateway.config.properties.IgnoreWhiteProperties; import io.jsonwebtoken.Claims; import com.ruoyi.gateway.config.properties.SignProperties; import org.apache.commons.codec.binary.Base64; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.gateway.filter.GatewayFilterChain; import org.springframework.cloud.gateway.filter.GlobalFilter; import org.springframework.core.Ordered; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferUtils; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpRequestDecorator; @@ -37,7 +31,6 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.concurrent.atomic.AtomicReference; /** * 网关鉴权 @@ -48,11 +41,11 @@ public class SignFilter implements GlobalFilter, Ordered { private static final Logger log = LoggerFactory.getLogger(SignFilter.class); @Value("${security.sign}") private boolean parameter_signature; @Autowired private IgnoreWhiteProperties ignoreWhite; @Autowired private SignProperties signProperties; @Override @@ -71,13 +64,13 @@ } String sign = request.getHeaders().getFirst(TokenConstants.SIGN); String nonce_str = request.getHeaders().getFirst(TokenConstants.NONCE_STR); if (parameter_signature && StringUtils.isEmpty(sign)) { if (signProperties.getEnable() && StringUtils.isEmpty(sign)) { return unauthorizedResponse(exchange, "签名不能为空!"); } if (parameter_signature && StringUtils.isEmpty(nonce_str)) { if (signProperties.getEnable() && StringUtils.isEmpty(nonce_str)) { return unauthorizedResponse(exchange, "签名不能为空!"); } if(parameter_signature){ if(signProperties.getEnable()){ return authSign(exchange, chain, sign, nonce_str); } return chain.filter(exchange.mutate().request(mutate.build()).build()); ruoyi-gateway/src/main/resources/bootstrap.yml
@@ -1,3 +1,8 @@ server: port: 9000 tomcat: basedir: /data/tomcat max-swallow-size: 100MB # Spring spring: application: @@ -49,6 +54,8 @@ server-addr: 192.168.110.169:8848 dataId: sentinel-ruoyi-gateway groupId: DEFAULT_GROUP username: nacos password: nacos data-type: json rule-type: gw-flow --- @@ -60,14 +67,18 @@ nacos: discovery: # 服务注册地址 server-addr: 127.0.0.1:8848 server-addr: 192.168.0.137:8848,192.168.0.123:8848 service: ${spring.application.name} group: DEFAULT_GROUP namespace: c2f47d1c-6355-4a68-b357-7523d73b2d13 namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a username: nacos password: nacos config: # 配置中心地址 server-addr: 127.0.0.1:8848 namespace: c2f47d1c-6355-4a68-b357-7523d73b2d13 server-addr: 192.168.0.137:8848,192.168.0.123:8848 namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a username: nacos password: nacos group: DEFAULT_GROUP name: ${spring.application.name} # 配置文件格式 @@ -80,14 +91,16 @@ eager: true transport: # 控制台地址 dashboard: 122.9.150.46:8718 dashboard: 192.168.0.137:8718 # nacos配置持久化 datasource: ds1: nacos: server-addr: 127.0.0.1:8848 server-addr: 192.168.0.137:8848,192.168.0.123:8848 dataId: sentinel-ruoyi-gateway groupId: DEFAULT_GROUP username: nacos password: nacos data-type: json rule-type: gw-flow --- ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/filter/AuthFilter.java
@@ -12,6 +12,7 @@ import org.apache.logging.log4j.core.config.Order; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; ruoyi-modules/ruoyi-system/src/main/resources/bootstrap.yml
@@ -1,3 +1,7 @@ server: port: 9800 tomcat: basedir: /data/tomcat # Spring spring: application: @@ -36,10 +40,7 @@ # 共享配置 shared-configs: - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} --- seata: enabled: true application-id: ${spring.application.name} @@ -52,36 +53,57 @@ config: type: nacos nacos: # 开发环境 server-addr: 192.168.110.169:8848 namespace: b5290bc2-e3aa-4988-8a7d-9c07e4e073cb group: DEFAULT_GROUP data-id: seata-server.properties username: nacos password: nacos # 生产环境 # server-addr: 192.168.0.137:8848,192.168.0.123:8848 # namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a # group: DEFAULT_GROUP # data-id: seata-server.properties # username: nacos # password: nacos registry: type: nacos nacos: application: seata-server # 开发环境 server-addr: 192.168.110.169:8848 namespace: b5290bc2-e3aa-4988-8a7d-9c07e4e073cb group: DEFAULT_GROUP username: nacos password: nacos # 生产环境 # server-addr: 192.168.0.137:8848,192.168.0.123:8848 # namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a # group: DEFAULT_GROUP # username: nacos # password: nacos cloud: nacos: discovery: # 开发环境 server-addr: 192.168.110.169:8848 # nacos注册中心地址 namespace: b5290bc2-e3aa-4988-8a7d-9c07e4e073cb # 命名空间 group: DEFAULT_GROUP application: seata-server #Nacos 中 Seata 名称 username: nacos password: nacos # 生产环境 # server-addr: 192.168.0.137:8848,192.168.0.123:8848 # namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a # group: DEFAULT_GROUP # application: seata-server #Nacos 中 Seata 名称 # username: nacos # password: nacos sentinel: transport: dashboard: 127.0.0.1:8080 # Sentinel控制台地址 eager: true --- spring: config: @@ -91,14 +113,18 @@ nacos: discovery: # 服务注册地址 server-addr: 127.0.0.1:8848 server-addr: 192.168.0.137:8848,192.168.0.123:8848 service: ${spring.application.name} group: DEFAULT_GROUP namespace: 3452d750-b08d-4485-a1e9-4fb0548f1fc2 namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a username: nacos password: nacos config: # 配置中心地址 server-addr: 127.0.0.1:8848 namespace: 3452d750-b08d-4485-a1e9-4fb0548f1fc2 server-addr: 192.168.0.137:8848,192.168.0.123:8848 namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a username: nacos password: nacos group: DEFAULT_GROUP name: ${spring.application.name} # 配置文件格式 ruoyi-service/pom.xml
ruoyi-service/ruoyi-account/pom.xml
@@ -150,7 +150,13 @@ <version>1.0.4</version> <scope>compile</scope> </dependency> <dependency> <groupId>com.huaweicloud.apigateway</groupId> <artifactId>apigateway</artifactId> <version>3.2.5</version> <scope>system</scope> <systemPath>${project.basedir}/lib/java-sdk-core-3.2.5.jar</systemPath> </dependency> </dependencies> <build> @@ -173,6 +179,13 @@ <directory>src/main/resources</directory> </resource> <resource> <directory>lib</directory> <targetPath>/BOOT-INF/lib/</targetPath> <includes> <include>**/*.jar</include> </includes> </resource> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppUserController.java
@@ -813,6 +813,8 @@ appUserService.updateById(byId); return R.ok(); } //已签到日期 @ApiOperation(value = "本月已签到日期", tags = {"小程序-个人中心-签到"}) @GetMapping(value = "/user/has/sign") ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/WxLoginController.java
@@ -67,4 +67,16 @@ appletUserDecodeData.setOpenId(openid); return AjaxResult.success(appUserService.wxLogin(appletUserDecodeData,data.getInviteUserId())); } /** * 测试用 * @param appletUserDecodeData * @return */ @ApiOperation(value = "通过code获得openid,获取用户信息",tags = {"微信小程序登录"}) @PostMapping("/openIdByJsCodeTest") public AjaxResult<Map<String, Object>> openIdByJsCode(@RequestBody AppletUserDecodeData appletUserDecodeData) { return AjaxResult.success(appUserService.wxLogin(appletUserDecodeData, null)); } } ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/filter/AuthFilter.java
@@ -11,6 +11,7 @@ import org.apache.logging.log4j.core.config.Order; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/TAppCouponServiceImpl.java
@@ -42,6 +42,7 @@ import java.util.Comparator; import java.util.Date; import java.util.List; import java.util.stream.Collectors; /** * <p> @@ -76,10 +77,19 @@ List<Integer> integers = new ArrayList<>(); integers.add(1); integers.add(2); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); QueryWrapper<TAppCoupon> wrapper = new QueryWrapper<>(); wrapper.eq("coupon_id",dto.getCouponId()); wrapper.in("ways_to_obtain",integers); if (StringUtils.hasLength(dto.getPhone())){ List<Long> collect = tAppUserMapper.selectList(new QueryWrapper<TAppUser>().like("phone", dto.getPhone())).stream() .map(TAppUser::getId).collect(Collectors.toList()); if(collect.isEmpty()){ collect.add(-1L); } wrapper.in("id",collect); } if (dto.getStatus()!=null){ wrapper.eq("status",dto.getStatus()); } ruoyi-service/ruoyi-account/src/main/resources/bootstrap.yml
@@ -1,3 +1,7 @@ server: port: 9200 tomcat: basedir: /data/tomcat # Spring spring: application: @@ -38,7 +42,6 @@ shared-configs: - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} --- seata: enabled: true application-id: ${spring.application.name} @@ -51,36 +54,57 @@ config: type: nacos nacos: # 开发环境 server-addr: 192.168.110.169:8848 namespace: b5290bc2-e3aa-4988-8a7d-9c07e4e073cb group: DEFAULT_GROUP data-id: seata-server.properties username: nacos password: nacos # 生产环境 # server-addr: 192.168.0.137:8848,192.168.0.123:8848 # namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a # group: DEFAULT_GROUP # data-id: seata-server.properties # username: nacos # password: nacos registry: type: nacos nacos: application: seata-server # 开发环境 server-addr: 192.168.110.169:8848 namespace: b5290bc2-e3aa-4988-8a7d-9c07e4e073cb group: DEFAULT_GROUP username: nacos password: nacos # 生产环境 # server-addr: 192.168.0.137:8848,192.168.0.123:8848 # namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a # group: DEFAULT_GROUP # username: nacos # password: nacos cloud: nacos: discovery: # 开发环境 server-addr: 192.168.110.169:8848 # nacos注册中心地址 namespace: b5290bc2-e3aa-4988-8a7d-9c07e4e073cb # 命名空间 group: DEFAULT_GROUP application: seata-server #Nacos 中 Seata 名称 username: nacos password: nacos # 生产环境 # server-addr: 192.168.0.137:8848,192.168.0.123:8848 # namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a # group: DEFAULT_GROUP # application: seata-server #Nacos 中 Seata 名称 # username: nacos # password: nacos sentinel: transport: dashboard: 127.0.0.1:8080 # Sentinel控制台地址 dashboard: 192.168.0.137:8080 # Sentinel控制台地址 eager: true --- spring: config: @@ -90,14 +114,18 @@ nacos: discovery: # 服务注册地址 server-addr: 127.0.0.1:8848 server-addr: 192.168.0.137:8848,192.168.0.123:8848 service: ${spring.application.name} group: DEFAULT_GROUP namespace: 3452d750-b08d-4485-a1e9-4fb0548f1fc2 namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a username: nacos password: nacos config: # 配置中心地址 server-addr: 127.0.0.1:8848 namespace: 3452d750-b08d-4485-a1e9-4fb0548f1fc2 server-addr: 192.168.0.137:8848,192.168.0.123:8848 namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a username: nacos password: nacos group: DEFAULT_GROUP name: ${spring.application.name} # 配置文件格式 ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/filter/AuthFilter.java
@@ -11,6 +11,7 @@ import org.apache.logging.log4j.core.config.Order; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; ruoyi-service/ruoyi-chargingPile/src/main/resources/bootstrap.yml
@@ -1,3 +1,7 @@ server: port: 9300 tomcat: basedir: /data/tomcat # Spring spring: application: @@ -37,9 +41,7 @@ # 共享配置 shared-configs: - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} --- seata: enabled: true application-id: ${spring.application.name} @@ -52,30 +54,53 @@ config: type: nacos nacos: # 开发环境 server-addr: 192.168.110.169:8848 namespace: b5290bc2-e3aa-4988-8a7d-9c07e4e073cb group: DEFAULT_GROUP data-id: seata-server.properties username: nacos password: nacos # 生产环境 # server-addr: 192.168.0.137:8848,192.168.0.123:8848 # namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a # group: DEFAULT_GROUP # data-id: seata-server.properties # username: nacos # password: nacos registry: type: nacos nacos: application: seata-server # 开发环境 server-addr: 192.168.110.169:8848 namespace: b5290bc2-e3aa-4988-8a7d-9c07e4e073cb group: DEFAULT_GROUP username: nacos password: nacos # 生产环境 # server-addr: 192.168.0.137:8848,192.168.0.123:8848 # namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a # group: DEFAULT_GROUP # username: nacos # password: nacos cloud: nacos: discovery: # 开发环境 server-addr: 192.168.110.169:8848 # nacos注册中心地址 namespace: b5290bc2-e3aa-4988-8a7d-9c07e4e073cb # 命名空间 group: DEFAULT_GROUP application: seata-server #Nacos 中 Seata 名称 username: nacos password: nacos # 生产环境 # server-addr: 192.168.0.137:8848,192.168.0.123:8848 # namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a # group: DEFAULT_GROUP # application: seata-server #Nacos 中 Seata 名称 # username: nacos # password: nacos sentinel: transport: dashboard: 127.0.0.1:8080 # Sentinel控制台地址 @@ -89,14 +114,18 @@ nacos: discovery: # 服务注册地址 server-addr: 127.0.0.1:8848 server-addr: 192.168.0.137:8848,192.168.0.123:8848 service: ${spring.application.name} group: DEFAULT_GROUP namespace: 3452d750-b08d-4485-a1e9-4fb0548f1fc2 namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a username: nacos password: nacos config: # 配置中心地址 server-addr: 127.0.0.1:8848 namespace: 3452d750-b08d-4485-a1e9-4fb0548f1fc2 server-addr: 192.168.0.137:8848,192.168.0.123:8848 namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a username: nacos password: nacos group: DEFAULT_GROUP name: ${spring.application.name} # 配置文件格式 ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/utils/api/IotInterfaceUtil.java
@@ -113,16 +113,15 @@ /** * 创建设备 * @param productId 产品ID * @param nodeId 设备标识码 通常使用IMEI、MAC地址或Serial No作为node_id * @param deviceId 设备ID 使用设备标识码 * @param nodeId 设备标识码 设备编号 * @param deviceName 设备名称 * @param description 设备描述 * @return AddDeviceResponse */ public AddDeviceResponse addDeviceRequest(String productId,String nodeId,String deviceId,String deviceName,String description) { public AddDeviceResponse addDeviceRequest(String productId,String nodeId,String deviceName,String description) { AddDeviceRequest request = new AddDeviceRequest(); AddDevice body = new AddDevice(); body.withDeviceId(deviceId); body.withDeviceId(nodeId); body.withNodeId(nodeId); body.withDeviceName(deviceName); body.withProductId(productId); ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/utils/listener/IotMessageListener.java
@@ -16,13 +16,12 @@ import com.ruoyi.integration.iotda.utils.tools.StrategyUtil; import com.ruoyi.integration.rocket.model.*; import com.ruoyi.integration.rocket.produce.EnhanceProduce; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.apache.rocketmq.client.producer.SendResult; import org.springframework.beans.BeanUtils; 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.RestController; import org.springframework.web.bind.annotation.*; import java.io.IOException; import java.math.BigDecimal; @@ -36,6 +35,7 @@ */ @Slf4j @RestController @RequestMapping("/iot") public class IotMessageListener { @Autowired @@ -266,60 +266,97 @@ return AjaxResult.success(); } @PostMapping(value = "/message/sendMessage") public R sendMessage() { @ApiOperation(value = "运营平台远程控制启机",tags = {"硬件接口"}) @GetMapping(value = "/platformStartCharging") public R platformStartCharging(String orderNum,String deviceId,Long orderId,BigDecimal money) { // 运营平台远程控制启机 // PlatformStartCharging platformStartCharging = new PlatformStartCharging(); // platformStartCharging.setTransaction_serial_number("4200002375202409185150427245"); // platformStartCharging.setCharging_pile_code("3401231001200202"); // platformStartCharging.setCharging_gun_code("1"); // platformStartCharging.setCard_number("1833063878153543681"); // platformStartCharging.setAccount_balance(new BigDecimal(50)); // String message = iotMessageProduce.sendMessage(platformStartCharging.getCharging_pile_code(), ServiceIdMenu.PLATFORM_START_CHARGING.getKey(), messageUtil.platformStartCharging(platformStartCharging)); PlatformStartCharging platformStartCharging = new PlatformStartCharging(); platformStartCharging.setTransaction_serial_number(orderNum); platformStartCharging.setCharging_pile_code(deviceId); platformStartCharging.setCharging_gun_code("1"); platformStartCharging.setCard_number(orderId.toString()); platformStartCharging.setAccount_balance(money); String message = iotMessageProduce.sendMessage(platformStartCharging.getCharging_pile_code(), ServiceIdMenu.PLATFORM_START_CHARGING.getKey(), messageUtil.platformStartCharging(platformStartCharging)); return R.ok(message); } @ApiOperation(value = "运营平台远程停机",tags = {"硬件接口"}) @GetMapping(value = "/platformStopCharging") public R platformStopCharging(String deviceId) { // 运营平台远程停机 // PlatformStopCharging platformStopCharging = new PlatformStopCharging(); // platformStopCharging.setCharging_pile_code("3401231001200202"); // platformStopCharging.setCharging_gun_code("1"); // String message = iotMessageProduce.sendMessage(platformStopCharging.getCharging_pile_code(), ServiceIdMenu.PLATFORM_STOP_CHARGING.getKey(),messageUtil.platformStopCharging(platformStopCharging)); PlatformStopCharging platformStopCharging = new PlatformStopCharging(); platformStopCharging.setCharging_pile_code(deviceId); platformStopCharging.setCharging_gun_code("1"); String message = iotMessageProduce.sendMessage(platformStopCharging.getCharging_pile_code(), ServiceIdMenu.PLATFORM_STOP_CHARGING.getKey(),messageUtil.platformStopCharging(platformStopCharging)); return R.ok(message); } @ApiOperation(value = "修改余额",tags = {"硬件接口"}) @GetMapping(value = "/updateBalance") public R updateBalance(String deviceId,Long orderId) { // 修改余额 // UpdateBalance updateBalance = new UpdateBalance(); // updateBalance.setCharging_pile_code("3401231001200202"); // updateBalance.setCharging_gun_code("1"); // updateBalance.setPhysical_card_number("1833063878153543681"); // updateBalance.setAccount_balance(new BigDecimal(20)); // String message = iotMessageProduce.sendMessage(updateBalance.getCharging_pile_code(), ServiceIdMenu.UPDATE_BALANCE.getKey(),messageUtil.updateBalance(updateBalance)); UpdateBalance updateBalance = new UpdateBalance(); updateBalance.setCharging_pile_code(deviceId); updateBalance.setCharging_gun_code("1"); updateBalance.setPhysical_card_number(orderId.toString()); updateBalance.setAccount_balance(new BigDecimal(20)); String message = iotMessageProduce.sendMessage(updateBalance.getCharging_pile_code(), ServiceIdMenu.UPDATE_BALANCE.getKey(),messageUtil.updateBalance(updateBalance)); return R.ok(message); } @ApiOperation(value = "充电桩工作参数设置",tags = {"硬件接口"}) @GetMapping(value = "/workingParameterSetting") public R workingParameterSetting(String deviceId) { // 充电桩工作参数设置 // WorkingParameterSetting workingParameterSetting = new WorkingParameterSetting(); // workingParameterSetting.setCharging_pile_code("3401231001200202"); // workingParameterSetting.setAllow_work(0); // workingParameterSetting.setMaximum_output_power(220); // String message = iotMessageProduce.sendMessage(workingParameterSetting.getCharging_pile_code(), ServiceIdMenu.WORKING_PARAMETER_SETTING.getKey(),messageUtil.workingParameterSetting(workingParameterSetting)); WorkingParameterSetting workingParameterSetting = new WorkingParameterSetting(); workingParameterSetting.setCharging_pile_code(deviceId); workingParameterSetting.setAllow_work(0); workingParameterSetting.setMaximum_output_power(220); String message = iotMessageProduce.sendMessage(workingParameterSetting.getCharging_pile_code(), ServiceIdMenu.WORKING_PARAMETER_SETTING.getKey(),messageUtil.workingParameterSetting(workingParameterSetting)); return R.ok(message); } @ApiOperation(value = "对时设置",tags = {"硬件接口"}) @GetMapping(value = "/timingSetting") public R timingSetting(String deviceId) { // 对时设置 // TimingSetting timingSetting = new TimingSetting(); // timingSetting.setCharging_pile_code("3401231001200202"); // System.err.println(CP56Time2aConverter.convertToCP56Time2a(new Date())); // timingSetting.setCurrent_time(CP56Time2aConverter.convertToCP56Time2a(new Date())); // String message = iotMessageProduce.sendMessage(timingSetting.getCharging_pile_code(), ServiceIdMenu.TIMING_SETTING.getKey(),messageUtil.timingSetting(timingSetting)); TimingSetting timingSetting = new TimingSetting(); timingSetting.setCharging_pile_code(deviceId); timingSetting.setCurrent_time(CP56Time2aConverter.convertToCP56Time2a(new Date())); String message = iotMessageProduce.sendMessage(timingSetting.getCharging_pile_code(), ServiceIdMenu.TIMING_SETTING.getKey(),messageUtil.timingSetting(timingSetting)); return R.ok(message); } @ApiOperation(value = "计费模型设置",tags = {"硬件接口"}) @GetMapping(value = "/setupBillingModel") public R setupBillingModel(String deviceId) { // TODO 罗 计费模型设置 // SetupBillingModel setupBillingModel = new SetupBillingModel(); // // 计费模型 // List<TAccountingStrategyDetail> accountingStrategyDetails = accountingStrategyDetailClient.getDetailListByCode("3401231001200202").getData(); // Map<Integer, TAccountingStrategyDetail> strategyPrice = StrategyUtil.getStrategyPrice(accountingStrategyDetails); // // 价格设置 // AcquisitionBillingModeReply acquisitionBillingModeReply = new AcquisitionBillingModeReply(); // StrategyUtil.setStrategyPrice(strategyPrice,acquisitionBillingModeReply); // // 时段设置 // StrategyUtil.setTime(accountingStrategyDetails,acquisitionBillingModeReply); // TAccountingStrategyDetail accountingStrategyDetail = accountingStrategyDetailClient.getDetailByCode("3401231001200202").getData(); // acquisitionBillingModeReply.setBilling_model_code(accountingStrategyDetail.getId().toString()); // acquisitionBillingModeReply.setCharging_pile_code("3401231001200202"); // acquisitionBillingModeReply.setLoss_ratio(BigDecimal.ZERO); // BeanUtils.copyProperties(acquisitionBillingModeReply,setupBillingModel); // System.err.println(setupBillingModel); // String message = iotMessageProduce.sendMessage(setupBillingModel.getCharging_pile_code(), ServiceIdMenu.SETUP_BILLING_MODEL.getKey(),messageUtil.setupBillingModel(setupBillingModel)); SetupBillingModel setupBillingModel = new SetupBillingModel(); // 计费模型 List<TAccountingStrategyDetail> accountingStrategyDetails = accountingStrategyDetailClient.getDetailListByCode(deviceId).getData(); Map<Integer, TAccountingStrategyDetail> strategyPrice = StrategyUtil.getStrategyPrice(accountingStrategyDetails); // 价格设置 AcquisitionBillingModeReply acquisitionBillingModeReply = new AcquisitionBillingModeReply(); StrategyUtil.setStrategyPrice(strategyPrice,acquisitionBillingModeReply); // 时段设置 StrategyUtil.setTime(accountingStrategyDetails,acquisitionBillingModeReply); TAccountingStrategyDetail accountingStrategyDetail = accountingStrategyDetailClient.getDetailByCode(deviceId).getData(); acquisitionBillingModeReply.setBilling_model_code(accountingStrategyDetail.getId().toString()); acquisitionBillingModeReply.setCharging_pile_code(deviceId); acquisitionBillingModeReply.setLoss_ratio(BigDecimal.ZERO); BeanUtils.copyProperties(acquisitionBillingModeReply,setupBillingModel); System.err.println(setupBillingModel); String message = iotMessageProduce.sendMessage(setupBillingModel.getCharging_pile_code(), ServiceIdMenu.SETUP_BILLING_MODEL.getKey(),messageUtil.setupBillingModel(setupBillingModel)); return R.ok(message); } @ApiOperation(value = "远程重启",tags = {"硬件接口"}) @PostMapping(value = "/platformRestart") public R platformRestart(String deviceId) { // 远程重启 PlatformRestart platformRestart = new PlatformRestart(); platformRestart.setCharging_pile_code("3401231001200202"); platformRestart.setCharging_pile_code(deviceId); platformRestart.setOperate(2); String message = iotMessageProduce.sendMessage(platformRestart.getCharging_pile_code(), ServiceIdMenu.PLATFORM_RESTART.getKey(),messageUtil.platformRestart(platformRestart)); return R.ok(message); ruoyi-service/ruoyi-integration/src/main/resources/bootstrap.yml
@@ -1,3 +1,7 @@ server: port: 9700 tomcat: basedir: /data/tomcat # Spring spring: application: @@ -9,6 +13,14 @@ profiles: # 环境配置 active: dev --- spring: cloud: stream: rocketmq: binder: name-server: 127.0.0.1:9876 --- spring: config: @@ -37,9 +49,7 @@ # 共享配置 shared-configs: - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} --- seata: enabled: true application-id: ${spring.application.name} @@ -52,36 +62,57 @@ config: type: nacos nacos: # 开发环境 server-addr: 192.168.110.169:8848 namespace: b5290bc2-e3aa-4988-8a7d-9c07e4e073cb group: DEFAULT_GROUP data-id: seata-server.properties username: nacos password: nacos # 生产环境 # server-addr: 192.168.0.137:8848,192.168.0.123:8848 # namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a # group: DEFAULT_GROUP # data-id: seata-server.properties # username: nacos # password: nacos registry: type: nacos nacos: application: seata-server # 开发环境 server-addr: 192.168.110.169:8848 namespace: b5290bc2-e3aa-4988-8a7d-9c07e4e073cb group: DEFAULT_GROUP username: nacos password: nacos # 生产环境 # server-addr: 192.168.0.137:8848,192.168.0.123:8848 # namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a # group: DEFAULT_GROUP # username: nacos # password: nacos cloud: nacos: discovery: # 开发环境 server-addr: 192.168.110.169:8848 # nacos注册中心地址 namespace: b5290bc2-e3aa-4988-8a7d-9c07e4e073cb # 命名空间 group: DEFAULT_GROUP application: seata-server #Nacos 中 Seata 名称 username: nacos password: nacos # 生产环境 # server-addr: 192.168.0.137:8848,192.168.0.123:8848 # namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a # group: DEFAULT_GROUP # application: seata-server #Nacos 中 Seata 名称 # username: nacos # password: nacos sentinel: transport: dashboard: 127.0.0.1:8080 # Sentinel控制台地址 eager: true --- spring: config: @@ -91,14 +122,18 @@ nacos: discovery: # 服务注册地址 server-addr: 127.0.0.1:8848 server-addr: 192.168.0.137:8848,192.168.0.123:8848 service: ${spring.application.name} group: DEFAULT_GROUP namespace: 3452d750-b08d-4485-a1e9-4fb0548f1fc2 namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a username: nacos password: nacos config: # 配置中心地址 server-addr: 127.0.0.1:8848 namespace: 3452d750-b08d-4485-a1e9-4fb0548f1fc2 server-addr: 192.168.0.137:8848,192.168.0.123:8848 namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a username: nacos password: nacos group: DEFAULT_GROUP name: ${spring.application.name} # 配置文件格式 ruoyi-service/ruoyi-order/pom.xml
@@ -15,6 +15,17 @@ </description> <dependencies> <!--网易邮件--> <dependency> <groupId>javax.mail</groupId> <artifactId>javax.mail-api</artifactId> <version>1.6.2</version> </dependency> <dependency> <groupId>com.sun.mail</groupId> <artifactId>jakarta.mail</artifactId> <version>1.6.5</version> </dependency> <!-- ruoyi-modules-other-api --> <dependency> <groupId>com.ruoyi</groupId> ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TOrderInvoiceController.java
@@ -20,18 +20,22 @@ import com.ruoyi.order.service.TOrderInvoiceService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.compress.utils.IOUtils; import org.apache.poi.ss.usermodel.Workbook; import org.springframework.beans.BeanUtils; import org.springframework.web.bind.annotation.*; import javax.activation.DataHandler; import javax.activation.FileDataSource; import javax.annotation.Resource; import javax.mail.*; import javax.mail.internet.*; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.*; import java.net.URL; import java.net.URLEncoder; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.*; /** * <p> @@ -72,6 +76,100 @@ TOrderInvoice orderInvoice = orderInvoiceService.getById(id); orderInvoice.setInvoiceUrl(invoiceUrl); orderInvoiceService.updateById(orderInvoice); // 发送邮箱 // 收件人电子邮箱,TODO 换成自己的收件箱 String to = orderInvoice.getMailbox(); // 发件人电子邮箱,TODO 换成自己的发件箱 String from = "13281306557@163.com"; // 指定发送邮件的主机为 String host = "smtp.163.com"; // 获取系统属性 Properties properties = new Properties(); // 设置邮件服务器 properties.setProperty("mail.smtp.host", host); // 邮件发送协议 properties.setProperty("mail.transport.protocol", "smtp"); //是否启用调试模式(启用调试模式可打印客户端与服务器交互过程时一问一答的响应消息) properties.setProperty("mail.debug","true"); properties.setProperty("mail.smtp.auth", "true"); // 获取默认session对象 Session session = Session.getDefaultInstance(properties,new Authenticator(){ @Override public PasswordAuthentication getPasswordAuthentication() { //发件人邮件用户名、授权码,换成自己的发件箱及授权码 return new PasswordAuthentication("13281306557@163.com", "NUSdxDQqadYvVek2"); } }); try{ // 创建默认的 MimeMessage 对象 MimeMessage message = new MimeMessage(session); // Set From,设置发件人 InternetAddress fromMail = new InternetAddress(from); //设置发件人名称,TODO 换成自己的发件箱 fromMail.setPersonal(MimeUtility.encodeText("明星电力<13281306557@163.com>")); message.setFrom(fromMail); // Set To: 设置收件人 InternetAddress toMail = new InternetAddress(to); // TODO 换成自己的收件箱 InternetAddress toMail2 = new InternetAddress(to); //发多个邮箱 Address[] allRecipients = {toMail, toMail2}; message.setRecipients(Message.RecipientType.TO, allRecipients); // Set Subject: 邮件主体 message.setSubject("明星电力"); // 设置消息体 message.setSentDate(new Date()); // 指定为混合关系 MimeMultipart msgMultipart = new MimeMultipart("mixed"); message.setContent(msgMultipart); // 邮件信息组装 //组装的顺序非常重要,一定要先组装文本域,再组装文件 MimeBodyPart htmlPart = new MimeBodyPart(); // 组装内容 htmlPart.setContent("This is message content", "text/html;charset=UTF-8"); msgMultipart.addBodyPart(htmlPart); // 组装附件 MimeBodyPart filePart = new MimeBodyPart(); String imageUrl = invoiceUrl; try { // 下载数据 URL url = new URL(imageUrl); InputStream inputStream = url.openStream(); byte[] imageBytes = IOUtils.toByteArray(inputStream); // 创建临时文件 File tempFile = File.createTempFile("tempImage", ".png"); try (FileOutputStream fos = new FileOutputStream(tempFile)) { fos.write(imageBytes); } // 创建 FileDataSource FileDataSource fileDataSource = new FileDataSource(tempFile); System.out.println("FileDataSource created: " + fileDataSource.getName()); // 如果需要,可以使用 DataHandler 进行进一步处理 DataHandler dh = new DataHandler(fileDataSource); // 清理:删除临时文件(如果不再需要) tempFile.deleteOnExit(); // 可根据需要保留或删除 filePart.setDataHandler(dh); // 附件区别内嵌内容的一个特点是有文件名,为防止中文乱码要编码 filePart.setFileName(MimeUtility.encodeText(dh.getName())); msgMultipart.addBodyPart(filePart); message.saveChanges(); //发送 //Transport.send(message, message.getAllRecipients()); Transport.send(message); System.out.println("发送成功"); } catch (Exception e) { e.printStackTrace(); } }catch (MessagingException | UnsupportedEncodingException mex) { mex.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return AjaxResult.success(); } ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/filter/AuthFilter.java
@@ -11,6 +11,7 @@ import org.apache.logging.log4j.core.config.Order; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java
@@ -70,6 +70,7 @@ import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; import javax.annotation.Resource; @@ -650,7 +651,7 @@ model.setOut_trade_no(chargingOrder.getCode()); model.setOut_refund_no(chargingOrderRefund.getRefundCode()); model.setReason("充电失败,取消充电订单"); model.setNotify_url("http://221.182.45.100:9000/order/t-charging-order/chargingOrderStartupFailureWxRefund"); model.setNotify_url("/order/t-charging-order/chargingOrderStartupFailureWxRefund"); WxPaymentRefundModel.RefundAmount amount = new WxPaymentRefundModel.RefundAmount(); amount.setRefund(rechargeAmount.multiply(new BigDecimal(100)).intValue()); amount.setTotal(rechargeAmount.multiply(new BigDecimal(100)).intValue()); ruoyi-service/ruoyi-order/src/main/resources/bootstrap.yml
@@ -1,3 +1,7 @@ server: port: 9400 tomcat: basedir: /data/tomcat # Spring spring: application: @@ -37,9 +41,7 @@ # 共享配置 shared-configs: - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} --- seata: enabled: true application-id: ${spring.application.name} @@ -52,36 +54,57 @@ config: type: nacos nacos: # 开发环境 server-addr: 192.168.110.169:8848 namespace: b5290bc2-e3aa-4988-8a7d-9c07e4e073cb group: DEFAULT_GROUP data-id: seata-server.properties username: nacos password: nacos # 生产环境 # server-addr: 192.168.0.137:8848,192.168.0.123:8848 # namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a # group: DEFAULT_GROUP # data-id: seata-server.properties # username: nacos # password: nacos registry: type: nacos nacos: application: seata-server # 开发环境 server-addr: 192.168.110.169:8848 namespace: b5290bc2-e3aa-4988-8a7d-9c07e4e073cb group: DEFAULT_GROUP username: nacos password: nacos # 生产环境 # server-addr: 192.168.0.137:8848,192.168.0.123:8848 # namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a # group: DEFAULT_GROUP # username: nacos # password: nacos cloud: nacos: discovery: # 开发环境 server-addr: 192.168.110.169:8848 # nacos注册中心地址 namespace: b5290bc2-e3aa-4988-8a7d-9c07e4e073cb # 命名空间 group: DEFAULT_GROUP application: seata-server #Nacos 中 Seata 名称 username: nacos password: nacos # 生产环境 # server-addr: 192.168.0.137:8848,192.168.0.123:8848 # namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a # group: DEFAULT_GROUP # application: seata-server #Nacos 中 Seata 名称 # username: nacos # password: nacos sentinel: transport: dashboard: 127.0.0.1:8080 # Sentinel控制台地址 eager: true --- spring: config: @@ -91,14 +114,18 @@ nacos: discovery: # 服务注册地址 server-addr: 127.0.0.1:8848 server-addr: 192.168.0.137:8848,192.168.0.123:8848 service: ${spring.application.name} group: DEFAULT_GROUP namespace: 3452d750-b08d-4485-a1e9-4fb0548f1fc2 namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a username: nacos password: nacos config: # 配置中心地址 server-addr: 127.0.0.1:8848 namespace: 3452d750-b08d-4485-a1e9-4fb0548f1fc2 server-addr: 192.168.0.137:8848,192.168.0.123:8848 namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a username: nacos password: nacos group: DEFAULT_GROUP name: ${spring.application.name} # 配置文件格式 ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/filter/AuthFilter.java
@@ -11,6 +11,7 @@ import org.apache.logging.log4j.core.config.Order; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TAdvertisingServiceImpl.java
@@ -37,6 +37,11 @@ } else { tAdvertising.setStartState(2); } if (tAdvertising.getStatus() == 0 ){ // 未上架 tAdvertising.setStartState(3); } } pageInfo.setRecords(list); return pageInfo; ruoyi-service/ruoyi-other/src/main/resources/bootstrap.yml
@@ -1,3 +1,7 @@ server: port: 9600 tomcat: basedir: /data/tomcat # Spring spring: application: @@ -50,36 +54,57 @@ config: type: nacos nacos: # 开发环境 server-addr: 192.168.110.169:8848 namespace: b5290bc2-e3aa-4988-8a7d-9c07e4e073cb group: DEFAULT_GROUP data-id: seata-server.properties username: nacos password: nacos # 生产环境 # server-addr: 192.168.0.137:8848,192.168.0.123:8848 # namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a # group: DEFAULT_GROUP # data-id: seata-server.properties # username: nacos # password: nacos registry: type: nacos nacos: application: seata-server # 开发环境 server-addr: 192.168.110.169:8848 namespace: b5290bc2-e3aa-4988-8a7d-9c07e4e073cb group: DEFAULT_GROUP username: nacos password: nacos # 生产环境 # server-addr: 192.168.0.137:8848,192.168.0.123:8848 # namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a # group: DEFAULT_GROUP # username: nacos # password: nacos cloud: nacos: discovery: # 开发环境 server-addr: 192.168.110.169:8848 # nacos注册中心地址 namespace: b5290bc2-e3aa-4988-8a7d-9c07e4e073cb # 命名空间 group: DEFAULT_GROUP application: seata-server #Nacos 中 Seata 名称 username: nacos password: nacos # 生产环境 # server-addr: 192.168.0.137:8848,192.168.0.123:8848 # namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a # group: DEFAULT_GROUP # application: seata-server #Nacos 中 Seata 名称 # username: nacos # password: nacos sentinel: transport: dashboard: 127.0.0.1:8080 # Sentinel控制台地址 eager: true --- spring: config: @@ -89,14 +114,18 @@ nacos: discovery: # 服务注册地址 server-addr: 127.0.0.1:8848 server-addr: 192.168.0.137:8848,192.168.0.123:8848 service: ${spring.application.name} group: DEFAULT_GROUP namespace: 3452d750-b08d-4485-a1e9-4fb0548f1fc2 namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a username: nacos password: nacos config: # 配置中心地址 server-addr: 127.0.0.1:8848 namespace: 3452d750-b08d-4485-a1e9-4fb0548f1fc2 server-addr: 192.168.0.137:8848,192.168.0.123:8848 namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a username: nacos password: nacos group: DEFAULT_GROUP name: ${spring.application.name} # 配置文件格式 ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/ali/v2/AppletPayUtil.java
@@ -207,12 +207,12 @@ alipayConfig.setSignType(SignType.RSA2.getType()); //判断加签方式 String signType = aliProperties.getSignType(); if(SignType.CERT.getType().equals(signType)){ if(SignType.SECRET_KEY.getType().equals(signType)){ alipayConfig.setPrivateKey(aliProperties.getPrivateKey()); alipayConfig.setAlipayPublicKey(aliProperties.getAlipayPublicKey()); return alipayConfig; } if(SignType.SECRET_KEY.getType().equals(signType)){ if(SignType.CERT.getType().equals(signType)){ alipayConfig.setAppCertPath(aliProperties.getAppCertPath()); alipayConfig.setAlipayPublicCertPath(aliProperties.getAlipayPublicCertPath()); alipayConfig.setRootCertPath(aliProperties.getRootCertPath()); ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/wx/model/V3.java
@@ -5,6 +5,7 @@ import org.apache.poi.util.IOUtils; import java.io.ByteArrayInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; @@ -54,18 +55,23 @@ public InputStream getPrivateKeyStream() { // 需要证书释放 byte[] certData; InputStream certStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(this.privateKeyPath); // InputStream certStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(this.privateKeyPath); InputStream certStream = null; try { certStream = new FileInputStream(this.privateKeyPath); certData = IOUtils.toByteArray(certStream); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException("私钥文件未找到"); }finally { if(null != certStream){ try { certStream.close(); } catch (IOException e) { log.error("私钥流关闭异常"); } } } return new ByteArrayInputStream(certData); } } ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/wx/model/WeixinProperties.java
@@ -103,4 +103,12 @@ public void setMchId(String mchId) { this.mchId = mchId; } public String getCallBackUrl() { return callBackUrl; } public void setCallBackUrl(String callBackUrl) { this.callBackUrl = callBackUrl; } } ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/wx/utils/WxAbstractPay.java
@@ -1,5 +1,7 @@ package com.ruoyi.payment.wx.utils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.fasterxml.jackson.core.type.TypeReference; import com.ruoyi.common.core.utils.WebUtils; import com.ruoyi.payment.wx.model.WxCloseOrderModel; @@ -69,7 +71,7 @@ */ protected String buildBaseParam(WxPaymentInfoModel requestBody, String notifyUrl) { // 封装基础数据 // requestBody.setNotify_url(notifyUrl); requestBody.setNotify_url(notifyUrl + requestBody.getNotify_url()); String reqBody = WxJsonUtils.toJsonString(requestBody); return reqBody; } @@ -199,9 +201,46 @@ url , socketTimeout , connectTimeout); String repBody = result(httpClient, httpGet); NotifyV3PayDecodeRespBody body = WxJsonUtils.parseObject(repBody, NotifyV3PayDecodeRespBody.class); CloseableHttpResponse response = null; try { response = httpClient.execute(httpGet); int statusCode = response.getStatusLine().getStatusCode(); String respBodyStr = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8); if (WxUtils.getLogger().isDebugEnabled()) { WxUtils.debug("请求成功:{}", respBodyStr); } if(404 == statusCode){ return null; } // 成功相应 if (STATUS_CODE == statusCode || OTHER_STATUS_CODE == statusCode ) { NotifyV3PayDecodeRespBody body = WxJsonUtils.parseObject(respBodyStr, NotifyV3PayDecodeRespBody.class); return body; } else { WxUtils.error("failed,resp code = {},return body = {}", statusCode, respBodyStr); throw new RuntimeException(respBodyStr); } } catch (ConnectTimeoutException e) { e.printStackTrace(); throw new RuntimeException("接口超时"); } catch (SocketTimeoutException e) { e.printStackTrace(); throw new RuntimeException("读取接口数据超时"); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException("接口请求失败,请尝试检查网络环境或请求接口是否能正常访问"); } finally { // 关闭响应 try { if (response != null) { //关闭结果集 response.getEntity().getContent().close(); response.close(); } } catch (IOException e) { throw new RuntimeException("关闭流异常"); } } } /** @@ -251,7 +290,6 @@ Map<String, Object> body = WxJsonUtils.parseObject(repBody, Map.class); return body; } /** * 请求结果 ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/wx/utils/WxV3Pay.java
@@ -191,7 +191,7 @@ */ @Override public Map<String, Object> refund(WxPaymentRefundModel refundModel) { // refundModel.setNotify_url(this.config.getV3().getNotifyRefundUrl()); refundModel.setNotify_url(this.config.getV3().getNotifyRefundUrl() + refundModel.getNotify_url()); return refund(this.httpClient, "/v3/refund/domestic/refunds", this.config.getHttpReadTimeoutMs(), this.config.getHttpConnectTimeoutMs(), refundModel); } ruoyi-service/ruoyi-payment/src/main/resources/bootstrap.yml
@@ -1,3 +1,7 @@ server: port: 9500 tomcat: basedir: /data/tomcat # Spring spring: application: @@ -37,10 +41,7 @@ # 共享配置 shared-configs: - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} --- seata: enabled: true application-id: ${spring.application.name} @@ -53,36 +54,57 @@ config: type: nacos nacos: # 开发环境 server-addr: 192.168.110.169:8848 namespace: b5290bc2-e3aa-4988-8a7d-9c07e4e073cb group: DEFAULT_GROUP data-id: seata-server.properties username: nacos password: nacos # 生产环境 # server-addr: 192.168.0.137:8848,192.168.0.123:8848 # namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a # group: DEFAULT_GROUP # data-id: seata-server.properties # username: nacos # password: nacos registry: type: nacos nacos: application: seata-server # 开发环境 server-addr: 192.168.110.169:8848 namespace: b5290bc2-e3aa-4988-8a7d-9c07e4e073cb group: DEFAULT_GROUP username: nacos password: nacos # 生产环境 # server-addr: 192.168.0.137:8848,192.168.0.123:8848 # namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a # group: DEFAULT_GROUP # username: nacos # password: nacos cloud: nacos: discovery: # 开发环境 server-addr: 192.168.110.169:8848 # nacos注册中心地址 namespace: b5290bc2-e3aa-4988-8a7d-9c07e4e073cb # 命名空间 group: DEFAULT_GROUP application: seata-server #Nacos 中 Seata 名称 username: nacos password: nacos # 生产环境 # server-addr: 192.168.0.137:8848,192.168.0.123:8848 # namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a # group: DEFAULT_GROUP # application: seata-server #Nacos 中 Seata 名称 # username: nacos # password: nacos sentinel: transport: dashboard: 127.0.0.1:8080 # Sentinel控制台地址 eager: true --- spring: config: @@ -92,14 +114,18 @@ nacos: discovery: # 服务注册地址 server-addr: 127.0.0.1:8848 server-addr: 192.168.0.137:8848,192.168.0.123:8848 service: ${spring.application.name} group: DEFAULT_GROUP namespace: 3452d750-b08d-4485-a1e9-4fb0548f1fc2 namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a username: nacos password: nacos config: # 配置中心地址 server-addr: 127.0.0.1:8848 namespace: 3452d750-b08d-4485-a1e9-4fb0548f1fc2 server-addr: 192.168.0.137:8848,192.168.0.123:8848 namespace: c6cf40b5-44e8-43f9-be61-8d10fa830e2a username: nacos password: nacos group: DEFAULT_GROUP name: ${spring.application.name} # 配置文件格式