Merge pull request '团长认证' (#7) from czk into main

Reviewed-on: #7
main
czk 2024-05-02 16:59:14 +08:00
commit de258f8405
141 changed files with 1133 additions and 442 deletions

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/mall_auth/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/mall_common/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/mall_gateway/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/mall_modules/mall_back/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/mall_modules/mall_client/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/mall_modules/mall_mq/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/mall_modules/mall_server/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/mall_modules/mall_system/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/mall_modules/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/mall_modules/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>

View File

@ -0,0 +1,17 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="AliAccessStaticViaInstance" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AliArrayNamingShouldHaveBracket" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AliControlFlowStatementWithoutBraces" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AliDeprecation" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AliEqualsAvoidNull" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AliLongLiteralsEndingWithLowercaseL" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AliMissingOverrideAnnotation" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AliWrapperTypeEquality" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AutoCloseableResource" enabled="true" level="WARNING" enabled_by_default="true">
<option name="METHOD_MATCHER_CONFIG" value="java.util.Formatter,format,java.io.Writer,append,com.google.common.base.Preconditions,checkNotNull,org.hibernate.Session,close,java.io.PrintWriter,printf,java.io.PrintStream,printf,cn.hutool.http.HttpRequest,execute" />
</inspection_tool>
<inspection_tool class="MapOrSetKeyShouldOverrideHashCodeEquals" enabled="true" level="WARNING" enabled_by_default="true" />
</profile>
</component>

16
.idea/misc.xml 100644
View File

@ -0,0 +1,16 @@
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
<option name="ignoredFiles">
<set>
<option value="$PROJECT_DIR$/mall_modules/mall_mq/pom.xml" />
</set>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
</project>

View File

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

6
.idea/vcs.xml 100644
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

File diff suppressed because one or more lines are too long

View File

@ -30,6 +30,18 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependency>
<!--aliyunOSS-->
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
<version>3.10.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -1,10 +1,21 @@
package com.mall; package com.mall;
import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.common.auth.CredentialsProviderFactory;
import com.aliyun.oss.common.auth.EnvironmentVariableCredentialsProvider;
import com.aliyun.oss.model.CreateBucketRequest;
import com.mall.auth.config.OssProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.cloud.openfeign.EnableFeignClients;
import java.io.ByteArrayInputStream;
/** /**
* @AuthorChen * @AuthorChen
* @Packagecom.mall * @Packagecom.mall
@ -20,4 +31,5 @@ public class MallAuthApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(MallAuthApplication.class); SpringApplication.run(MallAuthApplication.class);
} }
} }

View File

@ -0,0 +1,60 @@
package com.mall.auth.config;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
/**
*Oss
*/
@Data
@Component
@ConfigurationProperties(prefix = "aliyun.oss")
public class OssProperties {
private String endpoint;
private String accessKeyId;
private String bucketName;
private String accessKeySecret;
/**
* OSS
*/
public String upload(MultipartFile file) throws IOException {
// 获取上传的文件的输入流
InputStream inputStream = file.getInputStream();
// 避免文件覆盖
String originalFilename = file.getOriginalFilename();
String fileName = UUID.randomUUID() + originalFilename.substring(originalFilename.lastIndexOf("."));
// 增加文件结构,按年月日区分文件
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String date = sdf.format(new Date());
fileName = "image"+ "/" + date + "/" + fileName;
//上传文件到 OSS
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
ossClient.putObject(bucketName, fileName, inputStream);
//根据过期时间来获取
Date d = new Date(System.currentTimeMillis() + 1000 * 60 * 60 * 24 * 7);
//文件地址和过期时间获取图片信息
String url = ossClient.generatePresignedUrl(bucketName, fileName, d).toString();
// 关闭ossClient
ossClient.shutdown();
// 把上传到oss的路径返回
System.out.println(url);
return url;
}
}

View File

@ -1,21 +1,19 @@
package com.mall.auth.controller; package com.mall.auth.controller;
import com.mall.auth.domain.IdCardCheckLifeVo;
import com.mall.auth.domain.IdCardValidateVo;
import com.mall.auth.domain.request.IdCardRequest;
import com.mall.auth.service.AuthService; import com.mall.auth.service.AuthService;
import com.mall.common.constant.JwtConstants; import com.mall.auth.utils.IdentityAuthenticationUtils;
import com.mall.common.constant.TokenConstants;
import com.mall.common.domain.UserInfo; import com.mall.common.domain.UserInfo;
import com.mall.common.domain.request.LoginRequest; import com.mall.common.domain.request.LoginRequest;
import com.mall.common.domain.vo.LoginVo; import com.mall.common.domain.vo.LoginVo;
import com.mall.common.domain.vo.UserInfoVo; import com.mall.common.domain.vo.UserInfoVo;
import com.mall.common.result.Result; import com.mall.common.result.Result;
import com.mall.common.utils.IdUtils;
import com.mall.common.utils.JwtUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.util.HashMap;
/** /**
* @Author: lzh * @Author: lzh
@ -83,8 +81,32 @@ public class AuthController {
return result; return result;
} }
/**
* token
* @param refreshToken
* @return
*/
@GetMapping("refreshToken") @GetMapping("refreshToken")
public Result refreshToken(@RequestParam String refreshToken){ public Result refreshToken(@RequestParam String refreshToken){
return authService.refreshToken(refreshToken); return authService.refreshToken(refreshToken);
} }
/**
* oos
* @return
*/
@PostMapping("identityAuthentication")
public Result identityAuthentication(@RequestParam MultipartFile file ,@RequestParam String side){
return authService.identityAuthentication(file,side);
}
/**
*
* @return
*/
@PostMapping("authentication")
public Result authentication(@RequestBody IdCardRequest idCardRequest) {
return authService.authentication(idCardRequest);
}
} }

View File

@ -0,0 +1,58 @@
package com.mall.auth.domain;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
*
*/
@NoArgsConstructor
@Data
public class IdCardCheckLifeVo {
/**
* msg :
* success : true
* code : 200
* data : {"order_no":"480330320913945667","motions":{"score":0.9996092319488525,"motion":"BLINK","passed":true},"passed":true,"feature_image_id":"04457bdc3a4e4c91bbb69309e08a5f0a","hack_score":0.2748934709681988}
*/
private String msg;
private boolean success;
private int code;
private DataBean data;
@NoArgsConstructor
@Data
public static class DataBean {
/**
* order_no : 480330320913945667
* motions : {"score":0.9996092319488525,"motion":"BLINK","passed":true}
* passed : true
* feature_image_id : 04457bdc3a4e4c91bbb69309e08a5f0a
* hack_score : 0.2748934709681988
*/
private String order_no;
private MotionsBean motions;
private boolean passed;
private String feature_image_id;
private double hack_score;
@NoArgsConstructor
@Data
public static class MotionsBean {
/**
* score : 0.9996092319488525
* motion : BLINK
* passed : true
*/
private double score;
private String motion;
private boolean passed;
}
}
}

View File

@ -0,0 +1,102 @@
package com.mall.auth.domain;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* OCR
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class IdCardPeopleVO {
/**
*
*/
private String faceImage;
/**
*
*/
private String backImage;
@JsonProperty("address")
private String address;
@JsonProperty("angle")
private Integer angle;
@JsonProperty("birth")
private String birth;
@JsonProperty("card_region")
private List<CardRegionDTO> cardRegion;
@JsonProperty("config_str")
private String configStr;
@JsonProperty("face_rect")
private FaceRectDTO faceRect;
@JsonProperty("face_rect_vertices")
private List<FaceRectVerticesDTO> faceRectVertices;
@JsonProperty("is_fake")
private Boolean isFake;
@JsonProperty("name")
private String name;
@JsonProperty("nationality")
private String nationality;
@JsonProperty("num")
private String num;
@JsonProperty("request_id")
private String requestId;
@JsonProperty("sex")
private String sex;
@JsonProperty("success")
private Boolean success;
@NoArgsConstructor
@Data
public static class FaceRectDTO {
@JsonProperty("angle")
private Integer angle;
@JsonProperty("center")
private CenterDTO center;
@JsonProperty("size")
private SizeDTO size;
@NoArgsConstructor
@Data
public static class CenterDTO {
@JsonProperty("x")
private Integer x;
@JsonProperty("y")
private Integer y;
}
@NoArgsConstructor
@Data
public static class SizeDTO {
@JsonProperty("height")
private Integer height;
@JsonProperty("width")
private Integer width;
}
}
@NoArgsConstructor
@Data
public static class CardRegionDTO {
@JsonProperty("x")
private Integer x;
@JsonProperty("y")
private Integer y;
}
@NoArgsConstructor
@Data
public static class FaceRectVerticesDTO {
@JsonProperty("x")
private Integer x;
@JsonProperty("y")
private Integer y;
}
}

View File

@ -0,0 +1,28 @@
package com.mall.auth.domain;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
*
*/
@NoArgsConstructor
@Data
public class IdCardValidateVo {
private DataBean data;
private String msg;
private boolean success;
private int code;
private String taskNo;
@NoArgsConstructor
@Data
public static class DataBean {
private int result;
private String desc;
private String sex;
private String birthday;
private String address;
}
}

View File

@ -0,0 +1,30 @@
package com.mall.auth.domain.request;
import lombok.Data;
/**
*
*/
@Data
public class IdCardRequest {
/**
*
*/
private String faceImage;
/**
*
*/
private String backImage;
/**
*
*/
private String image;
/**
*
*/
private String name;
/**
*
*/
private String idCardNo;
}

View File

@ -1,5 +1,6 @@
package com.mall.auth.feign; package com.mall.auth.feign;
import com.mall.auth.domain.request.IdCardRequest;
import com.mall.common.domain.UserInfo; import com.mall.common.domain.UserInfo;
import com.mall.common.result.Result; import com.mall.common.result.Result;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
@ -21,4 +22,7 @@ public interface UserServiceFeign {
@PostMapping("register") @PostMapping("register")
public Result<UserInfo> register(@RequestBody UserInfo userInfo); public Result<UserInfo> register(@RequestBody UserInfo userInfo);
@PostMapping("authentication")
Result authentication(@RequestBody UserInfo userInfo);
} }

View File

@ -1,10 +1,12 @@
package com.mall.auth.service; package com.mall.auth.service;
import com.mall.auth.domain.request.IdCardRequest;
import com.mall.common.domain.UserInfo; import com.mall.common.domain.UserInfo;
import com.mall.common.domain.request.LoginRequest; import com.mall.common.domain.request.LoginRequest;
import com.mall.common.domain.vo.LoginVo; import com.mall.common.domain.vo.LoginVo;
import com.mall.common.domain.vo.UserInfoVo; import com.mall.common.domain.vo.UserInfoVo;
import com.mall.common.result.Result; import com.mall.common.result.Result;
import org.springframework.web.multipart.MultipartFile;
public interface AuthService { public interface AuthService {
Result login(LoginVo loginVo); Result login(LoginVo loginVo);
@ -19,4 +21,8 @@ public interface AuthService {
Result refreshToken(String refreshToken); Result refreshToken(String refreshToken);
Result identityAuthentication(MultipartFile file, String side);
Result authentication(IdCardRequest idCardRequest);
} }

View File

@ -2,8 +2,15 @@ package com.mall.auth.service.impl;
import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.RandomUtil;
import cn.hutool.crypto.SecureUtil; import cn.hutool.crypto.SecureUtil;
import com.mall.auth.config.OssProperties;
import com.mall.auth.domain.IdCardCheckLifeVo;
import com.mall.auth.domain.IdCardPeopleVO;
import com.mall.auth.domain.IdCardValidateVo;
import com.mall.auth.domain.request.IdCardRequest;
import com.mall.auth.feign.UserServiceFeign; import com.mall.auth.feign.UserServiceFeign;
import com.mall.auth.service.AuthService; import com.mall.auth.service.AuthService;
import com.mall.auth.utils.IdentityAuthenticationUtils;
import com.mall.common.config.ThreadPoolConfig;
import com.mall.common.constant.JwtConstants; import com.mall.common.constant.JwtConstants;
import com.mall.common.constant.TokenConstants; import com.mall.common.constant.TokenConstants;
import com.mall.common.domain.UserInfo; import com.mall.common.domain.UserInfo;
@ -22,12 +29,15 @@ import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.UUID; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/** /**
@ -47,6 +57,12 @@ public class AuthServiceImpl implements AuthService {
private UserServiceFeign userServiceFeign; private UserServiceFeign userServiceFeign;
@Autowired @Autowired
private RabbitTemplate rabbitTemplate; private RabbitTemplate rabbitTemplate;
@Autowired
private OssProperties ossProperties;
@Autowired
private IdentityAuthenticationUtils identityAuthenticationUtils;
@Autowired
private ThreadPoolConfig threadPoolConfig;
@Override @Override
public Result login(LoginVo loginVo) { public Result login(LoginVo loginVo) {
@ -167,4 +183,70 @@ public class AuthServiceImpl implements AuthService {
redisCache.setCacheObject(TokenConstants.TOKEN+token,userInfo,TokenConstants.EXPIRATION,TimeUnit.MINUTES); redisCache.setCacheObject(TokenConstants.TOKEN+token,userInfo,TokenConstants.EXPIRATION,TimeUnit.MINUTES);
return Result.success(token); return Result.success(token);
} }
@Override
public Result identityAuthentication(MultipartFile file, String side) {
String uploadPic = null;
try {
uploadPic = ossProperties.upload(file);
} catch (IOException e) {
throw new BizException(500,"图片信息有误");
}
//扫描身份证
IdCardPeopleVO idCardPeopleVO = identityAuthenticationUtils.ocrIdCard(uploadPic, side);
if(side.equals("face")){
idCardPeopleVO.setFaceImage(uploadPic);
}else {
idCardPeopleVO.setBackImage(uploadPic);
}
return Result.success(idCardPeopleVO);
}
@Override
public Result authentication(IdCardRequest idCardRequest) {
//校验身份证号姓名
CompletableFuture<IdCardValidateVo> f1 = CompletableFuture.supplyAsync(() -> {
IdCardValidateVo idCardValidateVo = identityAuthenticationUtils.idCardValidate(idCardRequest.getIdCardNo(), idCardRequest.getName());
return idCardValidateVo;
},threadPoolConfig.getThreadPoolExecutor());
//检验活体视频
CompletableFuture<IdCardCheckLifeVo> f2 = CompletableFuture.supplyAsync(() -> {
IdCardCheckLifeVo idCardCheckLifeVo = identityAuthenticationUtils.idCardCheckLife(idCardRequest.getImage());
return idCardCheckLifeVo;
}, threadPoolConfig.getThreadPoolExecutor());
// CompletableFuture.allOf(f1,f2).join();
IdCardValidateVo idCardValidateVo = null;
IdCardCheckLifeVo idCardCheckLifeVo = null;
try {
idCardValidateVo = f1.get();
idCardCheckLifeVo = f2.get();
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (ExecutionException e) {
throw new RuntimeException(e);
}
//提交申请
if(idCardValidateVo.getCode()==200 ){
UserInfo userInfo = userInfo().getData();
CompletableFuture<Result> f3 = CompletableFuture.supplyAsync(() -> {
userInfo.setIdentityFront(idCardRequest.getFaceImage());
userInfo.setIdentityReverse(idCardRequest.getBackImage());
userInfo.setIdentityAuthentication(idCardRequest.getImage());
userInfo.setCheckState(0);
return userServiceFeign.authentication(userInfo);
}, threadPoolConfig.getThreadPoolExecutor());
try {
f3.get();
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (ExecutionException e) {
throw new RuntimeException(e);
}
return Result.success();
}
return Result.error(500,"信息有误,冲洗提交");
}
} }

View File

@ -0,0 +1,106 @@
package com.mall.auth.utils;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import com.alibaba.fastjson.JSON;
import com.mall.auth.domain.IdCardCheckLifeVo;
import com.mall.auth.domain.IdCardPeopleVO;
import com.mall.auth.domain.IdCardValidateVo;
import com.mall.common.result.BizException;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
/**
*
*/
@Component
public class IdentityAuthenticationUtils {
/**
* ocr
* @param imgFile
* @return
*/
public IdCardPeopleVO ocrIdCard(String imgFile,String side){
String appCode = "bd7a2b331483430ebdccab6ea8a880c2";
// 创建JSON参数
JSONObject jsonObject = new JSONObject();
jsonObject.put("image", imgFile);
JSONObject configure = new JSONObject();
configure.put("side", side);
// configure.put("quality_info","false");
jsonObject.put("configure", configure.toString());
HttpRequest post = HttpUtil.createPost("https://cardnumber.market.alicloudapi.com/rest/160601/ocr/ocr_idcard.json");
IdCardPeopleVO idCardPeopleVO = null;
String body = null;
try {
body = post.header("Authorization", "APPCODE " + appCode)
.header("Content-Type", "application/json; charset=UTF-8")
.body(jsonObject.toString())
.execute().body();
idCardPeopleVO = JSON.parseObject(body, IdCardPeopleVO.class);
} catch (Exception e) {
throw new BizException(500,body);
}
return idCardPeopleVO;
}
/**
*
* @param idCardNo
* @param name
* @return
*/
public IdCardValidateVo idCardValidate(String idCardNo,String name){
String appCode = "bd7a2b331483430ebdccab6ea8a880c2";
Map<String, Object> bodys = new HashMap<>();
bodys.put("idCardNo", idCardNo);
bodys.put("name", name);
HttpRequest post = HttpUtil.createPost("https://jumdata.market.alicloudapi.com/idcard/validate");
String body = null;
IdCardValidateVo idCardValidateVo = null;
try {
body = post.header("Authorization", "APPCODE " + appCode)
.form(bodys)
.execute().body();
idCardValidateVo = JSON.parseObject(body, IdCardValidateVo.class);
} catch (Exception e) {
throw new BizException(500,body);
}
return idCardValidateVo;
}
/**
*
* @param url
* @return
*/
public IdCardCheckLifeVo idCardCheckLife(String url){
String appCode = "bd7a2b331483430ebdccab6ea8a880c2";
Map<String, Object> bodys = new HashMap<>();
//活体检测通过的难易程度默认为0 0简单模式1正常模式2困难模式3地狱模式
bodys.put("complexity", "0");
//用户动作序列BLINK 眨眼MOUTH 张嘴; NOD 点头YAW 摇头
bodys.put("motions", "BLINK ");
//路径
bodys.put("url", url);
String body = null;
IdCardCheckLifeVo idCardValidateVo = null;
try {
body = HttpRequest.post("https://life.shumaidata.com/checklife")
.header("Authorization", "APPCODE " + appCode)
.form(bodys)
.execute().body();
idCardValidateVo = JSON.parseObject(body, IdCardCheckLifeVo.class);
} catch (Exception e) {
throw new BizException(500,body);
}
return idCardValidateVo;
}
}

View File

@ -3,6 +3,12 @@ server:
port: 9000 port: 9000
# Spring # Spring
spring: spring:
servlet:
multipart:
#这将限制单个文件的最大大小为10MB
max-file-size: 10MB
#并限制整个请求的最大大小为10MB。
max-request-size: 10MB
main: main:
allow-circular-references: true allow-circular-references: true
jackson: jackson:
@ -33,4 +39,11 @@ spring:
shared-configs: shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
#开启监听feign调用不开监听不了 #开启监听feign调用不开监听不了
feign.sentinel.enabled: true feign.sentinel.enabled: true
aliyun:
oss:
endpoint: https://oss-cn-beijing.aliyuncs.com
accessKeyId: LTAI5tCBE54x4gX5pHfQNPCc
accessKeySecret: x6k0BYKmy842vWMu8K7ItMdFx2RQeR
bucketName: zixuan-com

View File

@ -0,0 +1,49 @@
# Tomcat
server:
port: 9000
# Spring
spring:
servlet:
multipart:
#这将限制单个文件的最大大小为10MB
max-file-size: 10MB
#并限制整个请求的最大大小为10MB。
max-request-size: 10MB
main:
allow-circular-references: true
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
application:
# 应用名称
name: czk-auth
profiles:
# 环境配置
active: dev
cloud:
#代理和sentinel交互端口
# sentinel:
# transport:
# port: 8719
# dashboard: localhost:8081
nacos:
discovery:
# 服务注册地址
server-addr: 42.192.106.69:8848
config:
# 配置中心地址
server-addr: 42.192.106.69:8848
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
#开启监听feign调用不开监听不了
feign.sentinel.enabled: true
aliyun:
oss:
endpoint: https://oss-cn-beijing.aliyuncs.com
accessKeyId: LTAI5tCBE54x4gX5pHfQNPCc
accessKeySecret: x6k0BYKmy842vWMu8K7ItMdFx2RQeR
bucketName: zixuan-com

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,3 @@
artifactId=mall_auth
groupId=com.mall
version=1.0.0

View File

@ -0,0 +1,5 @@
com\mall\auth\controller\Controller.class
com\mall\auth\controller\RemoteUserService.class
com\mall\auth\config\SwaggerConfig.class
com\mall\auth\controller\RemoteUserServiceFactory.class
com\mall\MallAuthApplication.class

View File

@ -0,0 +1,5 @@
G:\java\one_mall\mall_auth\src\main\java\com\mall\auth\controller\RemoteUserServiceFactory.java
G:\java\one_mall\mall_auth\src\main\java\com\mall\auth\config\SwaggerConfig.java
G:\java\one_mall\mall_auth\src\main\java\com\mall\auth\controller\RemoteUserService.java
G:\java\one_mall\mall_auth\src\main\java\com\mall\MallAuthApplication.java
G:\java\one_mall\mall_auth\src\main\java\com\mall\auth\controller\Controller.java

View File

@ -8,12 +8,7 @@ import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/** /**
* @AuthorChen * 线
* @Packagecom.mall.common.config
* @Projectflat_house
* @nameThreadPoolConfig
* @Date2024/3/27 19:39
* @Description: TODO
*/ */
@Configuration @Configuration
public class ThreadPoolConfig { public class ThreadPoolConfig {
@ -21,7 +16,7 @@ public class ThreadPoolConfig {
private static final Integer availableProcessors = Runtime.getRuntime().availableProcessors(); private static final Integer availableProcessors = Runtime.getRuntime().availableProcessors();
@Bean @Bean
public ThreadPoolExecutor getThreadPoolExecutor (){ public ThreadPoolExecutor getThreadPoolExecutor() {
ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(availableProcessors*2, (availableProcessors*2)+25, 5, TimeUnit.SECONDS, new LinkedBlockingQueue<>(availableProcessors)); ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(availableProcessors*2, (availableProcessors*2)+25, 5, TimeUnit.SECONDS, new LinkedBlockingQueue<>(availableProcessors));
return poolExecutor; return poolExecutor;
} }

Binary file not shown.

View File

@ -0,0 +1,3 @@
artifactId=mall_common
groupId=com.mall
version=1.0.0

View File

@ -0,0 +1,10 @@
com\mall\common\result\BizException.class
com\mall\common\utils\SecurityUtils.class
com\mall\common\handler\MyBlockExceptionHandler.class
com\mall\common\redis\RedisCache.class
com\mall\common\result\Result.class
com\mall\common\handler\GlobalExceptionHandler.class
com\mall\common\utils\JwtUtils.class
com\mall\common\result\PageResult.class
com\mall\common\utils\IdUtils.class
com\mall\common\utils\StringUtils.class

View File

@ -0,0 +1,19 @@
G:\java\one_mall\mall_common\src\main\java\com\mall\common\result\BizException.java
G:\java\one_mall\mall_common\src\main\java\com\mall\common\constant\Constants.java
G:\java\one_mall\mall_common\src\main\java\com\mall\common\handler\GlobalExceptionHandler.java
G:\java\one_mall\mall_common\src\main\java\com\mall\common\redis\RedisCache.java
G:\java\one_mall\mall_common\src\main\java\com\mall\common\utils\JwtUtils.java
G:\java\one_mall\mall_common\src\main\java\com\mall\common\utils\IdUtils.java
G:\java\one_mall\mall_common\src\main\java\com\mall\common\config\MybatisPlusConfig.java
G:\java\one_mall\mall_common\src\main\java\com\mall\common\config\ThreadPoolConfig.java
G:\java\one_mall\mall_common\src\main\java\com\mall\common\utils\StringUtils.java
G:\java\one_mall\mall_common\src\main\java\com\mall\common\constant\RemoteConstants.java
G:\java\one_mall\mall_common\src\main\java\com\mall\common\constant\JwtConstants.java
G:\java\one_mall\mall_common\src\main\java\com\mall\common\constant\ServerNameConstants.java
G:\java\one_mall\mall_common\src\main\java\com\mall\common\handler\MyBlockExceptionHandler.java
G:\java\one_mall\mall_common\src\main\java\com\mall\common\config\RedisConfig.java
G:\java\one_mall\mall_common\src\main\java\com\mall\common\result\PageResult.java
G:\java\one_mall\mall_common\src\main\java\com\mall\common\utils\SecurityUtils.java
G:\java\one_mall\mall_common\src\main\java\com\mall\common\config\FastJson2JsonRedisSerializer.java
G:\java\one_mall\mall_common\src\main\java\com\mall\common\constant\TokenConstants.java
G:\java\one_mall\mall_common\src\main\java\com\mall\common\result\Result.java

View File

@ -0,0 +1,29 @@
# Tomcat
server:
port: 18080
# Spring
spring:
application:
# 应用名称
name: czk-gateway
profiles:
# 环境配置
active: dev
main:
# 允许使用循环引用
allow-circular-references: true
# 允许定义相同的bean对象 去覆盖原有的
allow-bean-definition-overriding: true
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: 42.192.106.69:8848
config:
# 配置中心地址
server-addr: 42.192.106.69:8848
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}

Binary file not shown.

View File

@ -0,0 +1,3 @@
artifactId=mall_gateway
groupId=com.mall
version=1.0.0

View File

@ -0,0 +1,4 @@
com\mall\MallGateWayApplication.class
com\mall\gateway\utils\GatewayUtils.class
com\mall\gateway\config\IgnoreWhiteConfig.class
com\mall\gateway\filters\AuthFilter.class

View File

@ -0,0 +1,4 @@
G:\java\one_mall\mall_gateway\src\main\java\com\mall\gateway\config\IgnoreWhiteConfig.java
G:\java\one_mall\mall_gateway\src\main\java\com\mall\gateway\filters\AuthFilter.java
G:\java\one_mall\mall_gateway\src\main\java\com\mall\MallGateWayApplication.java
G:\java\one_mall\mall_gateway\src\main\java\com\mall\gateway\utils\GatewayUtils.java

View File

@ -35,6 +35,9 @@ public class SpikesJob {
@Autowired @Autowired
private RedissonClient redissonClient; private RedissonClient redissonClient;
/**
*
*/
// @Scheduled(cron = "0/5 * * * * ? ") // @Scheduled(cron = "0/5 * * * * ? ")
public void spikesJob(){ public void spikesJob(){
Date date = Date.from( Date date = Date.from(
@ -62,4 +65,34 @@ public class SpikesJob {
}); });
} }
/**
*
*/
// @Scheduled(cron = "0/5 * * * * ? ")
public void updateInventoryJob(){
List<SpikesEntity> list = spikesService.list(
new LambdaQueryWrapper<SpikesEntity>()
.le(SpikesEntity::getCreateTime, new Date())
.ge(SpikesEntity::getEndTime,new Date())
);
if(CollectionUtils.isEmpty(list)){
return;
}
list.forEach(c->{
skuService.list(
new LambdaQueryWrapper<SkuEntity>()
.eq(c.getSpikesId()!=null,SkuEntity::getSpikesId,c.getSpikesId())
).forEach(s -> {
RSemaphore semaphore = redissonClient.getSemaphore(SpikesConstant.SPIKES_INVENTORY + s.getId());
int inventoryRestrict = semaphore.availablePermits();
skuService.updateById(
SkuEntity.builder()
.id(s.getId())
.inventoryRestrict(inventoryRestrict)
.build()
);
});
});
}
} }

View File

@ -152,6 +152,11 @@ public class SpikesServiceImpl extends ServiceImpl<SpikesMapper, SpikesEntity>
*/ */
@Override @Override
public Result spike(Long skuId) { public Result spike(Long skuId) {
UserInfo login = getLogin();
if(redisCache.hasKey("spike_"+login.getId()+skuId)){
throw new BizException(500,"禁止重复抢购欧");
}
redisCache.setCacheObject("spike_"+login.getId()+skuId,IdUtils.genId().toString(),1L,TimeUnit.MINUTES);
SkuEntity skuEntity = skuService.getOne( SkuEntity skuEntity = skuService.getOne(
new LambdaQueryWrapper<SkuEntity>() new LambdaQueryWrapper<SkuEntity>()
.eq(skuId != null, SkuEntity::getId, skuId) .eq(skuId != null, SkuEntity::getId, skuId)
@ -163,20 +168,7 @@ public class SpikesServiceImpl extends ServiceImpl<SpikesMapper, SpikesEntity>
if(spikesEntity.getCreateTime().compareTo(new Date())>0 || spikesEntity.getEndTime().compareTo(new Date())<0){ if(spikesEntity.getCreateTime().compareTo(new Date())>0 || spikesEntity.getEndTime().compareTo(new Date())<0){
throw new BizException(500,skuEntity.getName()+"该商品不在抢购时间内"); throw new BizException(500,skuEntity.getName()+"该商品不在抢购时间内");
} }
UserInfo login = getLogin();
OrderItemEntity orderItemEntity = orderItemService.getOne(
new LambdaQueryWrapper<OrderItemEntity>()
.eq(OrderItemEntity::getUserId, login.getId())
.eq(OrderItemEntity::getSkuId,skuId)
);
if(orderItemEntity!=null){
throw new BizException(500,"禁止重复抢购欧");
}
RSemaphore semaphore = redissonClient.getSemaphore(SpikesConstant.SPIKES_INVENTORY + skuId); RSemaphore semaphore = redissonClient.getSemaphore(SpikesConstant.SPIKES_INVENTORY + skuId);
// if(semaphore.availablePermits()==0){
// //同步数据库库存量
// throw new BizException(500,"商品已抢购完");
// }
if(!semaphore.tryAcquire(1)){ if(!semaphore.tryAcquire(1)){
throw new BizException(500,"系统繁忙,商品已抢购完"); throw new BizException(500,"系统繁忙,商品已抢购完");
} }

View File

@ -0,0 +1,7 @@
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.mall.common.config.MybatisPlusConfig,\
com.mall.common.config.RedisConfig,\
com.mall.common.redis.RedisCache,\
com.mall.common.config.ThreadPoolConfig,\
com.mall.common.handler.GlobalExceptionHandler

View File

@ -0,0 +1,39 @@
# Tomcat
server:
port: 9002
# Spring
spring:
rabbitmq:
host: 42.192.106.69
port: 5672
username: guest
password: guest
virtual-host: /
listener:
simple:
# 消息确认模式这里设置为手动确认manual即消费者需要手动确认消息的消费
acknowledge-mode: manual
main:
allow-circular-references: true
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
application:
# 应用名称
name: czk-list
profiles:
# 环境配置
active: dev
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: 42.192.106.69:8848
config:
# 配置中心地址
server-addr: 42.192.106.69:8848
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}

Some files were not shown because too many files have changed in this diff Show More