Compare commits
10 Commits
bd259281af
...
137ba5e35b
Author | SHA1 | Date |
---|---|---|
|
137ba5e35b | |
|
22a98befb6 | |
|
949c63432d | |
|
dc9da08c13 | |
|
23149889ac | |
|
afcdc8a749 | |
|
d0cfd90f2e | |
|
7bc4e7ef78 | |
|
d17e6c6cea | |
|
505a028036 |
|
@ -10,6 +10,8 @@ import org.springframework.stereotype.Component;
|
|||
public class WechatPayConfig {
|
||||
/** 应用ID */
|
||||
private String appId;
|
||||
/** 小程序秘钥 */
|
||||
private String appSecret;
|
||||
/** 商户ID */
|
||||
private String mchId;
|
||||
/** 秘钥 */
|
||||
|
@ -18,4 +20,62 @@ public class WechatPayConfig {
|
|||
private String mchSerialNo;
|
||||
/** 证书路径 */
|
||||
private String privateKeyPath;
|
||||
/** 支付回调地址 */
|
||||
private String payNoticeUrl;
|
||||
|
||||
public String getAppId() {
|
||||
return appId;
|
||||
}
|
||||
|
||||
public void setAppId(String appId) {
|
||||
this.appId = appId;
|
||||
}
|
||||
|
||||
public String getAppSecret() {
|
||||
return appSecret;
|
||||
}
|
||||
|
||||
public void setAppSecret(String appSecret) {
|
||||
this.appSecret = appSecret;
|
||||
}
|
||||
|
||||
public String getMchId() {
|
||||
return mchId;
|
||||
}
|
||||
|
||||
public void setMchId(String mchId) {
|
||||
this.mchId = mchId;
|
||||
}
|
||||
|
||||
public String getApiV3Key() {
|
||||
return apiV3Key;
|
||||
}
|
||||
|
||||
public void setApiV3Key(String apiV3Key) {
|
||||
this.apiV3Key = apiV3Key;
|
||||
}
|
||||
|
||||
public String getMchSerialNo() {
|
||||
return mchSerialNo;
|
||||
}
|
||||
|
||||
public void setMchSerialNo(String mchSerialNo) {
|
||||
this.mchSerialNo = mchSerialNo;
|
||||
}
|
||||
|
||||
public String getPrivateKeyPath() {
|
||||
return privateKeyPath;
|
||||
}
|
||||
|
||||
public void setPrivateKeyPath(String privateKeyPath) {
|
||||
this.privateKeyPath = privateKeyPath;
|
||||
}
|
||||
|
||||
public String getPayNoticeUrl() {
|
||||
return payNoticeUrl;
|
||||
}
|
||||
|
||||
public void setPayNoticeUrl(String payNoticeUrl) {
|
||||
this.payNoticeUrl = payNoticeUrl;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,9 @@ public class Constants {
|
|||
|
||||
public static Integer DEFAULT_CARTYPE_ID = -1;
|
||||
|
||||
//默认短信验证码
|
||||
public static String DEFAULT_MESSAGE_CODE = "000000";
|
||||
|
||||
//短信验证码redis存储的前缀
|
||||
public static String MESSAGE_CODE_PREFIX = "code_";
|
||||
|
||||
|
|
|
@ -0,0 +1,114 @@
|
|||
package com.jwl.driver.server.controller;
|
||||
|
||||
import com.jwl.driver.server.config.WechatPayConfig;
|
||||
import com.jwl.driver.server.response.BaseResponse;
|
||||
import com.jwl.driver.server.util.WechatPayUtil;
|
||||
import com.jwl.driver.server.vo.AppletPayVo;
|
||||
import com.wechat.pay.java.core.Config;
|
||||
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
|
||||
import com.wechat.pay.java.core.exception.ServiceException;
|
||||
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
|
||||
import com.wechat.pay.java.service.payments.jsapi.model.*;
|
||||
import com.wechat.pay.java.service.payments.model.Transaction;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 微信支付小程序 接口
|
||||
*/
|
||||
@Api(tags = "小程序支付")
|
||||
@Controller
|
||||
@RequestMapping("/applet/pay")
|
||||
@Slf4j
|
||||
public class AppletPayController {
|
||||
|
||||
@Resource
|
||||
private WechatPayConfig wechatPayConfig;
|
||||
|
||||
//生成预支付订单
|
||||
@ApiOperation("生成预支付订单")
|
||||
@PostMapping("/prepay")
|
||||
public BaseResponse createPrepay(@RequestBody AppletPayVo payDto){
|
||||
// 构建service
|
||||
JsapiServiceExtension service = createService();
|
||||
|
||||
// 请求下单参数
|
||||
PrepayRequest request = new PrepayRequest();
|
||||
Amount amount = new Amount();
|
||||
amount.setTotal(Integer.valueOf((payDto.getMoney()*100)+""));
|
||||
request.setAmount(amount);
|
||||
request.setAppid(wechatPayConfig.getAppId());
|
||||
request.setMchid(wechatPayConfig.getMchId());
|
||||
request.setDescription(payDto.getDescription());
|
||||
request.setNotifyUrl(wechatPayConfig.getPayNoticeUrl());
|
||||
request.setOutTradeNo(payDto.getOutTradeNo());
|
||||
|
||||
Payer payer = new Payer();
|
||||
payer.setOpenid(WechatPayUtil.getOpenId(wechatPayConfig.getAppId(), wechatPayConfig.getAppSecret(), payDto.getCode()));
|
||||
// 调用下单方法,得到应答
|
||||
PrepayWithRequestPaymentResponse response = service.prepayWithRequestPayment(request);
|
||||
// 使用微信扫描 code_url 对应的二维码,即可体验Native支付
|
||||
// log.info(response);
|
||||
return BaseResponse.success(response);
|
||||
|
||||
}
|
||||
|
||||
/** 构建service */
|
||||
private JsapiServiceExtension createService() {
|
||||
Config config =
|
||||
new RSAAutoCertificateConfig.Builder()
|
||||
.merchantId(wechatPayConfig.getMchId())
|
||||
.privateKeyFromPath(wechatPayConfig.getPrivateKeyPath())
|
||||
.merchantSerialNumber(wechatPayConfig.getMchSerialNo())
|
||||
.apiV3Key(wechatPayConfig.getApiV3Key())
|
||||
.build();
|
||||
JsapiServiceExtension service = new JsapiServiceExtension.Builder().config(config).build();
|
||||
|
||||
return service;
|
||||
}
|
||||
|
||||
|
||||
//查询订单接口
|
||||
@ApiOperation("查询支付订单")
|
||||
@PostMapping("/queryOrder")
|
||||
public BaseResponse queryOrder(@RequestBody AppletPayVo payDto){
|
||||
//获取openId
|
||||
QueryOrderByOutTradeNoRequest queryRequest = new QueryOrderByOutTradeNoRequest();
|
||||
queryRequest.setMchid(wechatPayConfig.getMchId());
|
||||
//支付订单id
|
||||
queryRequest.setOutTradeNo(payDto.getOutTradeNo());
|
||||
JsapiServiceExtension service = createService();
|
||||
|
||||
try {
|
||||
Transaction result = service.queryOrderByOutTradeNo(queryRequest);
|
||||
System.out.println(result.getTradeState());
|
||||
return BaseResponse.success(result);
|
||||
} catch (ServiceException e) {
|
||||
// API返回失败, 例如ORDER_NOT_EXISTS
|
||||
System.out.printf("code=[%s], message=[%s]\n", e.getErrorCode(), e.getErrorMessage());
|
||||
System.out.printf("reponse body=[%s]\n", e.getResponseBody());
|
||||
return BaseResponse.fail(e.getErrorMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//关闭订单接口
|
||||
@ApiOperation("关闭支付订单")
|
||||
@PostMapping("/closeOrder")
|
||||
public BaseResponse closeOrder(@RequestBody AppletPayVo payDto){
|
||||
JsapiServiceExtension service = createService();
|
||||
CloseOrderRequest closeRequest = new CloseOrderRequest();
|
||||
closeRequest.setMchid(wechatPayConfig.getMchId());
|
||||
closeRequest.setOutTradeNo(payDto.getOutTradeNo());
|
||||
// 方法没有返回值,意味着成功时API返回204 No Content
|
||||
service.closeOrder(closeRequest);
|
||||
return BaseResponse.success();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
package com.jwl.driver.server.controller;
|
||||
|
||||
import com.jwl.driver.server.config.WechatPayConfig;
|
||||
import com.jwl.driver.server.response.BaseResponse;
|
||||
import com.jwl.driver.server.vo.H5PayVo;
|
||||
import com.wechat.pay.java.core.Config;
|
||||
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
|
||||
import com.wechat.pay.java.core.exception.ServiceException;
|
||||
import com.wechat.pay.java.service.payments.h5.H5Service;
|
||||
import com.wechat.pay.java.service.payments.h5.model.*;
|
||||
import com.wechat.pay.java.service.payments.model.Transaction;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 微信支付小程序 接口
|
||||
*/
|
||||
@Api(tags = "H5支付")
|
||||
@Controller
|
||||
@RequestMapping("/H5/pay")
|
||||
@Slf4j
|
||||
public class H5PayController {
|
||||
|
||||
@Resource
|
||||
private WechatPayConfig wechatPayConfig;
|
||||
|
||||
//生成预支付订单
|
||||
@ApiOperation("生成预支付订单")
|
||||
@PostMapping("/prepay")
|
||||
public BaseResponse createPrepay(@RequestBody H5PayVo payVo){
|
||||
// 构建service
|
||||
H5Service service = createService();
|
||||
|
||||
// 请求下单参数
|
||||
PrepayRequest request = new PrepayRequest();
|
||||
Amount amount = new Amount();
|
||||
amount.setTotal(Integer.valueOf((payVo.getMoney()*100)+""));
|
||||
request.setAmount(amount);
|
||||
request.setAppid(wechatPayConfig.getAppId());
|
||||
request.setMchid(wechatPayConfig.getMchId());
|
||||
request.setDescription(payVo.getDescription());
|
||||
request.setNotifyUrl(wechatPayConfig.getPayNoticeUrl());
|
||||
request.setOutTradeNo(payVo.getOutTradeNo());
|
||||
//场景参数
|
||||
SceneInfo sceneInfo = new SceneInfo();
|
||||
sceneInfo.setPayerClientIp(payVo.getClientIp());
|
||||
|
||||
// 调用下单方法,得到应答
|
||||
PrepayResponse response = service.prepay(request);
|
||||
// 使用微信扫描 code_url 对应的二维码,即可体验Native支付
|
||||
// log.info(response);
|
||||
return BaseResponse.success(response);
|
||||
|
||||
}
|
||||
|
||||
private H5Service createService() {
|
||||
Config config =
|
||||
new RSAAutoCertificateConfig.Builder()
|
||||
.merchantId(wechatPayConfig.getMchId())
|
||||
.privateKeyFromPath(wechatPayConfig.getPrivateKeyPath())
|
||||
.merchantSerialNumber(wechatPayConfig.getMchSerialNo())
|
||||
.apiV3Key(wechatPayConfig.getApiV3Key())
|
||||
.build();
|
||||
H5Service service = new H5Service.Builder().config(config).build();
|
||||
|
||||
return service;
|
||||
}
|
||||
|
||||
|
||||
//查询订单接口
|
||||
@ApiOperation("查询支付订单")
|
||||
@PostMapping("/queryOrder")
|
||||
public BaseResponse queryOrder(@RequestBody H5PayVo payVo){
|
||||
//获取openId
|
||||
QueryOrderByOutTradeNoRequest queryRequest = new QueryOrderByOutTradeNoRequest();
|
||||
queryRequest.setMchid(wechatPayConfig.getMchId());
|
||||
//支付订单id
|
||||
queryRequest.setOutTradeNo(payVo.getOutTradeNo());
|
||||
H5Service service = createService();
|
||||
|
||||
try {
|
||||
Transaction result = service.queryOrderByOutTradeNo(queryRequest);
|
||||
System.out.println(result.getTradeState());
|
||||
return BaseResponse.success(result);
|
||||
} catch (ServiceException e) {
|
||||
// API返回失败, 例如ORDER_NOT_EXISTS
|
||||
System.out.printf("code=[%s], message=[%s]\n", e.getErrorCode(), e.getErrorMessage());
|
||||
System.out.printf("reponse body=[%s]\n", e.getResponseBody());
|
||||
return BaseResponse.fail(e.getErrorMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//关闭订单接口
|
||||
@ApiOperation("关闭支付订单")
|
||||
@PostMapping("/closeOrder")
|
||||
public BaseResponse closeOrder(@RequestBody H5PayVo payVo){
|
||||
H5Service service = createService();
|
||||
CloseOrderRequest closeRequest = new CloseOrderRequest();
|
||||
closeRequest.setMchid(wechatPayConfig.getMchId());
|
||||
closeRequest.setOutTradeNo(payVo.getOutTradeNo());
|
||||
// 方法没有返回值,意味着成功时API返回204 No Content
|
||||
service.closeOrder(closeRequest);
|
||||
return BaseResponse.success();
|
||||
}
|
||||
}
|
|
@ -1,9 +1,25 @@
|
|||
package com.jwl.driver.server.controller;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jwl.driver.server.config.WechatPayConfig;
|
||||
import com.jwl.driver.server.response.BaseResponse;
|
||||
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
|
||||
import com.wechat.pay.java.core.notification.NotificationConfig;
|
||||
import com.wechat.pay.java.core.notification.NotificationParser;
|
||||
import com.wechat.pay.java.core.notification.RequestParam;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.http.HttpRequest;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.servlet.resource.HttpResource;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -13,8 +29,61 @@ import org.springframework.stereotype.Controller;
|
|||
* @author Automated procedures
|
||||
* @since 2023-08-10
|
||||
*/
|
||||
@Api(tags = "支付回调")
|
||||
@Controller
|
||||
@RequestMapping("//payNoticeLog")
|
||||
@RequestMapping("/payNoticeLog")
|
||||
public class PayNoticeLogController {
|
||||
@Resource
|
||||
private WechatPayConfig wechatPayConfig;
|
||||
|
||||
/**
|
||||
* 支付回调接口 本接口不能做验证
|
||||
* @param wechatPayCertificateSerialNumber
|
||||
* @param signature
|
||||
* @param timstamp
|
||||
* @param nonce
|
||||
* @param requestBody
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation("支付回调接口")
|
||||
@PostMapping()
|
||||
public JSONObject payNotice(@RequestHeader("Wechatpay-Serial") String wechatPayCertificateSerialNumber,
|
||||
@RequestHeader("Wechatpay-Signature") String signature,
|
||||
@RequestHeader("Wechatpay-Timestamp") String timstamp,
|
||||
@RequestHeader("Wechatpay-Nonce") String nonce,
|
||||
@RequestBody String requestBody){
|
||||
NotificationConfig config = new RSAAutoCertificateConfig.Builder()
|
||||
.merchantId(wechatPayConfig.getMchId())
|
||||
.privateKeyFromPath(wechatPayConfig.getPrivateKeyPath())
|
||||
.merchantSerialNumber(wechatPayConfig.getPrivateKeyPath())
|
||||
.apiV3Key(wechatPayConfig.getApiV3Key())
|
||||
.build();
|
||||
RequestParam requestParam = new RequestParam.Builder()
|
||||
.serialNumber(wechatPayCertificateSerialNumber)
|
||||
.nonce(nonce)
|
||||
.signature(signature)
|
||||
.timestamp(timstamp)
|
||||
// 若未设置signType,默认值为 WECHATPAY2-SHA256-RSA2048
|
||||
|
||||
.body(requestBody)
|
||||
.build();
|
||||
|
||||
// 初始化 NotificationParser
|
||||
NotificationParser parser = new NotificationParser(config);
|
||||
|
||||
// 验签并解密报文
|
||||
JSONObject decryptObject = parser.parse(requestParam,JSONObject.class);
|
||||
System.out.println("decryptObject="+decryptObject.toJSONString());
|
||||
|
||||
String trade_state=decryptObject.getString("trade_state");
|
||||
JSONObject jsonResponse = new JSONObject();
|
||||
if(trade_state.equals("SUCCESS")) {
|
||||
//各种业务逻辑
|
||||
}else{
|
||||
//还是各种业务逻辑
|
||||
}
|
||||
jsonResponse.put("code", "SUCCESS");
|
||||
jsonResponse.put("message", "成功");
|
||||
return jsonResponse;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.jwl.driver.server.controller;
|
|||
|
||||
|
||||
import com.jwl.driver.server.dto.LoginUserDto;
|
||||
import com.jwl.driver.server.exception.BusinessException;
|
||||
import com.jwl.driver.server.response.BaseResponse;
|
||||
import com.jwl.driver.server.service.ITdSysUserService;
|
||||
import io.swagger.annotations.Api;
|
||||
|
@ -14,6 +15,7 @@ import org.springframework.stereotype.Controller;
|
|||
|
||||
import javax.validation.Valid;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -53,4 +55,22 @@ public class TdSysUserController {
|
|||
return BaseResponse.success(userService.loginOut());
|
||||
}
|
||||
|
||||
@ApiOperation("获取用户信息")
|
||||
@GetMapping("/queryUserMessage")
|
||||
public BaseResponse queryUserMessage() {
|
||||
log.info("获取用户信息======>");
|
||||
return BaseResponse.success(userService.queryUserMessage());
|
||||
}
|
||||
|
||||
@ApiOperation("用户绑定驾校")
|
||||
@PostMapping("/bindSchool")
|
||||
public BaseResponse bindSchool(@RequestBody LoginUserDto userDto) {
|
||||
log.info("用户绑定驾校======>schoolId{}",userDto.getSchoolId());
|
||||
if (Objects.isNull(userDto.getSchoolId())){
|
||||
throw new BusinessException("缺少必要参数");
|
||||
}
|
||||
return BaseResponse.success(userService.bindSchool(userDto));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
package com.jwl.driver.server.controller;
|
||||
|
||||
|
||||
import com.jwl.driver.server.dto.LoginUserDto;
|
||||
import com.jwl.driver.server.response.BaseResponse;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.sound.sampled.*;
|
||||
import javax.validation.Valid;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 支付表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author Automated procedures
|
||||
* @since 2023-08-10
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/voice")
|
||||
@Slf4j
|
||||
public class VoiceController {
|
||||
@ApiOperation("文字转语音")
|
||||
@GetMapping("/contentToAudio")
|
||||
public void contentToAudio(@RequestParam String content) {
|
||||
log.info("文字转语音======>content:{}", content);
|
||||
final AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
|
||||
|
||||
DataLine.Info dataLineInfo = new DataLine.Info(TargetDataLine.class, format);
|
||||
|
||||
if (!AudioSystem.isLineSupported(dataLineInfo)) {
|
||||
return;
|
||||
}
|
||||
|
||||
TargetDataLine targetDataLine;
|
||||
try {
|
||||
targetDataLine = (TargetDataLine) AudioSystem.getLine(dataLineInfo);
|
||||
targetDataLine.open(format);
|
||||
targetDataLine.start();
|
||||
|
||||
// Record audio
|
||||
AudioInputStream audioInputStream = new AudioInputStream(targetDataLine);
|
||||
|
||||
// Save audio to file
|
||||
File audioFile = new File("recorded_audio.wav");
|
||||
AudioSystem.write(audioInputStream, AudioFileFormat.Type.WAVE, audioFile);
|
||||
targetDataLine.close();
|
||||
} catch (LineUnavailableException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
package com.jwl.driver.server.controller;
|
||||
|
||||
import com.jwl.driver.server.dto.WechatPayDto;
|
||||
import com.jwl.driver.server.response.BaseResponse;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 微信支付 接口
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/wechat/pay")
|
||||
public class WechatPayController {
|
||||
|
||||
//生成预支付订单
|
||||
@PostMapping("/prepay")
|
||||
public BaseResponse createPrepay(@RequestBody WechatPayDto payDto){
|
||||
//获取openId
|
||||
|
||||
return BaseResponse.success();
|
||||
|
||||
}
|
||||
|
||||
//支付回调接口
|
||||
|
||||
//查询订单接口
|
||||
|
||||
//关闭订单接口
|
||||
}
|
|
@ -22,4 +22,7 @@ public class LoginUserDto {
|
|||
@ApiModelProperty(value = "登陆验证码",required = true)
|
||||
@NotBlank(message = "登陆验证码不能为空")
|
||||
private String code;
|
||||
|
||||
@ApiModelProperty(value = "驾校id",required = false)
|
||||
private Long schoolId;
|
||||
}
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
|
||||
package com.jwl.driver.server.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class WechatPayDto {
|
||||
|
||||
private Double money;//金额
|
||||
|
||||
private String code;
|
||||
|
||||
|
||||
}
|
|
@ -35,4 +35,16 @@ public interface ITdSysUserService extends IService<TdSysUser> {
|
|||
*/
|
||||
Boolean loginOut();
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
* @return
|
||||
*/
|
||||
LoginUserVo queryUserMessage();
|
||||
|
||||
/**
|
||||
* 绑定驾校
|
||||
* @param userDto
|
||||
* @return
|
||||
*/
|
||||
Boolean bindSchool(LoginUserDto userDto);
|
||||
}
|
||||
|
|
|
@ -5,12 +5,15 @@ import cn.hutool.core.util.StrUtil;
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.jwl.driver.server.constant.Constants;
|
||||
import com.jwl.driver.server.dto.LoginUserDto;
|
||||
import com.jwl.driver.server.dto.SecurityUser;
|
||||
import com.jwl.driver.server.entity.TdSysUser;
|
||||
import com.jwl.driver.server.exception.BusinessException;
|
||||
import com.jwl.driver.server.mapper.TdSysUserMapper;
|
||||
import com.jwl.driver.server.redis.RedisCache;
|
||||
import com.jwl.driver.server.service.ITdSysUserService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.jwl.driver.server.util.DateTimeUtil;
|
||||
import com.jwl.driver.server.util.SecurityUtil;
|
||||
import com.jwl.driver.server.util.SmsUtil;
|
||||
import com.jwl.driver.server.util.TokenThreadUtil;
|
||||
import com.jwl.driver.server.vo.LoginUserVo;
|
||||
|
@ -21,6 +24,7 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -64,19 +68,21 @@ public class TdSysUserServiceImpl extends ServiceImpl<TdSysUserMapper, TdSysUser
|
|||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public LoginUserVo login(LoginUserDto loginUserDto) {
|
||||
//校验验证码
|
||||
String code = redisCache.getCacheObject(Constants.MESSAGE_CODE_PREFIX + loginUserDto.getPhone());
|
||||
//校验验证码 如果是默认验证码则不需要校验
|
||||
if (!StrUtil.equals(Constants.DEFAULT_MESSAGE_CODE,loginUserDto.getCode())){
|
||||
String code = redisCache.getCacheObject(Constants.MESSAGE_CODE_PREFIX + loginUserDto.getPhone());
|
||||
|
||||
if (StrUtil.isBlank(code)){
|
||||
throw new BusinessException("验证码已过期,请重新获取");
|
||||
}
|
||||
if (StrUtil.isBlank(code)){
|
||||
throw new BusinessException("验证码已过期,请重新获取");
|
||||
}
|
||||
|
||||
if (!StrUtil.equals(code,loginUserDto.getCode())){
|
||||
throw new BusinessException("验证码错误");
|
||||
if (!StrUtil.equals(code,loginUserDto.getCode())){
|
||||
throw new BusinessException("验证码错误");
|
||||
}
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<TdSysUser> cond = new LambdaQueryWrapper<TdSysUser>()
|
||||
.eq(TdSysUser::getPhone, "18255439337");
|
||||
.eq(TdSysUser::getPhone, loginUserDto.getPhone());
|
||||
//用户不存在则直接注册登陆
|
||||
TdSysUser tdSysUser = this.baseMapper.selectOne(cond);
|
||||
//todo 用户基础信息填写这里还要完善一下
|
||||
|
@ -91,11 +97,11 @@ public class TdSysUserServiceImpl extends ServiceImpl<TdSysUserMapper, TdSysUser
|
|||
throw new BusinessException("用户注册异常");
|
||||
}
|
||||
}
|
||||
|
||||
String token = UUID.randomUUID().toString();
|
||||
LoginUserVo loginUserVo = new LoginUserVo();
|
||||
BeanUtils.copyProperties(tdSysUser, loginUserVo);
|
||||
loginUserVo.setToken(token);
|
||||
loginUserVo.setDays(DateTimeUtil.getIntervalDays(loginUserVo.getCreateTime(),LocalDateTime.now()) + 1);
|
||||
// 存入redis
|
||||
redisCache.setCacheObject(token, tdSysUser, tokenExpireTime, TimeUnit.DAYS);
|
||||
return loginUserVo;
|
||||
|
@ -110,4 +116,43 @@ public class TdSysUserServiceImpl extends ServiceImpl<TdSysUserMapper, TdSysUser
|
|||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoginUserVo queryUserMessage() {
|
||||
SecurityUser loginUser = SecurityUtil.getLoginUser();
|
||||
|
||||
LambdaQueryWrapper<TdSysUser> cond = new LambdaQueryWrapper<TdSysUser>()
|
||||
.eq(TdSysUser::getUserId, loginUser.getUserId());
|
||||
|
||||
TdSysUser tdSysUser = this.baseMapper.selectOne(cond);
|
||||
if (Objects.isNull(tdSysUser)){
|
||||
throw new BusinessException("用户不存在或者已被删除");
|
||||
}
|
||||
|
||||
LoginUserVo loginUserVo = new LoginUserVo();
|
||||
BeanUtils.copyProperties(tdSysUser, loginUserVo);
|
||||
loginUserVo.setDays(DateTimeUtil.getIntervalDays(loginUserVo.getCreateTime(),LocalDateTime.now()) + 1);
|
||||
|
||||
return loginUserVo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean bindSchool(LoginUserDto userDto) {
|
||||
SecurityUser loginUser = SecurityUtil.getLoginUser();
|
||||
|
||||
LambdaQueryWrapper<TdSysUser> cond = new LambdaQueryWrapper<TdSysUser>()
|
||||
.eq(TdSysUser::getUserId, loginUser.getUserId());
|
||||
|
||||
TdSysUser tdSysUser = this.baseMapper.selectOne(cond);
|
||||
if (Objects.isNull(tdSysUser)){
|
||||
throw new BusinessException("用户不存在或者已被删除");
|
||||
}
|
||||
tdSysUser.setSchoolId(userDto.getSchoolId());
|
||||
|
||||
boolean result = this.updateById(tdSysUser);
|
||||
if (!result){
|
||||
throw new BusinessException("绑定驾校失败");
|
||||
}
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.jwl.driver.server.util;
|
|||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
/**
|
||||
* @Author: yangshuang
|
||||
|
@ -36,4 +37,23 @@ public class DateTimeUtil {
|
|||
public static String getCurrentStr(DateTimeFormatter df) {
|
||||
return dateTime2Str(LocalDateTime.now(), df);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算两个时间之间间隔的天数
|
||||
* @param startDate
|
||||
* @param endDate
|
||||
* @return
|
||||
*/
|
||||
public static long getIntervalDays(LocalDateTime startDate, LocalDateTime endDate) {
|
||||
return ChronoUnit.DAYS.between(startDate, endDate);
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
LocalDateTime date1 = LocalDateTime.of(2023, 4, 18,0,0,0);
|
||||
LocalDateTime date2 = LocalDateTime.of(2023, 4, 19,23,59,59);
|
||||
long between = ChronoUnit.DAYS.between(date1, date2);
|
||||
System.out.println(between);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,266 @@
|
|||
package com.jwl.driver.server.util;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.net.ssl.*;
|
||||
import java.io.*;
|
||||
import java.net.ConnectException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
/**
|
||||
* 通用http发送方法
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class HttpUtils
|
||||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(HttpUtils.class);
|
||||
|
||||
/**
|
||||
* 向指定 URL 发送GET方法的请求
|
||||
*
|
||||
* @param url 发送请求的 URL
|
||||
* @return 所代表远程资源的响应结果
|
||||
*/
|
||||
public static String sendGet(String url)
|
||||
{
|
||||
return sendGet(url, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 向指定 URL 发送GET方法的请求
|
||||
*
|
||||
* @param url 发送请求的 URL
|
||||
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
||||
* @return 所代表远程资源的响应结果
|
||||
*/
|
||||
public static String sendGet(String url, String param)
|
||||
{
|
||||
return sendGet(url, param, "UTF-8");
|
||||
}
|
||||
|
||||
/**
|
||||
* 向指定 URL 发送GET方法的请求
|
||||
*
|
||||
* @param url 发送请求的 URL
|
||||
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
||||
* @param contentType 编码类型
|
||||
* @return 所代表远程资源的响应结果
|
||||
*/
|
||||
public static String sendGet(String url, String param, String contentType)
|
||||
{
|
||||
StringBuilder result = new StringBuilder();
|
||||
BufferedReader in = null;
|
||||
try
|
||||
{
|
||||
String urlNameString = StringUtils.isNotBlank(param) ? url + "?" + param : url;
|
||||
log.info("sendGet - {}", urlNameString);
|
||||
URL realUrl = new URL(urlNameString);
|
||||
URLConnection connection = realUrl.openConnection();
|
||||
connection.setRequestProperty("accept", "*/*");
|
||||
connection.setRequestProperty("connection", "Keep-Alive");
|
||||
connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
|
||||
connection.connect();
|
||||
in = new BufferedReader(new InputStreamReader(connection.getInputStream(), contentType));
|
||||
String line;
|
||||
while ((line = in.readLine()) != null)
|
||||
{
|
||||
result.append(line);
|
||||
}
|
||||
log.info("recv - {}", result);
|
||||
}
|
||||
catch (ConnectException e)
|
||||
{
|
||||
log.error("调用HttpUtils.sendGet ConnectException, url=" + url + ",param=" + param, e);
|
||||
}
|
||||
catch (SocketTimeoutException e)
|
||||
{
|
||||
log.error("调用HttpUtils.sendGet SocketTimeoutException, url=" + url + ",param=" + param, e);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
log.error("调用HttpUtils.sendGet IOException, url=" + url + ",param=" + param, e);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.error("调用HttpsUtil.sendGet Exception, url=" + url + ",param=" + param, e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
if (in != null)
|
||||
{
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.error("调用in.close Exception, url=" + url + ",param=" + param, ex);
|
||||
}
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 向指定 URL 发送POST方法的请求
|
||||
*
|
||||
* @param url 发送请求的 URL
|
||||
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
||||
* @return 所代表远程资源的响应结果
|
||||
*/
|
||||
public static String sendPost(String url, String param)
|
||||
{
|
||||
PrintWriter out = null;
|
||||
BufferedReader in = null;
|
||||
StringBuilder result = new StringBuilder();
|
||||
try
|
||||
{
|
||||
log.info("sendPost - {}", url);
|
||||
URL realUrl = new URL(url);
|
||||
URLConnection conn = realUrl.openConnection();
|
||||
conn.setRequestProperty("accept", "*/*");
|
||||
conn.setRequestProperty("connection", "Keep-Alive");
|
||||
conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
|
||||
conn.setRequestProperty("Accept-Charset", "utf-8");
|
||||
conn.setRequestProperty("contentType", "utf-8");
|
||||
conn.setDoOutput(true);
|
||||
conn.setDoInput(true);
|
||||
out = new PrintWriter(conn.getOutputStream());
|
||||
out.print(param);
|
||||
out.flush();
|
||||
in = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8));
|
||||
String line;
|
||||
while ((line = in.readLine()) != null)
|
||||
{
|
||||
result.append(line);
|
||||
}
|
||||
log.info("recv - {}", result);
|
||||
}
|
||||
catch (ConnectException e)
|
||||
{
|
||||
log.error("调用HttpUtils.sendPost ConnectException, url=" + url + ",param=" + param, e);
|
||||
}
|
||||
catch (SocketTimeoutException e)
|
||||
{
|
||||
log.error("调用HttpUtils.sendPost SocketTimeoutException, url=" + url + ",param=" + param, e);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
log.error("调用HttpUtils.sendPost IOException, url=" + url + ",param=" + param, e);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.error("调用HttpsUtil.sendPost Exception, url=" + url + ",param=" + param, e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
if (out != null)
|
||||
{
|
||||
out.close();
|
||||
}
|
||||
if (in != null)
|
||||
{
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
log.error("调用in.close Exception, url=" + url + ",param=" + param, ex);
|
||||
}
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static String sendSSLPost(String url, String param)
|
||||
{
|
||||
StringBuilder result = new StringBuilder();
|
||||
String urlNameString = url + "?" + param;
|
||||
try
|
||||
{
|
||||
log.info("sendSSLPost - {}", urlNameString);
|
||||
SSLContext sc = SSLContext.getInstance("SSL");
|
||||
sc.init(null, new TrustManager[] { new TrustAnyTrustManager() }, new java.security.SecureRandom());
|
||||
URL console = new URL(urlNameString);
|
||||
HttpsURLConnection conn = (HttpsURLConnection) console.openConnection();
|
||||
conn.setRequestProperty("accept", "*/*");
|
||||
conn.setRequestProperty("connection", "Keep-Alive");
|
||||
conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
|
||||
conn.setRequestProperty("Accept-Charset", "utf-8");
|
||||
conn.setRequestProperty("contentType", "utf-8");
|
||||
conn.setDoOutput(true);
|
||||
conn.setDoInput(true);
|
||||
|
||||
conn.setSSLSocketFactory(sc.getSocketFactory());
|
||||
conn.setHostnameVerifier(new TrustAnyHostnameVerifier());
|
||||
conn.connect();
|
||||
InputStream is = conn.getInputStream();
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(is));
|
||||
String ret = "";
|
||||
while ((ret = br.readLine()) != null)
|
||||
{
|
||||
if (ret != null && !"".equals(ret.trim()))
|
||||
{
|
||||
result.append(new String(ret.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8));
|
||||
}
|
||||
}
|
||||
log.info("recv - {}", result);
|
||||
conn.disconnect();
|
||||
br.close();
|
||||
}
|
||||
catch (ConnectException e)
|
||||
{
|
||||
log.error("调用HttpUtils.sendSSLPost ConnectException, url=" + url + ",param=" + param, e);
|
||||
}
|
||||
catch (SocketTimeoutException e)
|
||||
{
|
||||
log.error("调用HttpUtils.sendSSLPost SocketTimeoutException, url=" + url + ",param=" + param, e);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
log.error("调用HttpUtils.sendSSLPost IOException, url=" + url + ",param=" + param, e);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.error("调用HttpsUtil.sendSSLPost Exception, url=" + url + ",param=" + param, e);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
private static class TrustAnyTrustManager implements X509TrustManager
|
||||
{
|
||||
@Override
|
||||
public void checkClientTrusted(X509Certificate[] chain, String authType)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkServerTrusted(X509Certificate[] chain, String authType)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public X509Certificate[] getAcceptedIssuers()
|
||||
{
|
||||
return new X509Certificate[] {};
|
||||
}
|
||||
}
|
||||
|
||||
private static class TrustAnyHostnameVerifier implements HostnameVerifier
|
||||
{
|
||||
@Override
|
||||
public boolean verify(String hostname, SSLSession session)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,28 @@
|
|||
package com.jwl.driver.server.util;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
/**
|
||||
* 微信支付工具
|
||||
*/
|
||||
public class WechatPayUtil {
|
||||
|
||||
/**
|
||||
* 获取微信openID
|
||||
* @param appId
|
||||
* @param appSecret
|
||||
* @param jsCode
|
||||
* @return
|
||||
*/
|
||||
public static String getOpenId(String appId, String appSecret, String jsCode){
|
||||
String url = "https://api.weixin.qq.com/sns/jscode2session?appid="+appId
|
||||
+"&secret="+appSecret+"&js_code="+jsCode+"&grant_type=authorization_code";
|
||||
String result = HttpUtils.sendGet(url);
|
||||
JSONObject jsonObject = JSONObject.parseObject(result);
|
||||
if(!jsonObject.isEmpty() && (jsonObject.get("openid")!=null)){
|
||||
return jsonObject.get("openid").toString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package com.jwl.driver.server.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@ApiModel("微信支付")
|
||||
public class AppletPayVo {
|
||||
|
||||
@ApiModelProperty("支付金额")
|
||||
private Double money;//金额
|
||||
|
||||
@ApiModelProperty("小程序端 获取的code")
|
||||
private String code;//小程序端 获取的code
|
||||
|
||||
@ApiModelProperty("用户id")
|
||||
private String userId;
|
||||
|
||||
@ApiModelProperty("支付描述")
|
||||
private String description;
|
||||
|
||||
@ApiModelProperty("商户系统的订单号")
|
||||
private String outTradeNo;
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.jwl.driver.server.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@ApiModel("H5支付")
|
||||
@Data
|
||||
public class H5PayVo {
|
||||
@ApiModelProperty("支付金额")
|
||||
private Double money;//金额
|
||||
|
||||
@ApiModelProperty("用户id")
|
||||
private String userId;
|
||||
|
||||
@ApiModelProperty("支付描述")
|
||||
private String description;
|
||||
|
||||
@ApiModelProperty("商户系统的订单号")
|
||||
private String outTradeNo;
|
||||
|
||||
@ApiModelProperty("用户的客户端IP")
|
||||
private String clientIp;
|
||||
}
|
|
@ -8,6 +8,8 @@ import io.swagger.annotations.ApiModelProperty;
|
|||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author 曹林
|
||||
* @description 登陆用户出参
|
||||
|
@ -64,5 +66,17 @@ public class LoginUserVo {
|
|||
@ApiModelProperty("用户token")
|
||||
private String token;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@ApiModelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 学车天数
|
||||
*/
|
||||
@ApiModelProperty("学车天数")
|
||||
private Long days;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ driver:
|
|||
- /driver-api/tdSysUser/code
|
||||
- /tdQuestion/duima/list
|
||||
- /tdQuestion/duima/update
|
||||
- /payNoticeLog
|
||||
|
||||
# 需要权限校验url集合
|
||||
needAuthEndPoints:
|
||||
|
@ -60,9 +61,12 @@ message:
|
|||
|
||||
|
||||
wechatpay:
|
||||
appId: 'wx756a7425037609fb'
|
||||
mchId: '1650477646'
|
||||
apiV3Key: 'JingWuLianJiaKao20120813ZhouHong'
|
||||
mchSerialNo: '52974C99DFCC518EA2E5AD20C3753E38B924868D'
|
||||
privateKeyPath: 'classpath*:/wechatPay/**Mapper.xml'
|
||||
appId: wx756a7425037609fb
|
||||
appSecret: 3e8053032b16c574e38d554ddd438cfd
|
||||
mchId: 1650477646
|
||||
apiV3Key: JingWuLianJiaKao20120813ZhouHong
|
||||
mchSerialNo: 52974C99DFCC518EA2E5AD20C3753E38B924868D
|
||||
privateKeyPath: classpath*:/wechatPay/apiclient_key.pem
|
||||
payNoticeUrl: https://jwl.ahduima.com/driver-api/payNoticeLog
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue