73 changed files with 2358 additions and 179 deletions
@ -0,0 +1,54 @@
|
||||
package com.biutag.constants; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.stream.Collectors; |
||||
|
||||
/** |
||||
* Created by oumyye on 2019/1/18. |
||||
*/ |
||||
public class AppConstants { |
||||
|
||||
|
||||
public static final String DEPT_TYPE_CATEGORY="6"; //是机构类型 数据字段 类型为6
|
||||
|
||||
|
||||
|
||||
|
||||
static class Entity { |
||||
private String name; |
||||
private String age; |
||||
|
||||
public Entity(String name, String age) { |
||||
this.name = name; |
||||
this.age = age; |
||||
} |
||||
|
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
public String getAge() { |
||||
return age; |
||||
} |
||||
} |
||||
|
||||
|
||||
public static void main(String[] args) { |
||||
List<Entity> entityList = new ArrayList<>(); |
||||
entityList.add(new Entity("Alice", "20")); |
||||
entityList.add(new Entity("Bob", "25")); |
||||
entityList.add(new Entity("Charlie", "30")); |
||||
|
||||
String targetAge = "25"; |
||||
|
||||
String matchedNames = entityList.stream() |
||||
.filter(entity -> entity.getAge() .equals(targetAge)) |
||||
.map(Entity::getName).findFirst().get(); |
||||
|
||||
System.out.println("Found matching names:"+matchedNames); |
||||
|
||||
} |
||||
|
||||
|
||||
} |
||||
@ -0,0 +1,9 @@
|
||||
package com.biutag.constants; |
||||
|
||||
public class Constants { |
||||
|
||||
public static final String DELETED = "Y"; |
||||
|
||||
public static final String UNDELETED = "N"; |
||||
|
||||
} |
||||
@ -0,0 +1,27 @@
|
||||
package com.biutag.entity.system; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
@Data |
||||
@ApiModel("警员部门关联表") |
||||
public class PoliceDepart implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
@TableId(value="id", type= IdType.AUTO) |
||||
@ApiModelProperty("ID") |
||||
private Integer id; |
||||
|
||||
@ApiModelProperty("警号") |
||||
private String empNo; |
||||
|
||||
@ApiModelProperty("部门id") |
||||
private String departId; |
||||
|
||||
} |
||||
@ -0,0 +1,27 @@
|
||||
package com.biutag.entity.system; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
@Data |
||||
@ApiModel("警员角色关联表") |
||||
public class PolicePosition implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
@TableId(value="id", type= IdType.AUTO) |
||||
@ApiModelProperty("ID") |
||||
private Integer id; |
||||
|
||||
@ApiModelProperty("警号") |
||||
private String empNo; |
||||
|
||||
@ApiModelProperty("岗位id") |
||||
private String positionId; |
||||
|
||||
} |
||||
@ -0,0 +1,27 @@
|
||||
package com.biutag.entity.system; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
@Data |
||||
@ApiModel("警员角色关联表") |
||||
public class PoliceRole implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
@TableId(value="id", type= IdType.AUTO) |
||||
@ApiModelProperty("ID") |
||||
private Integer id; |
||||
|
||||
@ApiModelProperty("警号") |
||||
private String empNo; |
||||
|
||||
@ApiModelProperty("角色id") |
||||
private String roleId; |
||||
|
||||
} |
||||
@ -0,0 +1,8 @@
|
||||
package com.biutag.exception; |
||||
|
||||
/** |
||||
* @author wxc |
||||
* @date 2024/1/9 |
||||
*/ |
||||
public class AuthException extends RuntimeException { |
||||
} |
||||
@ -0,0 +1,15 @@
|
||||
package com.biutag.mapper.system; |
||||
|
||||
import com.biutag.core.basics.IBaseMapper; |
||||
import com.biutag.entity.system.PoliceDepart; |
||||
import com.biutag.entity.system.PolicePosition; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
|
||||
/** |
||||
* 系统岗位Mapper |
||||
*/ |
||||
@Mapper |
||||
public interface PoliceDepartMapper extends IBaseMapper<PoliceDepart> { |
||||
|
||||
|
||||
} |
||||
@ -0,0 +1,18 @@
|
||||
package com.biutag.mapper.system; |
||||
|
||||
import com.biutag.core.basics.IBaseMapper; |
||||
import com.biutag.entity.system.Dept; |
||||
import com.biutag.entity.system.PolicePosition; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
import org.apache.ibatis.annotations.Select; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* 系统岗位Mapper |
||||
*/ |
||||
@Mapper |
||||
public interface PolicePositionMapper extends IBaseMapper<PolicePosition> { |
||||
|
||||
|
||||
} |
||||
@ -0,0 +1,15 @@
|
||||
package com.biutag.mapper.system; |
||||
|
||||
import com.biutag.core.basics.IBaseMapper; |
||||
import com.biutag.entity.system.PoliceDepart; |
||||
import com.biutag.entity.system.PoliceRole; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
|
||||
/** |
||||
* 系统岗位Mapper |
||||
*/ |
||||
@Mapper |
||||
public interface PoliceRoleMapper extends IBaseMapper<PoliceRole> { |
||||
|
||||
|
||||
} |
||||
@ -0,0 +1,18 @@
|
||||
package com.biutag.util; |
||||
|
||||
import java.io.ByteArrayInputStream; |
||||
import java.io.InputStream; |
||||
import java.util.Base64; |
||||
|
||||
public class IOUtil { |
||||
|
||||
/** |
||||
* 将base64 转 stream |
||||
* @param base64 |
||||
* @return |
||||
*/ |
||||
public static InputStream base64ToStream(String base64) { |
||||
byte[] decodedBytes = Base64.getDecoder().decode(base64); |
||||
return new ByteArrayInputStream(decodedBytes); |
||||
} |
||||
} |
||||
@ -1,46 +0,0 @@
|
||||
package com.biutag.util; |
||||
|
||||
import com.biutag.exception.MinioOperateException; |
||||
import io.minio.BucketExistsArgs; |
||||
import io.minio.MakeBucketArgs; |
||||
import io.minio.MinioClient; |
||||
import io.minio.UploadObjectArgs; |
||||
import io.minio.errors.MinioException; |
||||
|
||||
import java.io.IOException; |
||||
import java.security.InvalidKeyException; |
||||
import java.security.NoSuchAlgorithmException; |
||||
|
||||
public class MinioUtil { |
||||
|
||||
public static void main(String[] args) { |
||||
// 设置MinIO服务器的端点、Access Key和Secret Key
|
||||
String endpoint = "http://172.31.217.20:31813"; |
||||
String accessKey = "your-access-key"; |
||||
String secretKey = "your-secret-key"; |
||||
try { |
||||
// 创建MinIO客户端
|
||||
MinioClient minioClient = MinioClient.builder() |
||||
.endpoint(endpoint) |
||||
.credentials(accessKey, secretKey) |
||||
.build(); |
||||
// 检查存储桶是否存在,如果不存在则创建
|
||||
String bucketName = "mailbox"; |
||||
BucketExistsArgs bucketExistsArgs = BucketExistsArgs.builder() |
||||
.bucket(bucketName) |
||||
// 添加额外的选项
|
||||
.build(); |
||||
if (!minioClient.bucketExists(bucketExistsArgs)) { |
||||
MakeBucketArgs makeBucketArgs = MakeBucketArgs.builder().bucket(bucketName).build(); |
||||
minioClient.makeBucket(makeBucketArgs); |
||||
} |
||||
// 上传文件到MinIO服务器
|
||||
String objectName = "your-object-name"; |
||||
String filePath = "path/to/your/file.txt"; |
||||
UploadObjectArgs uploadObjectArgs = UploadObjectArgs.builder().bucket(bucketName).object(objectName).filename(filePath).build(); |
||||
minioClient.uploadObject(uploadObjectArgs); |
||||
} catch (MinioException | IOException | NoSuchAlgorithmException | InvalidKeyException e) { |
||||
throw new MinioOperateException(e.getCause()); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,22 @@
|
||||
package com.biutag.validator; |
||||
|
||||
import cn.hutool.core.util.IdcardUtil; |
||||
import cn.hutool.core.util.PhoneUtil; |
||||
import com.biutag.validator.annotation.IdCard; |
||||
|
||||
import javax.validation.ConstraintValidator; |
||||
import javax.validation.ConstraintValidatorContext; |
||||
|
||||
public class IdCardValidator implements ConstraintValidator<IdCard, String> { |
||||
|
||||
@Override |
||||
public void initialize(IdCard constraintAnnotation) { |
||||
ConstraintValidator.super.initialize(constraintAnnotation); |
||||
} |
||||
|
||||
@Override |
||||
public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) { |
||||
return IdcardUtil.isValidCard(value); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,22 @@
|
||||
package com.biutag.validator; |
||||
|
||||
import cn.hutool.core.util.IdcardUtil; |
||||
import cn.hutool.core.util.PhoneUtil; |
||||
import com.biutag.validator.annotation.IdCard; |
||||
|
||||
import javax.validation.ConstraintValidator; |
||||
import javax.validation.ConstraintValidatorContext; |
||||
|
||||
public class PhoneValidator implements ConstraintValidator<IdCard, String> { |
||||
|
||||
@Override |
||||
public void initialize(IdCard constraintAnnotation) { |
||||
ConstraintValidator.super.initialize(constraintAnnotation); |
||||
} |
||||
|
||||
@Override |
||||
public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) { |
||||
return PhoneUtil.isPhone(value); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,21 @@
|
||||
package com.biutag.validator.annotation; |
||||
|
||||
import com.biutag.validator.IdCardValidator; |
||||
|
||||
import javax.validation.Constraint; |
||||
import javax.validation.Payload; |
||||
import java.lang.annotation.*; |
||||
|
||||
@Documented |
||||
@Constraint(validatedBy = IdCardValidator.class) |
||||
@Target({ ElementType.PARAMETER,ElementType.FIELD }) |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
public @interface IdCard { |
||||
|
||||
String message() default "证件非法"; |
||||
|
||||
Class<?>[] groups() default {}; |
||||
|
||||
Class<? extends Payload>[] payload() default { }; |
||||
|
||||
} |
||||
@ -0,0 +1,21 @@
|
||||
package com.biutag.validator.annotation; |
||||
|
||||
import com.biutag.validator.PhoneValidator; |
||||
|
||||
import javax.validation.Constraint; |
||||
import javax.validation.Payload; |
||||
import java.lang.annotation.*; |
||||
|
||||
@Documented |
||||
@Constraint(validatedBy = PhoneValidator.class) |
||||
@Target({ ElementType.PARAMETER,ElementType.FIELD }) |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
public @interface Phone { |
||||
|
||||
String message() default "手机号码错误"; |
||||
|
||||
Class<?>[] groups() default {}; |
||||
|
||||
Class<? extends Payload>[] payload() default { }; |
||||
|
||||
} |
||||
@ -0,0 +1 @@
|
||||
com.biutag.exception.GlobalException |
||||
@ -0,0 +1,41 @@
|
||||
package com.biutag.outer.config; |
||||
|
||||
import cn.hutool.core.util.StrUtil; |
||||
import com.biutag.exception.AuthException; |
||||
import jakarta.servlet.http.HttpServletRequest; |
||||
import jakarta.servlet.http.HttpServletResponse; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.web.servlet.HandlerInterceptor; |
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; |
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
||||
|
||||
/** |
||||
* @author wxc |
||||
* @date 2024/1/8 |
||||
*/ |
||||
@Slf4j |
||||
@Configuration |
||||
public class InterceptorConfig implements WebMvcConfigurer { |
||||
|
||||
@Override |
||||
public void addInterceptors(InterceptorRegistry registry) { |
||||
registry.addInterceptor(new AuthInterceptor()).addPathPatterns("/**").excludePathPatterns("/auth", "/auth/openid", "/auth/wx/faceAuth", "/file/stream/**"); |
||||
} |
||||
|
||||
static class AuthInterceptor implements HandlerInterceptor { |
||||
|
||||
@Override |
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { |
||||
log.info("请求地址:{}", request.getRequestURI()); |
||||
String authorization = request.getHeader("Authorization"); |
||||
if (StrUtil.isBlank(authorization)) { |
||||
throw new AuthException(); |
||||
} |
||||
System.out.println(authorization); |
||||
return true; |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,89 @@
|
||||
package com.biutag.outer.config; |
||||
|
||||
import cn.hutool.core.date.DateUtil; |
||||
import cn.hutool.core.util.IdUtil; |
||||
import com.biutag.exception.MinioOperateException; |
||||
import com.biutag.util.IOUtil; |
||||
import io.minio.*; |
||||
import io.minio.errors.*; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import java.io.IOException; |
||||
import java.io.InputStream; |
||||
import java.io.OutputStream; |
||||
import java.net.URLDecoder; |
||||
import java.security.InvalidKeyException; |
||||
import java.security.NoSuchAlgorithmException; |
||||
import java.util.Date; |
||||
import java.util.Optional; |
||||
|
||||
@Component |
||||
public class Minio { |
||||
private final MinioClient minioClient; |
||||
|
||||
public final MinioProperties properties; |
||||
|
||||
public Minio(MinioProperties properties) { |
||||
this.properties = properties; |
||||
// 创建MinIO客户端
|
||||
this.minioClient = MinioClient.builder() |
||||
.endpoint(properties.getEndpoint()) |
||||
.credentials(properties.getAccessKey(), properties.getSecretKey()) |
||||
.build(); |
||||
BucketExistsArgs bucketExistsArgs = BucketExistsArgs.builder() |
||||
.bucket(properties.getBucketName()) |
||||
.build(); |
||||
try { |
||||
if (!minioClient.bucketExists(bucketExistsArgs)) { |
||||
MakeBucketArgs makeBucketArgs = MakeBucketArgs.builder().bucket(properties.getBucketName()).build(); |
||||
minioClient.makeBucket(makeBucketArgs); |
||||
} |
||||
} catch (IOException | ServerException | InsufficientDataException | ErrorResponseException | NoSuchAlgorithmException | |
||||
InvalidKeyException | InvalidResponseException | XmlParserException | InternalException e) { |
||||
throw new MinioOperateException(e); |
||||
} |
||||
} |
||||
|
||||
public String upload(InputStream is, String originName) { |
||||
try { |
||||
String filepath = DateUtil.format(new Date(), "YYMMdd") + "/" + IdUtil.nanoId(8) + |
||||
Optional.ofNullable(originName).map(item -> "_" + item).orElse(""); |
||||
PutObjectArgs putObjectArgs = PutObjectArgs.builder() |
||||
.object(filepath) |
||||
.bucket(properties.getBucketName()) |
||||
.stream(is, is.available(), -1).build(); |
||||
minioClient.putObject(putObjectArgs); |
||||
return filepath; |
||||
} catch (IOException | ServerException | InsufficientDataException | ErrorResponseException | NoSuchAlgorithmException | |
||||
InvalidKeyException | InvalidResponseException | XmlParserException | InternalException e) { |
||||
throw new MinioOperateException(e); |
||||
} |
||||
} |
||||
|
||||
public String upload(String base64) { |
||||
return upload(IOUtil.base64ToStream(base64), null); |
||||
} |
||||
|
||||
public void get(String filepath, OutputStream os) { |
||||
try { |
||||
GetObjectArgs getObjectArgs = GetObjectArgs.builder() |
||||
.bucket(properties.getBucketName()) |
||||
.object(URLDecoder.decode(filepath)) |
||||
.build(); |
||||
GetObjectResponse response = minioClient.getObject(getObjectArgs); |
||||
byte[] buffer = new byte[1024]; |
||||
int bytesRead; |
||||
while ((bytesRead = response.read(buffer, 0, buffer.length)) != -1) { |
||||
// 处理读取的数据,例如写入到其他流或进行其他操作
|
||||
// 这里只是简单的打印数据
|
||||
os.write(buffer, 0, bytesRead); |
||||
} |
||||
response.close(); |
||||
os.close(); |
||||
} catch (IOException | ServerException | InsufficientDataException | ErrorResponseException | NoSuchAlgorithmException | |
||||
InvalidKeyException | InvalidResponseException | XmlParserException | InternalException e) { |
||||
throw new MinioOperateException(e); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,21 @@
|
||||
package com.biutag.outer.config; |
||||
|
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
import org.springframework.boot.context.properties.ConfigurationProperties; |
||||
import org.springframework.context.annotation.Configuration; |
||||
|
||||
@Setter |
||||
@Getter |
||||
@Configuration |
||||
@ConfigurationProperties( |
||||
prefix = "oss.minio" |
||||
) |
||||
public class MinioProperties { |
||||
|
||||
private String endpoint; |
||||
private String accessKey; |
||||
private String secretKey; |
||||
private String bucketName; |
||||
|
||||
} |
||||
@ -0,0 +1,23 @@
|
||||
package com.biutag.outer.config; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType; |
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; |
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
|
||||
@Configuration |
||||
public class MybatisPlusConfig { |
||||
|
||||
/** |
||||
* 新增分页拦截器,并设置数据库类型为mysql |
||||
* @return |
||||
*/ |
||||
@Bean |
||||
public MybatisPlusInterceptor mybatisPlusInterceptor() { |
||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); |
||||
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.POSTGRE_SQL)); |
||||
return interceptor; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,94 @@
|
||||
package com.biutag.outer.controller; |
||||
|
||||
import cn.hutool.core.util.IdUtil; |
||||
import cn.hutool.core.util.StrUtil; |
||||
import com.alibaba.fastjson2.JSON; |
||||
import com.alibaba.fastjson2.JSONObject; |
||||
import com.biutag.core.AjaxResult; |
||||
import com.biutag.exception.AuthException; |
||||
import com.biutag.outer.domain.User; |
||||
import com.biutag.outer.domain.bo.FaceAuthBo; |
||||
import com.biutag.outer.service.FaceAuthService; |
||||
import com.biutag.outer.service.UserService; |
||||
import com.biutag.outer.util.TokenUtil; |
||||
import com.biutag.outer.util.UserHelper; |
||||
import com.biutag.outer.util.Weixin; |
||||
import com.biutag.outer.util.Weixin2; |
||||
import jakarta.validation.Valid; |
||||
import lombok.RequiredArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.validation.annotation.Validated; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import java.time.LocalDateTime; |
||||
import java.util.Date; |
||||
|
||||
@Validated |
||||
@Slf4j |
||||
@RequiredArgsConstructor |
||||
@RequestMapping("auth") |
||||
@RestController |
||||
public class AuthController { |
||||
|
||||
private final UserService userService; |
||||
|
||||
private final FaceAuthService faceAuthService; |
||||
|
||||
@PostMapping |
||||
public AjaxResult<JSONObject> code(@RequestParam String code) { |
||||
JSONObject result = Weixin.getAccessToken(code); |
||||
String openid = result.getString("openid"); |
||||
if (StrUtil.isBlank(openid)) { |
||||
throw new AuthException(); |
||||
} |
||||
User user = userService.getByOpenid(openid); |
||||
if (user == null) { |
||||
user = new User(); |
||||
user.setOpenid(openid); |
||||
user.setCreateTime(LocalDateTime.now()); |
||||
userService.save(user); |
||||
} |
||||
return AjaxResult.success(JSONObject.of("token", TokenUtil.set(user), "user", user)); |
||||
} |
||||
|
||||
@PostMapping("openid") |
||||
public AjaxResult<JSONObject> openid(@RequestParam String openid) { |
||||
User user = userService.getByOpenid(openid); |
||||
return AjaxResult.success(JSONObject.of("token", TokenUtil.set(user), "user", user)); |
||||
} |
||||
|
||||
@GetMapping("user") |
||||
public AjaxResult<User> user() { |
||||
return AjaxResult.success(UserHelper.getCurrentUser()); |
||||
} |
||||
|
||||
@GetMapping("realUser") |
||||
public AjaxResult<User> realUser(@RequestParam Integer userId) { |
||||
log.info("请求 realUser: {}", userId); |
||||
User user = userService.getById(userId); |
||||
if (StrUtil.isNotBlank(user.getIdCard())) { |
||||
log.info("用户信息:{}", JSON.toJSONString(user)); |
||||
// 更新用户信息
|
||||
UserHelper.update(user); |
||||
} |
||||
return AjaxResult.success(user); |
||||
} |
||||
|
||||
@GetMapping("wx/sign") |
||||
public AjaxResult<JSONObject> sign(@RequestParam String url) { |
||||
String noncestr = IdUtil.nanoId(16); |
||||
String jsapiTicket = Weixin2.getTicket(); |
||||
log.info("jsapiTicket: {}", jsapiTicket); |
||||
long timestamp = new Date().getTime() / 1000; |
||||
String sign = Weixin.sign(noncestr, jsapiTicket, timestamp, url); |
||||
JSONObject result = JSONObject.of("timestamp", timestamp, "nonceStr", noncestr, "signature", sign); |
||||
return AjaxResult.success(result); |
||||
} |
||||
|
||||
@PostMapping("wx/faceAuth") |
||||
public AjaxResult<Boolean> faceAuth(@RequestBody @Valid FaceAuthBo faceAuth) { |
||||
log.info("人身认证结果:{}", JSON.toJSONString(faceAuth)); |
||||
return AjaxResult.success(faceAuthService.save(faceAuth)); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,45 @@
|
||||
package com.biutag.outer.controller; |
||||
|
||||
import com.alibaba.fastjson2.JSONObject; |
||||
import com.biutag.core.AjaxResult; |
||||
import com.biutag.outer.config.Minio; |
||||
import jakarta.servlet.http.HttpServletRequest; |
||||
import jakarta.servlet.http.HttpServletResponse; |
||||
import lombok.RequiredArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.*; |
||||
import org.springframework.web.multipart.MultipartFile; |
||||
|
||||
import java.io.IOException; |
||||
|
||||
@Slf4j |
||||
@RequiredArgsConstructor |
||||
@RequestMapping("file") |
||||
@Controller |
||||
public class FileController { |
||||
|
||||
private final Minio minio; |
||||
|
||||
@ResponseBody |
||||
@PostMapping("upload") |
||||
public AjaxResult<JSONObject> upload(@RequestPart("file") MultipartFile file) throws IOException { |
||||
String filepath = minio.upload(file.getInputStream(), file.getOriginalFilename()); |
||||
return AjaxResult.success(JSONObject.of("filepath", filepath)); |
||||
} |
||||
|
||||
@ResponseBody |
||||
@PostMapping("upload/base64") |
||||
public AjaxResult<JSONObject> upload(@RequestBody JSONObject file) { |
||||
log.info("文件上传 base64: {}", file.toJSONString()); |
||||
String filepath = minio.upload(file.getString("base64")); |
||||
return AjaxResult.success(JSONObject.of("filepath", filepath)); |
||||
} |
||||
|
||||
@GetMapping("stream/**") |
||||
public void download(HttpServletRequest request, HttpServletResponse response) throws IOException { |
||||
String requestURI = request.getRequestURI(); |
||||
minio.get(requestURI.substring("/file/stream/".length()), response.getOutputStream()); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,46 @@
|
||||
package com.biutag.outer.controller; |
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import com.biutag.core.AjaxResult; |
||||
import com.biutag.outer.domain.MailDraft; |
||||
import com.biutag.outer.domain.bo.MailBo; |
||||
import com.biutag.outer.domain.vo.MailDraftVo; |
||||
import com.biutag.outer.service.MailDraftService; |
||||
import lombok.RequiredArgsConstructor; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import java.util.List; |
||||
|
||||
@RequiredArgsConstructor |
||||
@RequestMapping("mail/draft") |
||||
@RestController |
||||
public class MailDraftController { |
||||
|
||||
private final MailDraftService mailDraftService; |
||||
|
||||
/** |
||||
* 存草稿 |
||||
* @param mailBo |
||||
* @return |
||||
*/ |
||||
@PostMapping |
||||
public AjaxResult<MailDraft> draft(@RequestBody MailBo mailBo) { |
||||
return AjaxResult.success(mailDraftService.save(mailBo)); |
||||
} |
||||
|
||||
@GetMapping |
||||
public AjaxResult<Page<MailDraftVo>> list(Page<MailDraft> page) { |
||||
return AjaxResult.success(mailDraftService.listByCurrentUserId(page)); |
||||
} |
||||
|
||||
@GetMapping("{id}") |
||||
public AjaxResult<MailDraftVo> get(@PathVariable String id) { |
||||
return AjaxResult.success(MailDraftVo.of(mailDraftService.getById(id))); |
||||
} |
||||
|
||||
@DeleteMapping("{id}") |
||||
public AjaxResult<Boolean> del(@PathVariable String id) { |
||||
return AjaxResult.success(mailDraftService.removeById(id)); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,30 @@
|
||||
package com.biutag.outer.controller; |
||||
|
||||
import com.alibaba.fastjson2.JSONObject; |
||||
import com.biutag.core.AjaxResult; |
||||
import com.biutag.outer.util.CodeUtil; |
||||
import com.biutag.outer.util.Sms; |
||||
import lombok.RequiredArgsConstructor; |
||||
import org.springframework.web.bind.annotation.PostMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RequestParam; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
import java.util.Random; |
||||
|
||||
@RequiredArgsConstructor |
||||
@RequestMapping("sms") |
||||
@RestController |
||||
public class SmsController { |
||||
|
||||
private static final Random random = new Random(); |
||||
@PostMapping("send") |
||||
public AjaxResult<JSONObject> sendCode(@RequestParam String phone) { |
||||
String code = String.valueOf(1000 + random.nextInt(9000)); |
||||
// 发送短信
|
||||
Sms.send(phone, code); |
||||
// 设置缓存
|
||||
return AjaxResult.success(JSONObject.of("requestId", CodeUtil.set(code))); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,32 @@
|
||||
package com.biutag.outer.domain; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
import java.time.LocalDateTime; |
||||
import java.util.Date; |
||||
|
||||
@Setter |
||||
@Getter |
||||
public class FaceAuth { |
||||
|
||||
@TableId(type = IdType.AUTO) |
||||
private Integer id; |
||||
|
||||
private Integer userId; |
||||
|
||||
private String realName; |
||||
|
||||
private String idCard; |
||||
|
||||
private String errMsg; |
||||
|
||||
private Integer errCode; |
||||
|
||||
private String verifyResult; |
||||
|
||||
private LocalDateTime createTime; |
||||
|
||||
} |
||||
@ -0,0 +1,71 @@
|
||||
package com.biutag.outer.domain; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import com.baomidou.mybatisplus.annotation.TableLogic; |
||||
import com.biutag.constants.Constants; |
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
import java.time.LocalDateTime; |
||||
|
||||
@Setter |
||||
@Getter |
||||
public class MailDraft { |
||||
|
||||
@TableId |
||||
private String id; |
||||
|
||||
/** |
||||
* 联系人姓名 |
||||
*/ |
||||
private String contactName; |
||||
|
||||
/** |
||||
* 联系人性别 |
||||
*/ |
||||
private String contactSex; |
||||
|
||||
/** |
||||
* 联系人身份证号码 |
||||
*/ |
||||
private String contactIdCard; |
||||
|
||||
/** |
||||
* |
||||
*/ |
||||
private String contactPhone; |
||||
|
||||
/** |
||||
* 案件编号 |
||||
*/ |
||||
private String caseNumber; |
||||
|
||||
/** |
||||
* 内容 |
||||
*/ |
||||
private String content; |
||||
|
||||
/** |
||||
* 附件 |
||||
*/ |
||||
private String attachments; |
||||
|
||||
/** |
||||
* 用户ID |
||||
*/ |
||||
private Integer userId; |
||||
|
||||
/** |
||||
* 创建时间 |
||||
*/ |
||||
private LocalDateTime createTime; |
||||
|
||||
/** |
||||
* 更新时间 |
||||
*/ |
||||
private LocalDateTime updateTime; |
||||
|
||||
@TableLogic(value = Constants.UNDELETED, delval = Constants.DELETED) |
||||
private String delFlag; |
||||
|
||||
} |
||||
@ -0,0 +1,26 @@
|
||||
package com.biutag.outer.domain; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
import java.time.LocalDateTime; |
||||
import java.util.Date; |
||||
|
||||
@Setter |
||||
@Getter |
||||
public class MailEvaluate { |
||||
|
||||
@TableId(type = IdType.AUTO) |
||||
private Integer id; |
||||
|
||||
private Integer userId; |
||||
|
||||
private String mailId; |
||||
|
||||
private String satisfaction; |
||||
|
||||
private LocalDateTime createTime; |
||||
|
||||
} |
||||
@ -0,0 +1,33 @@
|
||||
package com.biutag.outer.domain; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
import java.time.LocalDateTime; |
||||
|
||||
@Setter |
||||
@Getter |
||||
@TableName("\"user\"") |
||||
public class User { |
||||
|
||||
@TableId(type = IdType.AUTO) |
||||
private Integer id; |
||||
|
||||
private String openid; |
||||
|
||||
private String phone; |
||||
|
||||
private String realName; |
||||
|
||||
private String idCard; |
||||
|
||||
private LocalDateTime createTime; |
||||
|
||||
private LocalDateTime updateTime; |
||||
|
||||
private LocalDateTime faceAuthTime; |
||||
|
||||
} |
||||
@ -0,0 +1,41 @@
|
||||
package com.biutag.outer.domain.bo; |
||||
|
||||
import cn.hutool.core.bean.BeanUtil; |
||||
import com.alibaba.fastjson2.JSON; |
||||
import com.biutag.outer.domain.FaceAuth; |
||||
import com.biutag.outer.domain.Mail; |
||||
import com.biutag.validator.annotation.IdCard; |
||||
import jakarta.validation.constraints.NotBlank; |
||||
import jakarta.validation.constraints.NotNull; |
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
@Setter |
||||
@Getter |
||||
public class FaceAuthBo { |
||||
|
||||
@NotNull |
||||
private Integer userId; |
||||
|
||||
@NotBlank |
||||
private String realName; |
||||
|
||||
@IdCard |
||||
private String idCard; |
||||
|
||||
@NotBlank |
||||
private String errMsg; |
||||
|
||||
@NotNull |
||||
private Integer errCode; |
||||
|
||||
@NotBlank |
||||
private String verifyResult; |
||||
|
||||
public FaceAuth toEntity() { |
||||
FaceAuth faceAuth = new FaceAuth(); |
||||
BeanUtil.copyProperties(this, faceAuth); |
||||
return faceAuth; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,104 @@
|
||||
package com.biutag.outer.domain.bo; |
||||
|
||||
import cn.hutool.core.bean.BeanUtil; |
||||
import com.alibaba.fastjson2.JSON; |
||||
import com.biutag.outer.domain.Mail; |
||||
import com.biutag.outer.domain.MailDraft; |
||||
import com.biutag.validator.annotation.IdCard; |
||||
import com.biutag.validator.annotation.Phone; |
||||
import jakarta.validation.constraints.NotBlank; |
||||
import jakarta.validation.constraints.Size; |
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
import org.hibernate.validator.constraints.Length; |
||||
|
||||
import java.util.List; |
||||
|
||||
@Setter |
||||
@Getter |
||||
public class MailBo { |
||||
|
||||
private String id; |
||||
|
||||
/** |
||||
* 联系人姓名 |
||||
*/ |
||||
@NotBlank(message = "请输入联系人姓名") |
||||
private String contactName; |
||||
|
||||
/** |
||||
* 联系人性别 |
||||
*/ |
||||
@NotBlank(message = "请选择联系人称呼") |
||||
private String contactSex; |
||||
|
||||
/** |
||||
* 联系人身份证号码 |
||||
*/ |
||||
@IdCard |
||||
private String contactIdCard; |
||||
|
||||
/** |
||||
* |
||||
*/ |
||||
@Phone |
||||
private String contactPhone; |
||||
|
||||
@NotBlank(message = "短信验证码不能为空") |
||||
@Length(max = 4) |
||||
private String code; |
||||
|
||||
@NotBlank(message = "短信验证码错误或已失效") |
||||
private String smsRequestId; |
||||
|
||||
/** |
||||
* 案件编号 |
||||
*/ |
||||
private String caseNumber; |
||||
|
||||
/** |
||||
* 内容 |
||||
*/ |
||||
@Length(min= 10, max = 300, message = "信件内容不符合规范(不少于10字,不多于300字)") |
||||
@NotBlank(message = "请输入信件内容") |
||||
private String content; |
||||
|
||||
/** |
||||
* 附件 |
||||
*/ |
||||
@Size(max = 20, message = "附件数量不能超过20") |
||||
private List<Attachment> attachments; |
||||
|
||||
/** |
||||
* 涉及单位ID |
||||
*/ |
||||
private Integer involvedDeptId; |
||||
|
||||
/** |
||||
* 涉及单位名称 |
||||
*/ |
||||
private String involvedDeptName; |
||||
|
||||
public Mail toEntity() { |
||||
Mail mail = new Mail(); |
||||
BeanUtil.copyProperties(this, mail); |
||||
mail.setAttachments(JSON.toJSONString(attachments)); |
||||
return mail; |
||||
} |
||||
|
||||
public MailDraft toMailDraft() { |
||||
MailDraft mailDraft = new MailDraft(); |
||||
BeanUtil.copyProperties(this, mailDraft); |
||||
mailDraft.setAttachments(JSON.toJSONString(attachments)); |
||||
return mailDraft; |
||||
} |
||||
|
||||
@Setter |
||||
@Getter |
||||
public static class Attachment { |
||||
private String filepath; |
||||
private String filetype; |
||||
private String originFilename; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,26 @@
|
||||
package com.biutag.outer.domain.bo; |
||||
|
||||
import cn.hutool.core.bean.BeanUtil; |
||||
import com.biutag.outer.domain.MailEvaluate; |
||||
import jakarta.validation.constraints.NotNull; |
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
import org.apache.logging.log4j.core.config.plugins.validation.constraints.NotBlank; |
||||
|
||||
@Setter |
||||
@Getter |
||||
public class MailEvaluateBo { |
||||
|
||||
@NotNull |
||||
private String mailId; |
||||
|
||||
@NotBlank |
||||
private String satisfaction; |
||||
|
||||
public MailEvaluate toEntity() { |
||||
MailEvaluate evaluate = new MailEvaluate(); |
||||
BeanUtil.copyProperties(this, evaluate); |
||||
return evaluate; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,76 @@
|
||||
package com.biutag.outer.domain.vo; |
||||
|
||||
import cn.hutool.core.bean.BeanUtil; |
||||
import cn.hutool.core.date.DateUtil; |
||||
import com.biutag.outer.domain.MailDraft; |
||||
import com.fasterxml.jackson.annotation.JsonFormat; |
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
import java.time.LocalDateTime; |
||||
import java.util.Date; |
||||
|
||||
@Setter |
||||
@Getter |
||||
public class MailDraftVo { |
||||
|
||||
private String id; |
||||
|
||||
/** |
||||
* 联系人姓名 |
||||
*/ |
||||
private String contactName; |
||||
|
||||
/** |
||||
* 联系人性别 |
||||
*/ |
||||
private String contactSex; |
||||
|
||||
/** |
||||
* 联系人身份证号码 |
||||
*/ |
||||
private String contactIdCard; |
||||
|
||||
/** |
||||
* |
||||
*/ |
||||
private String contactPhone; |
||||
|
||||
/** |
||||
* 案件编号 |
||||
*/ |
||||
private String caseNumber; |
||||
|
||||
/** |
||||
* 内容 |
||||
*/ |
||||
private String content; |
||||
|
||||
/** |
||||
* 附件 |
||||
*/ |
||||
private String attachments; |
||||
|
||||
/** |
||||
* 用户ID |
||||
*/ |
||||
private Integer userId; |
||||
|
||||
/** |
||||
* 创建时间 |
||||
*/ |
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
private LocalDateTime createTime; |
||||
|
||||
private String title; |
||||
|
||||
public static MailDraftVo of(MailDraft draft) { |
||||
MailDraftVo vo = new MailDraftVo(); |
||||
BeanUtil.copyProperties(draft, vo); |
||||
if (draft != null) { |
||||
vo.setTitle(String.format("%s我写的信", DateUtil.format(draft.getCreateTime(), "yyyy年MM月dd日HH时"))); |
||||
} |
||||
return vo; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,89 @@
|
||||
package com.biutag.outer.domain.vo; |
||||
|
||||
import cn.hutool.core.bean.BeanUtil; |
||||
import cn.hutool.core.date.DateUtil; |
||||
import com.biutag.outer.domain.Mail; |
||||
import com.fasterxml.jackson.annotation.JsonFormat; |
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
import java.time.LocalDateTime; |
||||
import java.util.Date; |
||||
|
||||
@Setter |
||||
@Getter |
||||
public class MailVo { |
||||
|
||||
private String id; |
||||
|
||||
/** |
||||
* 联系人姓名 |
||||
*/ |
||||
private String contactName; |
||||
|
||||
/** |
||||
* 联系人性别 |
||||
*/ |
||||
private String contactSex; |
||||
|
||||
/** |
||||
* 联系人身份证号码 |
||||
*/ |
||||
private String contactIdCard; |
||||
|
||||
/** |
||||
* |
||||
*/ |
||||
private String contactPhone; |
||||
|
||||
/** |
||||
* 案件编号 |
||||
*/ |
||||
private String caseNumber; |
||||
|
||||
/** |
||||
* 内容 |
||||
*/ |
||||
private String content; |
||||
|
||||
/** |
||||
* 附件 |
||||
*/ |
||||
private String attachments; |
||||
|
||||
/** |
||||
* 用户ID |
||||
*/ |
||||
private Integer userId; |
||||
|
||||
/** |
||||
* 创建时间 |
||||
*/ |
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
private LocalDateTime createTime; |
||||
|
||||
/** |
||||
* 是否满意 |
||||
*/ |
||||
private String satisfaction; |
||||
|
||||
private String title; |
||||
|
||||
/** |
||||
* 涉及单位ID |
||||
*/ |
||||
private Integer involvedDeptId; |
||||
|
||||
/** |
||||
* 涉及单位名称 |
||||
*/ |
||||
private String involvedDeptName; |
||||
|
||||
public static MailVo of(Mail mail) { |
||||
MailVo vo = new MailVo(); |
||||
BeanUtil.copyProperties(mail, vo); |
||||
vo.setTitle(String.format("%s我写的信", DateUtil.format(mail.getCreateTime(), "yyyy年MM月dd日HH时"))); |
||||
return vo; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,9 @@
|
||||
package com.biutag.outer.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.biutag.outer.domain.FaceAuth; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
|
||||
@Mapper |
||||
public interface FaceAuthMapper extends BaseMapper<FaceAuth> { |
||||
} |
||||
@ -0,0 +1,11 @@
|
||||
package com.biutag.outer.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.biutag.outer.domain.Mail; |
||||
import com.biutag.outer.domain.MailDraft; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
import org.apache.ibatis.annotations.Select; |
||||
|
||||
@Mapper |
||||
public interface MailDraftMapper extends BaseMapper<MailDraft> { |
||||
} |
||||
@ -0,0 +1,9 @@
|
||||
package com.biutag.outer.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.biutag.outer.domain.MailEvaluate; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
|
||||
@Mapper |
||||
public interface MailEvaluateMapper extends BaseMapper<MailEvaluate> { |
||||
} |
||||
@ -0,0 +1,9 @@
|
||||
package com.biutag.outer.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.biutag.outer.domain.User; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
|
||||
@Mapper |
||||
public interface UserMapper extends BaseMapper<User> { |
||||
} |
||||
@ -0,0 +1,34 @@
|
||||
package com.biutag.outer.service; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import com.biutag.outer.domain.FaceAuth; |
||||
import com.biutag.outer.domain.User; |
||||
import com.biutag.outer.domain.bo.FaceAuthBo; |
||||
import com.biutag.outer.mapper.FaceAuthMapper; |
||||
import lombok.RequiredArgsConstructor; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.transaction.annotation.Transactional; |
||||
|
||||
import java.time.LocalDateTime; |
||||
|
||||
@RequiredArgsConstructor |
||||
@Service |
||||
public class FaceAuthService extends ServiceImpl<FaceAuthMapper, FaceAuth> { |
||||
|
||||
private final UserService userService; |
||||
|
||||
@Transactional(rollbackFor = Exception.class) |
||||
public boolean save(FaceAuthBo faceAuthBo) { |
||||
LocalDateTime now = LocalDateTime.now(); |
||||
FaceAuth faceAuth = faceAuthBo.toEntity(); |
||||
faceAuth.setCreateTime(now); |
||||
save(faceAuth); |
||||
return userService.update(new LambdaUpdateWrapper<User>() |
||||
.eq(User::getId, faceAuth.getUserId()) |
||||
.set(User::getRealName, faceAuth.getRealName()) |
||||
.set(User::getIdCard, faceAuth.getIdCard()) |
||||
.set(User::getFaceAuthTime, now) |
||||
.set(User::getUpdateTime, now)); |
||||
} |
||||
} |
||||
@ -0,0 +1,46 @@
|
||||
package com.biutag.outer.service; |
||||
|
||||
import cn.hutool.core.util.IdUtil; |
||||
import cn.hutool.core.util.StrUtil; |
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import com.biutag.outer.domain.MailDraft; |
||||
import com.biutag.outer.domain.bo.MailBo; |
||||
import com.biutag.outer.domain.vo.MailDraftVo; |
||||
import com.biutag.outer.mapper.MailDraftMapper; |
||||
import com.biutag.outer.util.UserHelper; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.time.LocalDateTime; |
||||
import java.util.Date; |
||||
|
||||
import static java.util.stream.Collectors.toList; |
||||
|
||||
@Service |
||||
public class MailDraftService extends ServiceImpl<MailDraftMapper, MailDraft> { |
||||
|
||||
public MailDraft save(MailBo mailBo) { |
||||
MailDraft mailDraft = mailBo.toMailDraft(); |
||||
if (StrUtil.isBlank(mailDraft.getId())) { |
||||
mailDraft.setId(IdUtil.simpleUUID()); |
||||
} |
||||
mailDraft.setCreateTime(LocalDateTime.now()); |
||||
mailDraft.setUpdateTime(mailDraft.getCreateTime()); |
||||
mailDraft.setUserId(UserHelper.getCurrentUserId()); |
||||
saveOrUpdate(mailDraft); |
||||
return mailDraft; |
||||
} |
||||
|
||||
public Page<MailDraftVo> listByCurrentUserId(Page<MailDraft> page) { |
||||
LambdaQueryWrapper<MailDraft> queryWrapper = new LambdaQueryWrapper<MailDraft>() |
||||
.eq(MailDraft::getUserId, UserHelper.getCurrentUserId()) |
||||
.orderByDesc(MailDraft::getCreateTime); |
||||
Page<MailDraft> mailDraftPage = page(page, queryWrapper); |
||||
Page<MailDraftVo> voPage = new Page<>(); |
||||
voPage.setTotal(mailDraftPage.getTotal()) |
||||
.setRecords(mailDraftPage.getRecords().stream().map(MailDraftVo::of).collect(toList())); |
||||
return voPage; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,10 @@
|
||||
package com.biutag.outer.service; |
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import com.biutag.outer.domain.MailEvaluate; |
||||
import com.biutag.outer.mapper.MailEvaluateMapper; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
@Service |
||||
public class MailEvaluateService extends ServiceImpl<MailEvaluateMapper, MailEvaluate> { |
||||
} |
||||
@ -1,10 +1,82 @@
|
||||
package com.biutag.outer.service; |
||||
|
||||
import cn.hutool.core.date.DateUtil; |
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import com.biutag.outer.domain.Mail; |
||||
import com.biutag.outer.domain.MailDraft; |
||||
import com.biutag.outer.domain.MailEvaluate; |
||||
import com.biutag.outer.domain.bo.MailBo; |
||||
import com.biutag.outer.domain.bo.MailEvaluateBo; |
||||
import com.biutag.outer.domain.vo.MailDraftVo; |
||||
import com.biutag.outer.domain.vo.MailVo; |
||||
import com.biutag.outer.mapper.MailMapper; |
||||
import com.biutag.outer.util.UserHelper; |
||||
import lombok.RequiredArgsConstructor; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.transaction.annotation.Transactional; |
||||
|
||||
import java.time.LocalDateTime; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
|
||||
import static java.util.stream.Collectors.toList; |
||||
|
||||
@RequiredArgsConstructor |
||||
@Service |
||||
public class MailService extends ServiceImpl<MailMapper, Mail> { |
||||
|
||||
public final MailEvaluateService mailEvaluateService; |
||||
|
||||
public final MailDraftService mailDraftService; |
||||
|
||||
public final UserService userService; |
||||
|
||||
@Transactional(rollbackFor = Exception.class) |
||||
public boolean save(MailBo mailBo) { |
||||
Mail mail = mailBo.toEntity(); |
||||
mail.setId(generateMailId()); |
||||
mail.setCreateTime(LocalDateTime.now()); |
||||
mail.setUserId(UserHelper.getCurrentUserId()); |
||||
boolean save = save(mail); |
||||
if (save) { |
||||
userService.updatePhoneByCurrent(mailBo.getContactPhone()); |
||||
} |
||||
return save; |
||||
} |
||||
|
||||
@Transactional(rollbackFor = Exception.class) |
||||
public boolean evaluate(MailEvaluateBo evaluateBo) { |
||||
MailEvaluate evaluate = evaluateBo.toEntity(); |
||||
evaluate.setCreateTime(LocalDateTime.now()); |
||||
evaluate.setUserId(UserHelper.getCurrentUserId()); |
||||
mailEvaluateService.save(evaluate); |
||||
Mail mail = new Mail(); |
||||
mail.setId(evaluateBo.getMailId()); |
||||
mail.setSatisfaction(evaluateBo.getSatisfaction()); |
||||
return updateById(mail); |
||||
} |
||||
|
||||
public String generateMailId() { |
||||
Integer seqVal = baseMapper.getMailIdSeqVal(); |
||||
int length = 6 - seqVal.toString().length(); |
||||
StringBuilder zeroString = new StringBuilder(); |
||||
for (int i = 0; i < length; i++) { |
||||
zeroString.append('0'); |
||||
} |
||||
return DateUtil.format(new Date(), "yyyyMMddHHMM") + zeroString + seqVal; |
||||
} |
||||
|
||||
public Page<MailVo> listByCurrentUserId(Page<Mail> page) { |
||||
LambdaQueryWrapper<Mail> queryWrapper = new LambdaQueryWrapper<Mail>() |
||||
.eq(Mail::getUserId, UserHelper.getCurrentUserId()) |
||||
.orderByDesc(Mail::getCreateTime); |
||||
Page<Mail> mailPage = page(page, queryWrapper); |
||||
Page<MailVo> voPage = new Page<>(); |
||||
voPage.setTotal(mailPage.getTotal()) |
||||
.setRecords(mailPage.getRecords().stream().map(MailVo::of).collect(toList())); |
||||
return voPage; |
||||
} |
||||
|
||||
} |
||||
|
||||
@ -0,0 +1,30 @@
|
||||
package com.biutag.outer.service; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import com.biutag.outer.domain.User; |
||||
import com.biutag.outer.mapper.UserMapper; |
||||
import com.biutag.outer.util.UserHelper; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
@Service |
||||
public class UserService extends ServiceImpl<UserMapper, User> { |
||||
|
||||
public User getByOpenid(String openid) { |
||||
return getOne(new LambdaQueryWrapper<User>().eq(User::getOpenid, openid)); |
||||
} |
||||
|
||||
public boolean updatePhoneByCurrent(String phone) { |
||||
User currentUser = UserHelper.getCurrentUser(); |
||||
boolean updated = update(new LambdaUpdateWrapper<User>().eq(User::getId, currentUser.getId()).set(User::getPhone, phone)); |
||||
if (updated) { |
||||
currentUser.setPhone(phone); |
||||
// 更新缓存
|
||||
UserHelper.update(currentUser); |
||||
} |
||||
return updated; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,28 @@
|
||||
package com.biutag.outer.util; |
||||
|
||||
import cn.hutool.core.util.IdUtil; |
||||
import com.github.benmanes.caffeine.cache.Cache; |
||||
import com.github.benmanes.caffeine.cache.Caffeine; |
||||
|
||||
import java.util.concurrent.TimeUnit; |
||||
|
||||
public class CodeUtil { |
||||
|
||||
private static final Cache<String, String> cache = Caffeine.newBuilder() |
||||
.expireAfterWrite(5, TimeUnit.MINUTES) // 设置写入后过期时间
|
||||
.maximumSize(1000) // 最多1000人
|
||||
.build(); |
||||
|
||||
|
||||
|
||||
public static String set(String code) { |
||||
String key = IdUtil.fastSimpleUUID(); |
||||
cache.put(key, code); |
||||
return key; |
||||
} |
||||
|
||||
public static String get(String key) { |
||||
return cache.getIfPresent(key); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,62 @@
|
||||
package com.biutag.outer.util; |
||||
|
||||
import com.alibaba.fastjson2.JSON; |
||||
import com.alibaba.fastjson2.JSONObject; |
||||
import com.aliyun.auth.credentials.Credential; |
||||
import com.aliyun.auth.credentials.provider.StaticCredentialProvider; |
||||
import com.aliyun.sdk.service.dysmsapi20170525.AsyncClient; |
||||
import com.aliyun.sdk.service.dysmsapi20170525.models.SendSmsRequest; |
||||
import com.aliyun.sdk.service.dysmsapi20170525.models.SendSmsResponse; |
||||
import darabonba.core.client.ClientOverrideConfiguration; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
import java.util.concurrent.CompletableFuture; |
||||
import java.util.concurrent.ExecutionException; |
||||
|
||||
@Slf4j |
||||
public class Sms { |
||||
|
||||
public static void send(String phoneNumber, String code) { |
||||
log.info("手机号:{}, 短信验证码:{}", phoneNumber, code); |
||||
String accessKeyId = "LTAI5tS4QJAGMqNCYvsGkXs6"; |
||||
String accessKeySecret = "PGN12Bm5LYihcC5j3dzIqDdvssJ7XY"; |
||||
StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder() |
||||
// Please ensure that the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set.
|
||||
.accessKeyId(accessKeyId) |
||||
.accessKeySecret(accessKeySecret) |
||||
//.securityToken(System.getenv("ALIBABA_CLOUD_SECURITY_TOKEN")) // use STS token
|
||||
.build()); |
||||
|
||||
// Configure the Client
|
||||
AsyncClient client = AsyncClient.builder() |
||||
//.httpClient(httpClient) // Use the configured HttpClient, otherwise use the default HttpClient (Apache HttpClient)
|
||||
.credentialsProvider(provider) |
||||
//.serviceConfiguration(Configuration.create()) // Service-level configuration
|
||||
// Client-level configuration rewrite, can set Endpoint, Http request parameters, etc.
|
||||
.overrideConfiguration( |
||||
ClientOverrideConfiguration.create() |
||||
// Endpoint 请参考 https://api.aliyun.com/product/Dysmsapi
|
||||
.setEndpointOverride("dysmsapi.aliyuncs.com") |
||||
//.setConnectTimeout(Duration.ofSeconds(30))
|
||||
) |
||||
.build(); |
||||
// Parameter settings for API request
|
||||
SendSmsRequest sendSmsRequest = SendSmsRequest.builder() |
||||
.phoneNumbers(phoneNumber) |
||||
.signName("长沙创客软件") |
||||
.templateCode("SMS_294115479") |
||||
.templateParam(JSONObject.of("code", code).toJSONString()) |
||||
|
||||
// Request-level configuration rewrite, can set Http request parameters, etc.
|
||||
// .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders()))
|
||||
.build(); |
||||
|
||||
// Asynchronously get the return value of the API request
|
||||
CompletableFuture<SendSmsResponse> response = client.sendSms(sendSmsRequest); |
||||
try { |
||||
log.info("手机号:{}, 发送短信结果:{}", phoneNumber, JSON.toJSONString(response.get())); |
||||
} catch (ExecutionException | InterruptedException e) { |
||||
log.error(e.getMessage(), e); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,32 @@
|
||||
package com.biutag.outer.util; |
||||
|
||||
import cn.hutool.core.util.IdUtil; |
||||
import com.biutag.outer.domain.User; |
||||
import com.github.benmanes.caffeine.cache.Cache; |
||||
import com.github.benmanes.caffeine.cache.Caffeine; |
||||
import org.springframework.util.Assert; |
||||
|
||||
import java.util.concurrent.TimeUnit; |
||||
|
||||
public class TokenUtil { |
||||
private static final Cache<String, User> cache = Caffeine.newBuilder() |
||||
.expireAfterWrite(60, TimeUnit.MINUTES) // 设置写入后过期时间
|
||||
.maximumSize(1000) // 最多1000人
|
||||
.build(); |
||||
public static String set(User user) { |
||||
Assert.notNull(user, "未找到该用户"); |
||||
String key = IdUtil.fastSimpleUUID(); |
||||
cache.put(key, user); |
||||
return key; |
||||
} |
||||
|
||||
public static User update(String key, User user) { |
||||
cache.put(key, user); |
||||
return user; |
||||
} |
||||
|
||||
public static User get(String key) { |
||||
return cache.getIfPresent(key); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,33 @@
|
||||
package com.biutag.outer.util; |
||||
|
||||
import com.biutag.exception.AuthException; |
||||
import com.biutag.outer.domain.User; |
||||
import jakarta.servlet.http.HttpServletRequest; |
||||
import org.springframework.web.context.request.RequestContextHolder; |
||||
import org.springframework.web.context.request.ServletRequestAttributes; |
||||
|
||||
public class UserHelper { |
||||
|
||||
public static User getCurrentUser() { |
||||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); |
||||
// 获取请求头的值
|
||||
String authorization = request.getHeader("Authorization"); |
||||
User user = TokenUtil.get(authorization); |
||||
if (user == null) { |
||||
throw new AuthException(); |
||||
} |
||||
return user; |
||||
} |
||||
|
||||
public static User update(User user) { |
||||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); |
||||
// 获取请求头的值
|
||||
String authorization = request.getHeader("Authorization"); |
||||
return TokenUtil.update(authorization, user); |
||||
} |
||||
|
||||
public static Integer getCurrentUserId() { |
||||
return getCurrentUser().getId(); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,86 @@
|
||||
package com.biutag.outer.util; |
||||
|
||||
import cn.hutool.core.util.StrUtil; |
||||
import cn.hutool.http.HttpResponse; |
||||
import cn.hutool.http.HttpUtil; |
||||
import com.alibaba.fastjson2.JSON; |
||||
import com.alibaba.fastjson2.JSONObject; |
||||
import com.biutag.exception.BusinessException; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
import java.security.MessageDigest; |
||||
import java.security.NoSuchAlgorithmException; |
||||
|
||||
@Slf4j |
||||
public class Weixin { |
||||
|
||||
// 优客智能家
|
||||
private static final String APP_ID = "wx795f76e4bc3b0062"; |
||||
public static final String SECRET = "7596544a77776be53d10fd78a7b4a441"; |
||||
|
||||
public static JSONObject getAccessToken(String code) { |
||||
// https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=SECRET&code=%s&grant_type=authorization_code
|
||||
String url = String.format("https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code", |
||||
APP_ID, |
||||
SECRET, |
||||
code); |
||||
HttpResponse httpResponse = HttpUtil.createGet(url) |
||||
.execute(); |
||||
JSONObject data = JSON.parseObject(httpResponse.body()); |
||||
if (StrUtil.isBlank(data.getString("access_token"))) { |
||||
log.error("response: {}", JSON.toJSONString(data)); |
||||
throw new BusinessException("微信授权失败,code: " + data.getInteger("errcode")); |
||||
} |
||||
return data; |
||||
} |
||||
|
||||
public static JSONObject getAccessToken() { |
||||
String url = String.format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s", |
||||
APP_ID, |
||||
SECRET); |
||||
HttpResponse httpResponse = HttpUtil.createGet(url) |
||||
.execute(); |
||||
JSONObject data = JSON.parseObject(httpResponse.body()); |
||||
if (StrUtil.isBlank(data.getString("access_token"))) { |
||||
log.error("response: {}", JSON.toJSONString(data)); |
||||
throw new BusinessException("微信获取 access_token 异常,code: " + data.getInteger("errcode")); |
||||
} |
||||
return data; |
||||
} |
||||
|
||||
public static String getTicket() { |
||||
JSONObject result = getAccessToken(); |
||||
String url = String.format("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=%s&type=jsapi", |
||||
result.getString("access_token")); |
||||
HttpResponse httpResponse = HttpUtil.createGet(url) |
||||
.execute(); |
||||
JSONObject data = JSON.parseObject(httpResponse.body()); |
||||
String ticket = data.getString("ticket"); |
||||
if (StrUtil.isBlank(ticket)) { |
||||
log.error("response: {}", JSON.toJSONString(data)); |
||||
throw new BusinessException("微信获取 tiket 异常,code: " + data.getInteger("errcode")); |
||||
} |
||||
return ticket; |
||||
} |
||||
|
||||
public static String sign(String noncestr, String jsapiTicket, long timestamp, String url) { |
||||
String input = String.format("jsapi_ticket=%s&noncestr=%s×tamp=%s&url=%s", jsapiTicket, noncestr, timestamp, url); |
||||
try { |
||||
String sign = generateSHA1(input); |
||||
return sign; |
||||
} catch (NoSuchAlgorithmException e) { |
||||
throw new BusinessException(e.getCause()); |
||||
} |
||||
} |
||||
|
||||
public static String generateSHA1(String input) throws NoSuchAlgorithmException { |
||||
MessageDigest md = MessageDigest.getInstance("SHA-1"); |
||||
byte[] digest = md.digest(input.getBytes()); |
||||
StringBuilder hexString = new StringBuilder(); |
||||
for (byte b : digest) { |
||||
hexString.append(String.format("%02x", b)); |
||||
} |
||||
return hexString.toString(); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,90 @@
|
||||
package com.biutag.outer.util; |
||||
|
||||
import cn.hutool.core.util.StrUtil; |
||||
import cn.hutool.http.HttpResponse; |
||||
import cn.hutool.http.HttpUtil; |
||||
import com.alibaba.fastjson2.JSON; |
||||
import com.alibaba.fastjson2.JSONObject; |
||||
import com.biutag.exception.BusinessException; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
import java.security.MessageDigest; |
||||
import java.security.NoSuchAlgorithmException; |
||||
|
||||
@Slf4j |
||||
public class Weixin2 { |
||||
|
||||
// 优客智能家
|
||||
// private static final String APP_ID = "wx795f76e4bc3b0062";
|
||||
// public static final String SECRET = "7596544a77776be53d10fd78a7b4a441";
|
||||
|
||||
// 博麟智渊
|
||||
private static final String APP_ID = "wx03c2abbf3291a7c7"; |
||||
public static final String SECRET = "4d6bc9ab9821f642d185b353893b44ea"; |
||||
|
||||
public static JSONObject getAccessToken(String code) { |
||||
// https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=SECRET&code=%s&grant_type=authorization_code
|
||||
String url = String.format("https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code", |
||||
APP_ID, |
||||
SECRET, |
||||
code); |
||||
HttpResponse httpResponse = HttpUtil.createGet(url) |
||||
.execute(); |
||||
JSONObject data = JSON.parseObject(httpResponse.body()); |
||||
if (StrUtil.isBlank(data.getString("access_token"))) { |
||||
log.error("response: {}", JSON.toJSONString(data)); |
||||
throw new BusinessException("微信授权失败,code: " + data.getInteger("errcode")); |
||||
} |
||||
return data; |
||||
} |
||||
|
||||
public static JSONObject getAccessToken() { |
||||
String url = String.format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s", |
||||
APP_ID, |
||||
SECRET); |
||||
HttpResponse httpResponse = HttpUtil.createGet(url) |
||||
.execute(); |
||||
JSONObject data = JSON.parseObject(httpResponse.body()); |
||||
if (StrUtil.isBlank(data.getString("access_token"))) { |
||||
log.error("response: {}", JSON.toJSONString(data)); |
||||
throw new BusinessException("微信获取 access_token 异常,code: " + data.getInteger("errcode")); |
||||
} |
||||
return data; |
||||
} |
||||
|
||||
public static String getTicket() { |
||||
JSONObject result = getAccessToken(); |
||||
String url = String.format("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=%s&type=jsapi", |
||||
result.getString("access_token")); |
||||
HttpResponse httpResponse = HttpUtil.createGet(url) |
||||
.execute(); |
||||
JSONObject data = JSON.parseObject(httpResponse.body()); |
||||
String ticket = data.getString("ticket"); |
||||
if (StrUtil.isBlank(ticket)) { |
||||
log.error("response: {}", JSON.toJSONString(data)); |
||||
throw new BusinessException("微信获取 tiket 异常,code: " + data.getInteger("errcode")); |
||||
} |
||||
return ticket; |
||||
} |
||||
|
||||
public static String sign(String noncestr, String jsapiTicket, long timestamp, String url) { |
||||
String input = String.format("jsapi_ticket=%s&noncestr=%s×tamp=%s&url=%s", jsapiTicket, noncestr, timestamp, url); |
||||
try { |
||||
String sign = generateSHA1(input); |
||||
return sign; |
||||
} catch (NoSuchAlgorithmException e) { |
||||
throw new BusinessException(e.getCause()); |
||||
} |
||||
} |
||||
|
||||
public static String generateSHA1(String input) throws NoSuchAlgorithmException { |
||||
MessageDigest md = MessageDigest.getInstance("SHA-1"); |
||||
byte[] digest = md.digest(input.getBytes()); |
||||
StringBuilder hexString = new StringBuilder(); |
||||
for (byte b : digest) { |
||||
hexString.append(String.format("%02x", b)); |
||||
} |
||||
return hexString.toString(); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,42 @@
|
||||
server: |
||||
port: 8081 |
||||
tongweb: |
||||
license: |
||||
path: license/license.dat |
||||
|
||||
spring: |
||||
profiles: |
||||
active: dev |
||||
mvc: |
||||
static-path-pattern: /api/static/** |
||||
throw-exception-if-no-handler-found: true |
||||
pathmatch: |
||||
matching-strategy: ant_path_matcher |
||||
datasource: |
||||
driver-class-name: org.postgresql.Driver |
||||
url: jdbc:postgresql://172.31.217.20:32378/mailbox?currentSchema=mailbox |
||||
username: mailbox |
||||
password: Ip12341234 |
||||
hikari: |
||||
connection-timeout: 30000 # 等待连接分配连接的最大时长(毫秒),超出时长还没可用连接则发送SQLException,默认30秒 |
||||
minimum-idle: 5 # 最小连接数 |
||||
maximum-pool-size: 20 # 最大连接数 |
||||
auto-commit: true # 自动提交 |
||||
idle-timeout: 600000 # 连接超时的最大时长(毫秒),超时则被释放(retired),默认10分钟 |
||||
pool-name: DateSourceHikariCP # 连接池名称 |
||||
max-lifetime: 1800000 # 连接的生命时长(毫秒),超时而且没被使用则被释放,默认30分钟(1800000ms) |
||||
connection-init-sql: SELECT 1 # 连接时发起SQL测试脚本 |
||||
# 限制配置 |
||||
servlet: |
||||
multipart: |
||||
max-file-size: 100MB # 文件上传大小限制 |
||||
max-request-size: 100MB # 文件最大请求限制 |
||||
enabled: true |
||||
# Redis配置 |
||||
data: |
||||
redis: |
||||
timeout: 5000 |
||||
host: 192.168.48.231 |
||||
port: 6379 |
||||
password: yuanian |
||||
database: 100 |
||||
@ -1,42 +1,27 @@
|
||||
server: |
||||
port: 8081 |
||||
port: 8080 |
||||
tongweb: |
||||
license: |
||||
path: license/license.dat |
||||
path: classpath:license/license.dat |
||||
|
||||
spring: |
||||
profiles: |
||||
active: dev |
||||
mvc: |
||||
static-path-pattern: /api/static/** |
||||
throw-exception-if-no-handler-found: true |
||||
pathmatch: |
||||
matching-strategy: ant_path_matcher |
||||
servlet: |
||||
multipart: |
||||
max-file-size: 10MB |
||||
max-request-size: 10MB |
||||
datasource: |
||||
driver-class-name: org.postgresql.Driver |
||||
url: jdbc:postgresql://172.31.217.20:32378/mailbox?currentSchema=mailbox |
||||
username: mailbox |
||||
url: jdbc:postgresql://172.31.217.20:32378/mailbox?currentSchema=mailbox-outer |
||||
username: vbadmin |
||||
password: Ip12341234 |
||||
hikari: |
||||
connection-timeout: 30000 # 等待连接分配连接的最大时长(毫秒),超出时长还没可用连接则发送SQLException,默认30秒 |
||||
minimum-idle: 5 # 最小连接数 |
||||
maximum-pool-size: 20 # 最大连接数 |
||||
auto-commit: true # 自动提交 |
||||
idle-timeout: 600000 # 连接超时的最大时长(毫秒),超时则被释放(retired),默认10分钟 |
||||
pool-name: DateSourceHikariCP # 连接池名称 |
||||
max-lifetime: 1800000 # 连接的生命时长(毫秒),超时而且没被使用则被释放,默认30分钟(1800000ms) |
||||
connection-init-sql: SELECT 1 # 连接时发起SQL测试脚本 |
||||
# 限制配置 |
||||
servlet: |
||||
multipart: |
||||
max-file-size: 100MB # 文件上传大小限制 |
||||
max-request-size: 100MB # 文件最大请求限制 |
||||
enabled: true |
||||
# Redis配置 |
||||
data: |
||||
redis: |
||||
timeout: 5000 |
||||
host: 192.168.48.231 |
||||
port: 6379 |
||||
password: yuanian |
||||
database: 100 |
||||
|
||||
mybatis-plus: |
||||
configuration: |
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl |
||||
|
||||
oss: |
||||
minio: |
||||
endpoint: http://172.31.217.20:31401 |
||||
accessKey: n8yPVAJk4yw879zi |
||||
secretKey: eElQ7gCwuNxaFhKEbtRRq0lsovoOTgI1 |
||||
bucketName: mailbox |
||||
@ -0,0 +1 @@
|
||||
uc3Y29XJfVtZtZTbmFsTP26/w7Lzq+nBy7WClY3b2pmFtRfb6/sZT2+7ETPzKxev8rGljQKbzZVZW5D039pZxMwNjYWNlpsalX3bnNGU9R5cpYWdHJ3JlwKYlX2YXRGU9RhdyMyMjAi0w0xMlbmNQpGF0RfZyMDZT0TAzI0L1ClLTA1ByRXX1Y3b2RmFtRfTUb2ZT12Vi5nVXX1ClRnNpZlcfTnb25mVyVtYuMCPTclRX5FCQVVX0N1VO9DTKYmVD0GlwluZUV1PQpXJk9IYyZVd2FD0K9JZfTWVFd051F4XlcjbWJQpU0tMMaWV19nNlNlblcnX1Nl9WZlczaWZXJTQu9uPwClMi419QRIUkdWcm905hN0X9VGbWU0h09uZTZXdHBXIKJ2ZTX1VEhnNpZlcfTnb25mVyVtYuMAPTY19FpUV0aWZGlUVt9uPkCkYmV19W5FVTSURVJ0xJ9OXOQ0Q0VFJGU9UYSkS1hzlWJUKLOHZ0pllDBHZ2aDdEdVllZTW0d2RlRXpxpTTkZTNzZ2ladVKjN0UmNjRKJvdJd0K0hDI2tzNBOEcG1EtFVFZvQ3NWkDlrhWW0OXVnkS9BVYTIT2VmdmROxJRjemeC9UZZ9FcXeFV0h0YzdXYKOXL2xVAKowWXX1TkVlNJZFUfTET05U5DlDRIQ0RT10d3tRKGY2OGVHVRdkb3VXSUIXp1NTTyc0WVk3BxpMNhZkOXhGNSE2VDMEUnBjNk1EWiaEUDN1dYplLLYVdm51VtpkVsMmZi9GE5E3cyZEZjkWlQ9McCRlbENTFDhydwdEdGM2hGNqdzOWWncEFqg5MGUHbDRVowNxapbAY3ZVdfpORSU0VkVl9MlPTFTkSUNWNyNFPaM1T0llQ1BjTaM2OW5jJUw4W4ZGYk5Xd392bsMHV3NGVRNGWwTDeTlEsyJYVyVkUUx21j5Dd2QlWFcjdDNOepb3SUlTArhpeLTVMFFVlMNLNpS3ek9Uhah1VEOUb2lmx242VRcVWW92dUl6cTZUMlFmVp5XTMb0MlRmpmtOVFV1Ck5VJT9WROX0SU90VOxJQ9aiQ0UFlltjdPSDSUtGpKR1SiZlVWVEpGpIdiQ0WCtzlU5LVyakdjFE9TJuRwcFK0EUpQQ4YwRTUEpjMrFITIejQm11VxVoZ1NEcS9DZ5xQMzTlUFInZ1l3dIeXdjd2ZwI5QDSGbzl1dKZDL0aTQ1M2MylyZtWlZnlEl0JpSnZkQjJkVXsKTFUlX1Z05fNJTDRUTElV9T5DR9V2VU40o4txMjWkL1l3ZZVvVvMjUmQWhidjQ2bDOTdkNucvamNkS0xTZEYwVaVkTEFnIztPMxdkK2lHZM9jM2RTeUoXlzZma0NEMjU3VNJqazMFQXAys4B5ZNV3WGtDh4dxR6TEcHdlFUplduaET2hXVphTemZGWnlHdPR1O0c2ckZkVX8KTFUlX1Z05fNJTDRUTElV9T5DR9MjVU4m1jl5Q6RSTnd0lv94dYNkaEFm1hxuThR0T1BGNFtzaYc3cGlFVBh1dCWlZkJmhFBHeFdDemtjh6dCd0RmQ24jdjFyZwVHU0Z3NQVKb3U3RFFUhaFuTxYWRnZlRuVlWkMGZVVUxY5hYRSGcEhlF2MrWwUTZGxW5tczdONHdmNkVXAKTFUlX1Z05fNJTDRUTElV9T5DR9TkVU4zJOZYZMK1cUNldSc1dNQ3M29GNQdFZvUHemY1MxJFY3dFZ2UjZDlEQzeCM2QXZ2t6YWbkNjNkdEZUd3ajVkRzBhJ5QGeUOC9GFok1TsT2TWFVIvV1ZLMVUHJXZpBCM4b3MnN0MwJEY2akaFIVYyVLWyNzRGIVVYhoZhUiZTBkVX8KTFUlX1Z05fNJTDRUTElV9T5DR9aTVU4zNUlNUVSUajdG5SZVOOMGcmVCt6lWeLS1d1lnk4VTbFOWWmlWQ0E4UIOUME9EdHdWOScTYlJ1MvUyR0NmZW8kFvZ3S0ZmMDQ2xH1UT6V1VlFHk3Qwd1UDTlgkppB3WwVULzBVZrowOtWFaUVFJ0dDaTZWS3p1RXVVQOdTSld YK |
||||
@ -0,0 +1,58 @@
|
||||
package com.biutag.outer; |
||||
|
||||
import com.alibaba.fastjson2.JSONObject; |
||||
import com.aliyun.auth.credentials.Credential; |
||||
import com.aliyun.auth.credentials.provider.StaticCredentialProvider; |
||||
import com.aliyun.sdk.service.dysmsapi20170525.AsyncClient; |
||||
import com.aliyun.sdk.service.dysmsapi20170525.models.SendSmsRequest; |
||||
import com.aliyun.sdk.service.dysmsapi20170525.models.SendSmsResponse; |
||||
import darabonba.core.client.ClientOverrideConfiguration; |
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
import java.util.concurrent.CompletableFuture; |
||||
import java.util.concurrent.ExecutionException; |
||||
|
||||
public class SmsTest { |
||||
|
||||
@Test |
||||
public void testSend() throws ExecutionException, InterruptedException { |
||||
String accessKeyId = "LTAI5tS4QJAGMqNCYvsGkXs6"; |
||||
String accessKeySecret = "PGN12Bm5LYihcC5j3dzIqDdvssJ7XY"; |
||||
StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder() |
||||
// Please ensure that the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set.
|
||||
.accessKeyId(accessKeyId) |
||||
.accessKeySecret(accessKeySecret) |
||||
//.securityToken(System.getenv("ALIBABA_CLOUD_SECURITY_TOKEN")) // use STS token
|
||||
.build()); |
||||
|
||||
// Configure the Client
|
||||
AsyncClient client = AsyncClient.builder() |
||||
//.httpClient(httpClient) // Use the configured HttpClient, otherwise use the default HttpClient (Apache HttpClient)
|
||||
.credentialsProvider(provider) |
||||
//.serviceConfiguration(Configuration.create()) // Service-level configuration
|
||||
// Client-level configuration rewrite, can set Endpoint, Http request parameters, etc.
|
||||
.overrideConfiguration( |
||||
ClientOverrideConfiguration.create() |
||||
// Endpoint 请参考 https://api.aliyun.com/product/Dysmsapi
|
||||
.setEndpointOverride("dysmsapi.aliyuncs.com") |
||||
//.setConnectTimeout(Duration.ofSeconds(30))
|
||||
) |
||||
.build(); |
||||
// Parameter settings for API request
|
||||
SendSmsRequest sendSmsRequest = SendSmsRequest.builder() |
||||
.phoneNumbers("15608487213") |
||||
.signName("长沙创客软件") |
||||
.templateCode("SMS_294115479") |
||||
.templateParam(JSONObject.of("code", "1234").toJSONString()) |
||||
|
||||
// Request-level configuration rewrite, can set Http request parameters, etc.
|
||||
// .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders()))
|
||||
.build(); |
||||
|
||||
// Asynchronously get the return value of the API request
|
||||
CompletableFuture<SendSmsResponse> response = client.sendSms(sendSmsRequest); |
||||
SendSmsResponse resp = response.get(); |
||||
System.out.println(resp); |
||||
} |
||||
|
||||
} |
||||
File diff suppressed because one or more lines are too long
@ -0,0 +1,76 @@
|
||||
package com.biutag.outer; |
||||
|
||||
import cn.hutool.core.util.IdUtil; |
||||
import com.alibaba.fastjson2.JSONObject; |
||||
import com.biutag.outer.util.Weixin; |
||||
import com.biutag.outer.util.Weixin2; |
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
import java.security.MessageDigest; |
||||
import java.security.NoSuchAlgorithmException; |
||||
import java.util.Date; |
||||
|
||||
public class WeixinTest { |
||||
|
||||
@Test |
||||
public void testGetAccessToken() { |
||||
JSONObject accessToken = Weixin.getAccessToken("051H1lGa1iJiLG0SfyIa1r1e7D1H1lGd"); |
||||
System.out.println(accessToken); |
||||
// {"access_token":"76_06xHwWwv5Uh0kL9rS4XlIo6zUnTR8UTQPkgqCudq0CCWKIHWKtm1ZTt2gjL0UFhIu5nRz_fbj3K8FU3cP_KV7BvYj10klyzGwo3SfH9J2C8","expires_in":7200,"refresh_token":"76_NTEKzhqkR8r4DHIrNHjqdf_op1WO45S-9hXZUudVa9AIpWVtrOeI9GjtrRRv9li1eW42HEhZlWywUeNU3-PQ5eax1HuDoSjmIf-ryr6b1ho","openid":"oXI846jfRZAqNG1MifdS6BUEVQBo","scope":"snsapi_userinfo"}
|
||||
|
||||
} |
||||
|
||||
@Test |
||||
public void testGetAccessToken2() { |
||||
// 47.104.162.76
|
||||
JSONObject accessToken = Weixin.getAccessToken(); |
||||
System.out.println(accessToken); |
||||
// 76_G7arjUsJjMcy1aTZsnEDwha4omw5DMoIy6fdeBCwrT0mRB9UFdEsOPo0v_NI2tA_GQepSf5ci5ywEswAp3SXfY-wG98vyvbFpYgYbnFkioIIn7IQJv9sKvBqQPgXHGjACAPZY
|
||||
} |
||||
|
||||
@Test |
||||
public void testGetTicket() { |
||||
String ticket = Weixin.getTicket(); |
||||
// ticket -> kgt8ON7yVITDhtdwci0qeQqMEspVxlvdU-9lgGDo9a9am_7XqzZHlyJqkuAvhu422wxs1VRgcuXvKhmYwdYMmQ
|
||||
} |
||||
|
||||
@Test |
||||
public void testSignature() { |
||||
// noncestr=Wm3WZYTPz0wzccnW
|
||||
// jsapi_ticket=sM4AOVdWfPE4DxkXGEs8VMCPGGVi4C3VM0P37wVUCFvkVAy_90u5h9nbSlYy3-Sl-HhTdfl2fzFy1AOcHKP7qg
|
||||
// timestamp=1414587457
|
||||
// url=http://mp.weixin.qq.com?params=value
|
||||
|
||||
String input = "jsapi_ticket=sM4AOVdWfPE4DxkXGEs8VMCPGGVi4C3VM0P37wVUCFvkVAy_90u5h9nbSlYy3-Sl-HhTdfl2fzFy1AOcHKP7qg&noncestr=Wm3WZYTPz0wzccnW×tamp=1414587457&url=http://mp.weixin.qq.com?params=value"; |
||||
|
||||
try { |
||||
String sha1Hash = generateSHA1(input); |
||||
System.out.println(sha1Hash); |
||||
} catch (NoSuchAlgorithmException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
|
||||
public static String generateSHA1(String input) throws NoSuchAlgorithmException { |
||||
MessageDigest md = MessageDigest.getInstance("SHA-1"); |
||||
byte[] digest = md.digest(input.getBytes()); |
||||
StringBuilder hexString = new StringBuilder(); |
||||
for (byte b : digest) { |
||||
hexString.append(String.format("%02x", b)); |
||||
} |
||||
return hexString.toString(); |
||||
} |
||||
|
||||
@Test |
||||
public void testSign() { |
||||
String noncestr = IdUtil.nanoId(16); |
||||
String jsapiTicket = Weixin2.getTicket(); |
||||
System.out.println(jsapiTicket); |
||||
long timestamp = new Date().getTime() / 1000; |
||||
String sign = Weixin2.sign(noncestr, jsapiTicket, timestamp, "https://mailbox.biutag.com/open.html"); |
||||
System.out.println("noncestr: " + noncestr); |
||||
System.out.println("timestamp: " + timestamp); |
||||
System.out.println("sign: " + sign); |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue