修复相关
This commit is contained in:
parent
1226a2880e
commit
cf0763fb04
@ -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<RepairOrderInfo> {
|
||||
* @param orderId 订单主键
|
||||
* @return
|
||||
*/
|
||||
Map<String,Object> payTransactions(String orderId);
|
||||
Map<String,Object> payTransactions(String orderId) throws IOException, NoSuchAlgorithmException, SignatureException, InvalidKeyException;
|
||||
Map<String,Object> payTransactionsCode(String orderId) throws IOException, NoSuchAlgorithmException, SignatureException, InvalidKeyException;
|
||||
|
||||
/**
|
||||
* 获得已经评价的订单
|
||||
|
@ -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<RepairOrderInfoMappe
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String,Object> payTransactions(String orderId){
|
||||
public Map<String,Object> 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<RepairOrderInfoMappe
|
||||
sceneInfoMap.put("device_id", "127.0.0.1");
|
||||
// 除H5与JSAPI有特殊参数外,其他的支付方式都一样
|
||||
Map<String, Object> 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<String, Object> resMap = JSONObject.parseObject(resStr);
|
||||
//Map<String, Object> signMap = paySignMsg(resMap.get("prepay_id").toString(), wechatPayConfig.getAppId(),null);
|
||||
return resMap;
|
||||
Map<String, Object> signMap = paySignMsg(resMap.get("prepay_id").toString(), wechatPayConfig.getRepairAppId(),null);
|
||||
return signMap;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 支付吊起接口
|
||||
* @param orderId 订单主键
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Map<String,Object> payTransactionsCode(String orderId){
|
||||
RepairOrderInfo orderInfo = this.getById(orderId);
|
||||
// 统一参数封装
|
||||
Map<String, Object> 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<String, Object> 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<Map<String, Object>>(){});
|
||||
}
|
||||
/**
|
||||
* 获得已经评价的订单
|
||||
*
|
||||
@ -283,6 +309,49 @@ public class RepairOrderInfoServiceImpl extends ServiceImpl<RepairOrderInfoMappe
|
||||
}));
|
||||
}
|
||||
|
||||
private Map<String, Object> 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<String, Object> 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());
|
||||
}
|
||||
/**
|
||||
* 统计未入账和已入账(最简版)
|
||||
*
|
||||
|
@ -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<Map<String, Object>> payTransactions(String orderId){
|
||||
public CommonResult<Map<String, Object>> payTransactions(String orderId) throws IOException, NoSuchAlgorithmException, SignatureException, InvalidKeyException {
|
||||
Map<String, Object> res = repairOrderInfoService.payTransactions(orderId);
|
||||
return success(res);
|
||||
}
|
||||
|
||||
@GetMapping("/toPayCode")
|
||||
@TenantIgnore
|
||||
public CommonResult<Map<String, Object>> toPayCode(String orderId) throws IOException, NoSuchAlgorithmException, SignatureException, InvalidKeyException {
|
||||
Map<String, Object> res = repairOrderInfoService.payTransactionsCode(orderId);
|
||||
return success(res);
|
||||
}
|
||||
private final ReentrantLock lock = new ReentrantLock();
|
||||
@PostMapping("/payNotify")
|
||||
@TenantIgnore
|
||||
|
@ -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<Map<String, Object>> payTransactions(String orderId){
|
||||
public CommonResult<Map<String, Object>> payTransactions(String orderId) throws IOException, NoSuchAlgorithmException, SignatureException, InvalidKeyException {
|
||||
Map<String, Object> res = repairOrderInfoService.payTransactions(orderId);
|
||||
return success(res);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -278,6 +278,7 @@ public class SysLoginController {
|
||||
* @return 结果
|
||||
*/
|
||||
@PostMapping("/driverLogin")
|
||||
@TenantIgnore
|
||||
public CommonResult driverLogin(@RequestBody LoginBody loginBody) throws Exception {
|
||||
// 生成令牌
|
||||
AuthLoginReqVO authLoginReqVO = new AuthLoginReqVO();
|
||||
|
@ -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);
|
||||
|
@ -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()
|
||||
// 蓝安救援
|
||||
|
@ -112,5 +112,6 @@ public class AdminUserDO extends TenantBaseDO {
|
||||
private String openId;
|
||||
|
||||
private Long inviteId;
|
||||
private String repairOpenId;
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user