diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/order/service/RepairOrderInfoService.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/order/service/RepairOrderInfoService.java index 9ba56c44..a9ba121f 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/order/service/RepairOrderInfoService.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/order/service/RepairOrderInfoService.java @@ -10,6 +10,10 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; +import java.io.IOException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.security.SignatureException; import java.util.Map; /** @@ -116,7 +120,8 @@ public interface RepairOrderInfoService extends IService { * @param orderId 订单主键 * @return */ - Map payTransactions(String orderId); + Map payTransactions(String orderId) throws IOException, NoSuchAlgorithmException, SignatureException, InvalidKeyException; + Map payTransactionsCode(String orderId) throws IOException, NoSuchAlgorithmException, SignatureException, InvalidKeyException; /** * 获得已经评价的订单 diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/order/service/impl/RepairOrderInfoServiceImpl.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/order/service/impl/RepairOrderInfoServiceImpl.java index 8f5ce6df..c0c4ea72 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/order/service/impl/RepairOrderInfoServiceImpl.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/order/service/impl/RepairOrderInfoServiceImpl.java @@ -32,6 +32,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.wechat.pay.contrib.apache.httpclient.util.PemUtil; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; @@ -40,9 +42,7 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.io.IOException; import java.math.BigDecimal; -import java.security.InvalidKeyException; -import java.security.NoSuchAlgorithmException; -import java.security.SignatureException; +import java.security.*; import java.time.LocalDateTime; import java.util.*; import java.util.stream.Collectors; @@ -229,7 +229,7 @@ public class RepairOrderInfoServiceImpl extends ServiceImpl payTransactions(String orderId){ + public Map payTransactions(String orderId) throws IOException, NoSuchAlgorithmException, SignatureException, InvalidKeyException { RepairOrderInfo orderInfo = this.getById(orderId); AdminUserDO user = userService.getUser(orderInfo.getUserId()); @@ -256,17 +256,43 @@ public class RepairOrderInfoServiceImpl extends ServiceImpl payerMap = new HashMap<>(4); - payerMap.put("openid", user.getOpenId()); + payerMap.put("openid", user.getRepairOpenId()); params.put("payer", payerMap); params.put("scene_info", sceneInfoMap); String paramsStr = JSON.toJSONString(params); String resStr = wechatPayRequest.wechatHttpPost("https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi",paramsStr); Map resMap = JSONObject.parseObject(resStr); - //Map signMap = paySignMsg(resMap.get("prepay_id").toString(), wechatPayConfig.getAppId(),null); - return resMap; + Map signMap = paySignMsg(resMap.get("prepay_id").toString(), wechatPayConfig.getRepairAppId(),null); + return signMap; } + + /** + * 支付吊起接口 + * @param orderId 订单主键 + * @return + */ + @Override + public Map payTransactionsCode(String orderId){ + RepairOrderInfo orderInfo = this.getById(orderId); + // 统一参数封装 + Map params = new HashMap<>(8); + params.put("appid", wechatPayConfig.getAppId()); + params.put("mchid", wechatPayConfig.getMchId()); + params.put("description", orderInfo.getPayRemark()); + params.put("out_trade_no", orderInfo.getOrderNo()); + params.put("notify_url", wechatPayConfig.getRepairNotifyUrl()); + Map amountMap = new HashMap<>(4); + // 金额单位为分 + amountMap.put("total", orderInfo.getPayMoney().multiply(BigDecimal.valueOf(100L)).intValue()); + //人民币 + amountMap.put("currency", "CNY"); + params.put("amount", amountMap); + String paramsStr = JSON.toJSONString(params); + String resStr = wechatPayRequest.wechatHttpPost("https://api.mch.weixin.qq.com/v3/pay/transactions/native",paramsStr); + return JSONObject.parseObject(resStr, new TypeReference>(){}); + } /** * 获得已经评价的订单 * @@ -283,6 +309,49 @@ public class RepairOrderInfoServiceImpl extends ServiceImpl paySignMsg(String prepayId,String appId,String privateKeyStr) throws IOException, NoSuchAlgorithmException, InvalidKeyException, SignatureException { + long timeMillis = System.currentTimeMillis(); + String timeStamp = timeMillis/1000+""; + String nonceStr = timeMillis+""; + String packageStr = "prepay_id="+prepayId; + // 公共参数 + Map resMap = new HashMap<>(); + resMap.put("nonceStr",nonceStr); + resMap.put("timeStamp",timeStamp); + resMap.put("appId",appId); + resMap.put("package", packageStr); + // 使用字段appId、timeStamp、nonceStr、package进行签名 + //从下往上依次生成 + String message = buildMessage(appId, timeStamp, nonceStr, packageStr); + //签名 + String paySign = sign(message.getBytes("utf-8"), privateKeyStr); + resMap.put("paySign", paySign); + resMap.put("signType", "RSA"); + return resMap; + } + + String buildMessage(String appId, String timestamp,String nonceStr,String prepay_id) { + + return appId + "\n" + + timestamp + "\n" + + nonceStr + "\n" + + prepay_id + "\n"; + } + String sign(byte[] message,String privateKeyStr) throws NoSuchAlgorithmException, SignatureException, IOException, InvalidKeyException { + //签名方式 + Signature sign = Signature.getInstance("SHA256withRSA"); + //私钥,通过MyPrivateKey来获取,这是个静态类可以接调用方法 ,需要的是_key.pem文件的绝对路径配上文件名 + PrivateKey privateKey =null; + if (StringUtils.isNotEmpty(privateKeyStr)){ + privateKey = PemUtil.loadPrivateKey(privateKeyStr); + }else { + privateKey = wechatPayConfig.getPrivateKey(wechatPayConfig.getKeyPemPath()); + } + + sign.initSign(privateKey); + sign.update(message); + return Base64.getEncoder().encodeToString(sign.sign()); + } /** * 统计未入账和已入账(最简版) * diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/app/apy/RepairPayApi.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/app/apy/RepairPayApi.java index ca280176..2e106d71 100644 --- a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/app/apy/RepairPayApi.java +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/app/apy/RepairPayApi.java @@ -12,7 +12,11 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.security.SignatureException; import java.util.HashMap; import java.util.Map; import java.util.concurrent.locks.ReentrantLock; @@ -35,10 +39,17 @@ public class RepairPayApi { */ @GetMapping("/toPay") @TenantIgnore - public CommonResult> payTransactions(String orderId){ + public CommonResult> payTransactions(String orderId) throws IOException, NoSuchAlgorithmException, SignatureException, InvalidKeyException { Map res = repairOrderInfoService.payTransactions(orderId); return success(res); } + + @GetMapping("/toPayCode") + @TenantIgnore + public CommonResult> toPayCode(String orderId) throws IOException, NoSuchAlgorithmException, SignatureException, InvalidKeyException { + Map res = repairOrderInfoService.payTransactionsCode(orderId); + return success(res); + } private final ReentrantLock lock = new ReentrantLock(); @PostMapping("/payNotify") @TenantIgnore diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/project/controller/admin/RepairPayController.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/project/controller/admin/RepairPayController.java index dd250662..47128eba 100644 --- a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/project/controller/admin/RepairPayController.java +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/project/controller/admin/RepairPayController.java @@ -9,6 +9,10 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; +import java.io.IOException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.security.SignatureException; import java.util.Map; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -27,7 +31,7 @@ public class RepairPayController { * @return */ @GetMapping("/toPay") - public CommonResult> payTransactions(String orderId){ + public CommonResult> payTransactions(String orderId) throws IOException, NoSuchAlgorithmException, SignatureException, InvalidKeyException { Map res = repairOrderInfoService.payTransactions(orderId); return success(res); } diff --git a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/app/controller/admin/AnnouncementSocket.java b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/app/controller/admin/AnnouncementSocket.java index 4a705872..d2dbdf9b 100644 --- a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/app/controller/admin/AnnouncementSocket.java +++ b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/app/controller/admin/AnnouncementSocket.java @@ -17,7 +17,7 @@ import java.util.concurrent.ConcurrentHashMap; * @Date: 2023/7/9 10:21 * @Description : */ -@ServerEndpoint(value = "/admin-api/websocket/announcement/{userId}") +@ServerEndpoint(value = "/websocket/announcement/{userId}") @Component public class AnnouncementSocket { private final static Logger log = LoggerFactory.getLogger(AnnouncementSocket.class); diff --git a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/app/controller/admin/SysLoginController.java b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/app/controller/admin/SysLoginController.java index 8bbd839a..566588c6 100644 --- a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/app/controller/admin/SysLoginController.java +++ b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/app/controller/admin/SysLoginController.java @@ -278,6 +278,7 @@ public class SysLoginController { * @return 结果 */ @PostMapping("/driverLogin") + @TenantIgnore public CommonResult driverLogin(@RequestBody LoginBody loginBody) throws Exception { // 生成令牌 AuthLoginReqVO authLoginReqVO = new AuthLoginReqVO(); diff --git a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/app/controller/admin/UserAnnouncementSocket.java b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/app/controller/admin/UserAnnouncementSocket.java index 2803b336..84a9ac98 100644 --- a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/app/controller/admin/UserAnnouncementSocket.java +++ b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/app/controller/admin/UserAnnouncementSocket.java @@ -19,7 +19,7 @@ import java.util.concurrent.ConcurrentHashMap; * @Date: 2023/7/9 10:21 * @Description : */ -@ServerEndpoint(value = "/admin-api/websocket/userAnnouncement/{userId}") +@ServerEndpoint(value = "/websocket/userAnnouncement/{userId}") @Component public class UserAnnouncementSocket { private final static Logger log = LoggerFactory.getLogger(UserAnnouncementSocket.class); diff --git a/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/config/YudaoWebSecurityConfigurerAdapter.java b/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/config/YudaoWebSecurityConfigurerAdapter.java index fd51558e..e20ff358 100644 --- a/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/config/YudaoWebSecurityConfigurerAdapter.java +++ b/yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/config/YudaoWebSecurityConfigurerAdapter.java @@ -148,6 +148,7 @@ public class YudaoWebSecurityConfigurerAdapter { .antMatchers("/userClient/pay/**").permitAll() .antMatchers("/userClient/weChat/**","/userClient/repair/wxLogin").permitAll() .antMatchers("/admin-api/websocket/**").permitAll() + .antMatchers("/websocket/**").permitAll() // 小程序首页 .antMatchers("/admin-api/system/notice/listWx","/admin-api/system/swiper/listWx","/admin-api/system/shopconfig/listWx").permitAll() // 蓝安救援 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/user/AdminUserDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/user/AdminUserDO.java index 073dbb6b..30453969 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/user/AdminUserDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/user/AdminUserDO.java @@ -112,5 +112,6 @@ public class AdminUserDO extends TenantBaseDO { private String openId; private Long inviteId; + private String repairOpenId; } diff --git a/yudao-server/src/main/resources/application.yaml b/yudao-server/src/main/resources/application.yaml index 20f73e89..c7173248 100644 --- a/yudao-server/src/main/resources/application.yaml +++ b/yudao-server/src/main/resources/application.yaml @@ -3,7 +3,7 @@ spring: name: yudao-server profiles: - active: local + active: prod main: allow-circular-references: true # 允许循环依赖,因为项目是三层架构,无法避免这个情况。 @@ -234,6 +234,7 @@ yudao: - /userClient/repair/wxLogin - /userClient/base/company/page #查询可提供服务的子公司,不需要登录 - /userClient/base/company/get #查询可提供服务的子公司详情,不需要登录 + - /admin-api/rescue/driverLogin websocket: enable: true # websocket的开关 path: /infra/ws # 路径 @@ -290,6 +291,7 @@ yudao: - /userClient/weChat/** - /userClient/** - /admin-api/ueditor/** + - /admin-api/rescue/driverLogin ignore-tables: - system_tenant