api-passenger调用service-verificationcode

master
方煜 3 years ago
parent 1d3c48413b
commit 12be01ea87

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>online-taxi-public</artifactId>
<groupId>com.mashibing</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>api-boss</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
</project>

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>online-taxi-public</artifactId>
<groupId>com.mashibing</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>api-driver</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
</project>

@ -14,6 +14,7 @@
<properties> <properties>
<maven.compiler.source>8</maven.compiler.source> <maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target> <maven.compiler.target>8</maven.compiler.target>
<spring-cloud-alibaba.version>2021.1</spring-cloud-alibaba.version>
</properties> </properties>
<dependencies> <dependencies>
@ -21,5 +22,20 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependency>
<!-- nacos discovery -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>

@ -2,12 +2,16 @@ package com.mashibing.passenger;
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.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
/** /**
* @author fangyu * @author fangyu
* @version v1.0.0 * @version v1.0.0
* @date 2022/7/24 01:07 * @date 2022/7/24 01:07
*/ */
@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication @SpringBootApplication
public class ApiPassengerApplication { public class ApiPassengerApplication {

@ -0,0 +1,26 @@
package com.mashibing.passenger.remote;
import com.mashibing.common.dto.ResponseResult;
import com.mashibing.common.response.NumberCodeResponse;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
/**
* @author fangyu
* @version v1.0.0
* @date 2022/7/26 22:48
*/
@FeignClient("service-verificationcode")
public interface ServiceVerificationCodeClient {
/**
*
*
* @param size
* @return ResponseResult
*/
@RequestMapping(method = RequestMethod.GET, value = "/numberCode/${size}")
ResponseResult<NumberCodeResponse> getNumberCode(@PathVariable("size") int size);
}

@ -1,26 +1,13 @@
package com.mashibing.passenger.request; package com.mashibing.passenger.request;
import lombok.Data;
/** /**
* @author fangyu * @author fangyu
* @version v1.0.0 * @version v1.0.0
* @date 2022/7/24 01:21 * @date 2022/7/24 01:21
*/ */
@Data
public class VerificationCodeDTO { public class VerificationCodeDTO {
private String passengerPhone; private String passengerPhone;
public String getPassengerPhone() {
return passengerPhone;
}
public void setPassengerPhone(String passengerPhone) {
this.passengerPhone = passengerPhone;
}
@Override
public String toString() {
return "{\"VerificationCodeDTO\":{"
+ " \"passengerPhone\":\"" + passengerPhone + "\""
+ "}}";
}
} }

@ -1,6 +1,10 @@
package com.mashibing.passenger.service; package com.mashibing.passenger.service;
import com.mashibing.common.dto.ResponseResult;
import com.mashibing.common.response.NumberCodeResponse;
import com.mashibing.passenger.remote.ServiceVerificationCodeClient;
import net.sf.json.JSONObject; import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/** /**
@ -11,10 +15,18 @@ import org.springframework.stereotype.Service;
@Service @Service
public class VerificationCodeService { public class VerificationCodeService {
@Autowired
private ServiceVerificationCodeClient verificationCodeServiceClient;
public String generateCode(String passengerPhone) { public String generateCode(String passengerPhone) {
// 调用验证码服务,获取验证码 // 调用验证码服务,获取验证码
System.out.println("调用验证码服务,获取验证码"); System.out.println("调用验证码服务,获取验证码");
ResponseResult<NumberCodeResponse> numberCodeResponse = verificationCodeServiceClient.getNumberCode(6);
int numberCode = numberCodeResponse.getData().getNumberCode();
System.out.println("remote number code:" + numberCode);
// 存入redis // 存入redis
System.out.println("存入redis"); System.out.println("存入redis");

@ -1,2 +1,9 @@
server: server:
port: 8081 port: 8081
spring:
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
application:
name: api-passenger

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>online-taxi-public</artifactId>
<groupId>com.mashibing</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>internal-common</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
</project>

@ -0,0 +1,41 @@
package com.mashibing.common.constant;
/**
* @author fangyu
* @version v1.0.0
* @date 2022/7/26 00:10
*/
public class AmapConfigConstants {
/**
*
*/
public static final String DIRECTION_URL = "https://restapi.amap.com/v3/direction/driving";
/**
*
*/
public static final String DISTRICT_URL = "https://restapi.amap.com/v3/config/district";
/**
* json key
*/
public static final String STATUS = "status";
public static final String ROUTE = "route";
public static final String PATHS = "paths";
public static final String DISTANCE = "distance";
public static final String DURATION = "duration";
public static final String DISTRICTS = "districts";
public static final String ADCODE = "adcode";
public static final String NAME = "name";
public static final String LEVEL = "level";
public static final String STREET = "street";
}

@ -0,0 +1,56 @@
package com.mashibing.common.constant;
import lombok.Getter;
/**
* @author fangyu
* @version v1.0.0
* @date 2022/7/25 22:16
*/
public enum CommonStatusEnum {
/**
* 1000-1099
*/
VERIFICATION_CODE_ERROR(1099, "验证码不正确"),
/**
* Token1100-1199
*/
TOKEN_ERROR(1199, "token错误"),
/**
* 1200-1299
*/
USER_NOT_EXISTS(1200, "当前用户不存在"),
/**
* :1300-1399
*/
PRICE_RULE_EMPTY(1300, "计价规则不存在"),
/**
* 1400-1499
*/
MAP_DISTRICT_ERROR(1400, "请求地图错误"),
/**
*
*/
SUCCESS(1, "success"),
/**
*
*/
FAIL(0, "fail");
@Getter
private int code;
@Getter
private String value;
CommonStatusEnum(int code, String value) {
this.code = code;
this.value = value;
}
}

@ -0,0 +1,18 @@
package com.mashibing.common.constant;
/**
* @author fangyu
* @version v1.0.0
* @date 2022/7/26 00:11
*/
public class IdentityConstants {
/**
*
*/
public static final String PASSENGER_IDENTITY = "1";
/**
*
*/
public static final String DRIVER_IDENTITY = "2";
}

@ -0,0 +1,15 @@
package com.mashibing.common.constant;
/**
* token
*
* @author fangyu
* @version v1.0.0
* @date 2022/7/26 00:12
*/
public class TokenConstants {
public static final String ACCESS_TOKEN_TYPE = "accessToken";
public static final String REFRESH_TOKEN_TYPE = "refreshToken";
}

@ -0,0 +1,16 @@
package com.mashibing.common.dto;
import lombok.Data;
/**
* @author fangyu
* @version v1.0.0
* @date 2022/7/26 00:08
*/
@Data
public class DicDistrict {
private String addressCode;
private String addressName;
private String parentAddressCode;
private Integer level;
}

@ -0,0 +1,46 @@
package com.mashibing.common.dto;
import lombok.Data;
import java.time.LocalDate;
import java.time.LocalDateTime;
/**
* @author fangyu
* @version v1.0.0
* @date 2022/7/26 00:09
*/
@Data
public class DriverUser {
private Long id;
private String address;
private String driverName;
private String driverPhone;
private Integer driverGender;
private LocalDate driverBirthday;
private String driverNation;
private String driverContactAddress;
private String licenseId;
private LocalDate getDriverLicenseDate;
private LocalDate driverLicenseOn;
private LocalDate driverLicenseOff;
private Integer taxiDriver;
private String certificateNo;
private String networkCarIssueOrganization;
private LocalDate networkCarIssueDate;
private LocalDate getNetworkCarProofDate;
private LocalDate networkCarProofOn;
private LocalDate networkCarProofOff;
private LocalDate registerDate;
private Integer commercialType;
private String contractCompany;
private LocalDate contractOn;
private LocalDate contractOff;
private Integer state;
private LocalDateTime gmtCreate;
private LocalDateTime gmtModified;
}

@ -0,0 +1,27 @@
package com.mashibing.common.dto;
import java.time.LocalDateTime;
/**
* @author fangyu
* @version v1.0.0
* @date 2022/7/26 00:10
*/
public class PassengerUser {
private Long id;
private LocalDateTime gmtCreate;
private LocalDateTime gmtModified;
private String passengerPhone;
private String passengerName;
private byte passengerGender;
private byte state;
private String profilePhoto;
}

@ -0,0 +1,20 @@
package com.mashibing.common.dto;
/**
* @author fangyu
* @version v1.0.0
* @date 2022/7/26 00:10
*/
public class PriceRule {
private String cityCode;
private String vehicleType;
private Double startFare;
private Integer startMile;
private Double unitPricePerMile;
private Double unitPricePerMinute;
}

@ -0,0 +1,74 @@
package com.mashibing.common.dto;
import com.mashibing.common.constant.CommonStatusEnum;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* @author fangyu
* @version v1.0.0
* @date 2022/7/25 22:09
*/
@Data
@Accessors(chain = true)
public class ResponseResult<T> {
private int code;
private String message;
private T data;
/**
*
*
* @param <T>
* @return
*/
public static <T> ResponseResult success() {
return new ResponseResult().setCode(CommonStatusEnum.SUCCESS.getCode()).setMessage(CommonStatusEnum.SUCCESS.getValue());
}
/**
*
*
* @param data
* @param <T>
* @return
*/
public static <T> ResponseResult success(T data) {
return new ResponseResult().setCode(CommonStatusEnum.SUCCESS.getCode()).setMessage(CommonStatusEnum.SUCCESS.getValue()).setData(data);
}
/**
*
*
* @param data
* @param <T>
* @return
*/
public static <T> ResponseResult fail(T data) {
return new ResponseResult().setData(data);
}
/**
*
*
* @param code
* @param message
* @return
*/
public static ResponseResult fail(int code, String message) {
return new ResponseResult().setCode(code).setMessage(message);
}
/**
*
*
* @param code
* @param message
* @param data
* @return
*/
public static ResponseResult fail(int code, String message, String data) {
return new ResponseResult().setCode(code).setMessage(message).setData(data);
}
}

@ -0,0 +1,14 @@
package com.mashibing.common.dto;
import lombok.Data;
/**
* @author fangyu
* @version v1.0.0
* @date 2022/7/25 23:37
*/
@Data
public class TokenResult {
private String phone;
private String identity;
}

@ -0,0 +1,16 @@
package com.mashibing.common.request;
import lombok.Data;
/**
* @author fangyu
* @version v1.0.0
* @date 2022/7/26 00:08
*/
@Data
public class ForecastPriceDTO {
private String depLongitude;
private String depLatitude;
private String destLongitude;
private String destLatitude;
}

@ -0,0 +1,14 @@
package com.mashibing.common.request;
import lombok.Data;
/**
* @author fangyu
* @version v1.0.0
* @date 2022/7/26 00:08
*/
@Data
public class VerificationCodeDTO {
private String passengerPhone;
private String verificationCode;
}

@ -0,0 +1,14 @@
package com.mashibing.common.response;
import lombok.Data;
/**
* @author fangyu
* @version v1.0.0
* @date 2022/7/26 00:07
*/
@Data
public class DirectionResponse {
private Integer distance;
private Integer duration;
}

@ -0,0 +1,13 @@
package com.mashibing.common.response;
import lombok.Data;
/**
* @author fangyu
* @version v1.0.0
* @date 2022/7/26 00:07
*/
@Data
public class ForecastPriceResponse {
private double price;
}

@ -0,0 +1,13 @@
package com.mashibing.common.response;
import lombok.Data;
/**
* @author fangyu
* @version v1.0.0
* @date 2022/7/26 00:05
*/
@Data
public class NumberCodeResponse {
private int numberCode;
}

@ -0,0 +1,14 @@
package com.mashibing.common.response;
import lombok.Data;
/**
* @author fangyu
* @version v1.0.0
* @date 2022/7/26 00:06
*/
@Data
public class TokenResponse {
private String accessToken;
private String refreshToken;
}

@ -0,0 +1,69 @@
package com.mashibing.common.util;
import java.math.BigDecimal;
/**
* @author fangyu
* @version v1.0.0
* @date 2022/7/25 22:54
*/
public class BigDecimalUtils {
/**
*
*
* @param v1
* @param v2
* @return
*/
public static double add(double v1, double v2) {
BigDecimal b1 = BigDecimal.valueOf(v1);
BigDecimal b2 = BigDecimal.valueOf(v2);
return b1.add(b2).doubleValue();
}
/**
*
*
* @param v1
* @param v2
* @return
*/
public static double subtract(double v1, double v2) {
BigDecimal b1 = BigDecimal.valueOf(v1);
BigDecimal b2 = BigDecimal.valueOf(v2);
return b1.subtract(b2).doubleValue();
}
/**
*
*
* @param v1
* @param v2
* @return
*/
public static double multiply(double v1, double v2) {
BigDecimal b1 = BigDecimal.valueOf(v1);
BigDecimal b2 = BigDecimal.valueOf(v2);
return b1.multiply(b2).doubleValue();
}
/**
*
*
* @param v1
* @param v2
* @return
*/
public static double divide(int v1, int v2) {
if (v2 <= 0) {
throw new IllegalArgumentException("除数非法");
}
BigDecimal b1 = BigDecimal.valueOf(v1);
BigDecimal b2 = BigDecimal.valueOf(v2);
return b1.divide(b2, 2, BigDecimal.ROUND_HALF_UP).doubleValue();
}
}

@ -0,0 +1,112 @@
package com.mashibing.common.util;
import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTCreator;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.interfaces.DecodedJWT;
import com.mashibing.common.dto.TokenResult;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
/**
* @author fangyu
* @version v1.0.0
* @date 2022/7/25 23:12
*/
public class JwtUtils {
/**
* salt
*/
private static final String SIGN = "CPFsb!@#$$";
private static final String JWT_KEY_PHONE = "phone";
/**
* 12
*/
private static final String JWT_KEY_IDENTITY = "identity";
/**
* token
*/
private static final String JWT_TOKEN_TYPE = "tokenType";
private static final String JWT_TOKEN_TIME = "tokenTime";
/**
* token
* @param passengerPhone
* @param identity
* @param tokenType
* @return
*/
public static String generatorToken(String passengerPhone, String identity, String tokenType) {
Map<String, String> map = new HashMap<>();
map.put(JWT_KEY_PHONE, passengerPhone);
map.put(JWT_KEY_IDENTITY, identity);
map.put(JWT_TOKEN_TYPE, tokenType);
// 防止每次生成的token一样。
map.put(JWT_TOKEN_TIME, Calendar.getInstance().getTime().toString());
JWTCreator.Builder builder = JWT.create();
// 整合map
map.forEach(
(k, v) -> {
builder.withClaim(k, v);
}
);
// 整合过期时间
// builder.withExpiresAt(date);
// 生成 token
String sign = builder.sign(Algorithm.HMAC256(SIGN));
return sign;
}
/**
* token
* @param token
* @return
*/
public static TokenResult parseToken(String token) {
DecodedJWT verify = JWT.require(Algorithm.HMAC256(SIGN)).build().verify(token);
String phone = verify.getClaim(JWT_KEY_PHONE).asString();
String identity = verify.getClaim(JWT_KEY_IDENTITY).asString();
TokenResult tokenResult = new TokenResult();
tokenResult.setPhone(phone);
tokenResult.setIdentity(identity);
return tokenResult;
}
/**
* tokentoken
*
* @param token
* @return
*/
public static TokenResult checkToken(String token) {
TokenResult tokenResult = null;
try {
tokenResult = JwtUtils.parseToken(token);
} catch (Exception e) {
}
return tokenResult;
}
public static void main(String[] args) {
String s = generatorToken("13910733521", "1", "accessToken");
System.out.println("生成的token" + s);
System.out.println("解析-----------------");
TokenResult tokenResult = parseToken(s);
System.out.println("手机号:" + tokenResult.getPhone());
System.out.println("身份:" + tokenResult.getIdentity());
}
}

@ -0,0 +1,39 @@
package com.mashibing.common.util;
/**
* @author fangyu
* @version v1.0.0
* @date 2022/7/25 23:05
*/
public class RedisPrefixUtils {
/**
*
*/
public static String verificationCodePrefix = "passenger-verification-code-";
/**
* token
*/
public static String tokenPrefix = "token-";
/**
* key
*
* @param passengerPhone
* @return
*/
public static String generatorKeyByPhone(String passengerPhone) {
return verificationCodePrefix + passengerPhone;
}
/**
* token
*
* @param phone
* @param identity
* @return
*/
public static String generatorTokenKey(String phone, String identity, String tokenType) {
return tokenPrefix + phone + "-" + identity + "-" + tokenType;
}
}

@ -15,6 +15,14 @@
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<modules> <modules>
<module>api-passenger</module> <module>api-passenger</module>
<module>service-verificationcode</module>
<module>service-driver-user</module>
<module>service-passenger-user</module>
<module>service-map</module>
<module>service-price</module>
<module>api-boss</module>
<module>api-driver</module>
<module>internal-common</module>
</modules> </modules>
<packaging>pom</packaging> <packaging>pom</packaging>
@ -34,5 +42,36 @@
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.14.0</version>
</dependency>
<dependency>
<groupId>com.mashibing</groupId>
<artifactId>internal-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2021.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>2020.0.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies> </dependencies>
</dependencyManagement>
</project> </project>

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>online-taxi-public</artifactId>
<groupId>com.mashibing</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>service-driver-user</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
</project>

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>online-taxi-public</artifactId>
<groupId>com.mashibing</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>service-map</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
</project>

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>online-taxi-public</artifactId>
<groupId>com.mashibing</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>service-passenger-user</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
</project>

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>online-taxi-public</artifactId>
<groupId>com.mashibing</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>service-price</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
</project>

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>online-taxi-public</artifactId>
<groupId>com.mashibing</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>service-verificationcode</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<!-- add nacos -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

@ -0,0 +1,19 @@
package com.mashibing.service.verificationcode;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
/**
* @author fangyu
* @version v1.0.0
* @date 2022/7/26 00:13
*/
@SpringBootApplication
@EnableDiscoveryClient
public class VerificationCodeApplication {
public static void main(String[] args) {
SpringApplication.run(VerificationCodeApplication.class, args);
}
}

@ -0,0 +1,32 @@
package com.mashibing.service.verificationcode.controller;
import com.mashibing.common.dto.ResponseResult;
import com.mashibing.common.response.NumberCodeResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
/**
* @author fangyu
* @version v1.0.0
* @date 2022/7/25 21:47
*/
@RestController
public class NumberCodeController {
@GetMapping("/numberCode/{size}")
public ResponseResult numberCode(@PathVariable("size") int size) {
System.out.println("size:" + size);
// 生成验证码
double mathRandom = (Math.random() * 9 + 1) * (Math.pow(10, size - 1));
System.out.println(mathRandom);
int resultInt = (int) mathRandom;
System.out.println("generator src code:" + resultInt);
// 定义返回值
NumberCodeResponse response = new NumberCodeResponse();
response.setNumberCode(resultInt);
return ResponseResult.success(response);
}
}

@ -0,0 +1,18 @@
package com.mashibing.service.verificationcode.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author fangyu
* @version v1.0.0
* @date 2022/7/26 00:13
*/
@RestController
public class TestController {
@GetMapping("/test")
public String test(){
return "service-verificationcode";
}
}

@ -0,0 +1,9 @@
server:
port: 8082
spring:
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
application:
name: service-verificationcode
Loading…
Cancel
Save