Commit 1217a54a by zhoujinghao

对外提供登陆接口提交

1 parent 2ec6fb68
......@@ -15,7 +15,7 @@ import java.io.IOException;
@RestController
@RequestMapping("/nafmii/admin/excel")
@Api(tags = "2.0.1", description = "中心端批量导入Excel接口【zjh】")
@Api(tags = "2.0.3", description = "中心端批量导入Excel接口【zjh】")
public class ImportExcelController {
@Resource
private ImportExcelService iImportExcelService;
......
/*
* Copyright 2007-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.net.*;
import java.io.*;
import java.nio.channels.*;
import java.util.Properties;
public class MavenWrapperDownloader {
private static final String WRAPPER_VERSION = "0.5.6";
/**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
*/
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
/**
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
* use instead of the default one.
*/
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
".mvn/wrapper/maven-wrapper.properties";
/**
* Path where the maven-wrapper.jar will be saved to.
*/
private static final String MAVEN_WRAPPER_JAR_PATH =
".mvn/wrapper/maven-wrapper.jar";
/**
* Name of the property which should be used to override the default download url for the wrapper.
*/
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
public static void main(String args[]) {
System.out.println("- Downloader started");
File baseDirectory = new File(args[0]);
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
// If the maven-wrapper.properties exists, read it and check if it contains a custom
// wrapperUrl parameter.
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
String url = DEFAULT_DOWNLOAD_URL;
if (mavenWrapperPropertyFile.exists()) {
FileInputStream mavenWrapperPropertyFileInputStream = null;
try {
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
Properties mavenWrapperProperties = new Properties();
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
} catch (IOException e) {
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
} finally {
try {
if (mavenWrapperPropertyFileInputStream != null) {
mavenWrapperPropertyFileInputStream.close();
}
} catch (IOException e) {
// Ignore ...
}
}
}
System.out.println("- Downloading from: " + url);
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
if (!outputFile.getParentFile().exists()) {
if (!outputFile.getParentFile().mkdirs()) {
System.out.println(
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
}
}
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
try {
downloadFileFromURL(url, outputFile);
System.out.println("Done");
System.exit(0);
} catch (Throwable e) {
System.out.println("- Error downloading");
e.printStackTrace();
System.exit(1);
}
}
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
String username = System.getenv("MVNW_USERNAME");
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
}
URL website = new URL(urlString);
ReadableByteChannel rbc;
rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destination);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
rbc.close();
}
}
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.nafmii</groupId>
<artifactId>nafmii-app</artifactId>
<version>0.0.1-SNAPSHOT</version><!-- lookup parent from repository -->
</parent>
<groupId>org.nafmii</groupId>
<artifactId>app-client</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>app-client</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<httpClient.version>4.5.3</httpClient.version>
<fastjson.version>1.2.58</fastjson.version>
<ojdbc.version>10.2.0.4</ojdbc.version>
<jjwt.version>0.9.1</jjwt.version>
</properties>
<dependencies>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</project>
package org.nafmii.app.client.user.param;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* @author:zhoujh
* @Function:TODO
* @date 2021/4/26 16:41
* @ClassName:
* @version:
* @remark:
*/
@Data
@ApiModel("app用户登陆参数对象")
public class LoginClientParam {
@NotNull(message = "手机号或登录账号不能为空")
@ApiModelProperty("手机号/登录账号")
private String phone;
@ApiModelProperty("登陆密码")
private String loginPwd;
@ApiModelProperty("验证码")
private String code;
}
package org.nafmii.app.client.user.service;
import org.nafmii.app.client.user.param.LoginClientParam;
import org.nafmii.app.client.user.vo.UserClientVO;
import org.nafmii.common.response.ApiResponse;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* @author:zhoujh
* @Function:TODO
* @date 2021/5/11 13:42
* @ClassName:对外提供用户接口
* @version:1.0
* @remark:
*/
@FeignClient("nafmii-app")
@RequestMapping("/app/nafmii/user")
public interface UserClient {
@PostMapping("/userLogin")
@ResponseBody
ApiResponse<UserClientVO> userLogin (@RequestBody @Validated LoginClientParam loginClientParam);
@PostMapping("/phoneLogin")
@ResponseBody
ApiResponse<UserClientVO> phoneLogin (@RequestBody @Validated LoginClientParam loginClientParam);
}
package org.nafmii.app.client.user.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* @author:zhoujh
* @Function:TODO
* @date 2021/4/25 10:22
* @ClassName:
* @version:
* @remark:
*/
@Data
@ApiModel("用户返回报文")
public class UserClientVO {
private Long id;
@ApiModelProperty(value = "昵称")
private String userName;
@ApiModelProperty(value = "登录密码")
private String loginPwd;
@ApiModelProperty(value = "中文姓名")
private String realName;
@ApiModelProperty(value = "手机号/登录账号")
private String phone;
@ApiModelProperty(value = "出生日期")
private String birthday;
@ApiModelProperty(value = "邮箱")
private String email;
@ApiModelProperty(value = "头像图片地址")
private String headPicture;
@ApiModelProperty(value = "国籍")
private String nationality;
@ApiModelProperty(value = "单位全称")
private String unitName;
@ApiModelProperty(value = "微信OPENT_ID")
private String openId;
@ApiModelProperty(value = "是否开启指纹登录 0 未开启 1 已开启")
private String figerprintFalg;
@ApiModelProperty(value = "是否开启人脸识别登录 0 未开启 1 已开启")
private String faceidFalg;
@ApiModelProperty(value = "创建时间")
private Date createTime;
@ApiModelProperty(value = "更新时间")
private Date updateTime;
@ApiModelProperty(value = "是否有效标识 0 有效用户 1无效用户")
private String isEnable;
@ApiModelProperty(value = "token")
private String authorization;
@ApiModelProperty(value = "验证码登陆判断是否第一次登陆 0是 1否")
private String loginType;
}
......@@ -52,6 +52,11 @@
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.nafmii</groupId>
<artifactId>app-client</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
......
package org.nafmii.app.feign.controller;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.nafmii.app.client.user.service.UserClient;
import org.nafmii.app.feign.service.UserFeignService;
import org.nafmii.app.user.param.LoginParam;
import org.nafmii.app.user.vo.UserVO;
import org.nafmii.common.response.ApiResponse;
import org.nafmii.common.utils.BeanTransferUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
/**
* @author:zhoujh
* @Function:TODO
* @date 2021/5/11 14:12
* @ClassName:
* @version:
* @remark:
*/
@RestController
@RequestMapping("/app/nafmii/user/client")
@Api(tags = "2.0.4", description = "用户登陆对外提供【zjh】")
public class UserFeignController {
@Resource
private UserFeignService feignService;
@ApiOperation( value = "app用户登陆接口",notes = "app用户登陆接口")
@PostMapping("/userLogin")
@ResponseBody
public ApiResponse userLogin (@RequestBody JSONObject object){
ApiResponse userLogin = feignService.userLogin(object);
return userLogin;
}
@ApiOperation( value = "app手机号登陆接口",notes = "app手机号登陆接口")
@PostMapping("/phoneLogin")
@ResponseBody
public ApiResponse phoneLogin (@RequestBody JSONObject object){
ApiResponse phoneLogin = feignService.phoneLogin(object);
return phoneLogin;
}
}
package org.nafmii.app.feign.service;
import com.alibaba.fastjson.JSONObject;
import org.nafmii.common.response.ApiResponse;
/**
* @author:zhoujh
* @Function:TODO
* @date 2021/5/11 14:21
* @ClassName:
* @version:
* @remark:
*/
public interface UserFeignService {
//对外提供手机号登陆接口
ApiResponse phoneLogin(JSONObject object);
//对外提供用户登陆接口
ApiResponse userLogin(JSONObject object);
}
package org.nafmii.app.feign.service.impl;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.nafmii.app.client.user.param.LoginClientParam;
import org.nafmii.app.client.user.service.UserClient;
import org.nafmii.app.feign.service.UserFeignService;
import org.nafmii.app.feign.vo.UserFeignVO;
import org.nafmii.common.response.ApiResponse;
import org.nafmii.common.utils.BeanTransferUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/**
* @author:zhoujh
* @Function:TODO
* @date 2021/5/11 14:21
* @ClassName:
* @version:
* @remark:
*/
@Service
@Slf4j
public class UserFeignServiceImpl implements UserFeignService {
@Resource
private UserClient userClient;
/**
* 对外提供手机号登陆接口
* @param object
* @return
*/
@Override
public ApiResponse phoneLogin(JSONObject object) {
ApiResponse<UserFeignVO> apiResponse = new ApiResponse<>();
log.info("对外提供手机号登陆接口相关json参数========》{}",object.toJSONString());
LoginClientParam loginClientParam = BeanTransferUtils.transfer(object, LoginClientParam.class);
log.info("对外提供手机号登陆接口相关对象参数========》{}",loginClientParam);
if("002".equals(object.get("apiCode"))){
apiResponse = userClient.phoneLogin(loginClientParam);
}
return apiResponse;
}
/**
* 对外提供用户登陆接口
* @param object
* @return
*/
@Override
public ApiResponse userLogin(JSONObject object) {
ApiResponse<UserFeignVO> apiResponse = new ApiResponse<>();
log.info("对外提供登陆接口相关json参数========》{}",object.toJSONString());
LoginClientParam loginClientParam = BeanTransferUtils.transfer(object, LoginClientParam.class);
log.info("对外提供登陆接口相关对象参数========》{}",loginClientParam);
if("001".equals(object.get("apiCode"))){
apiResponse = userClient.userLogin(loginClientParam);
}
return apiResponse;
}
}
package org.nafmii.app.feign.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* @author:zhoujh
* @Function:TODO
* @date 2021/4/25 10:22
* @ClassName:
* @version:
* @remark:
*/
@Data
@ApiModel("用户返回报文")
public class UserFeignVO {
private Long id;
@ApiModelProperty(value = "昵称")
private String userName;
@ApiModelProperty(value = "登录密码")
private String loginPwd;
@ApiModelProperty(value = "中文姓名")
private String realName;
@ApiModelProperty(value = "手机号/登录账号")
private String phone;
@ApiModelProperty(value = "出生日期")
private String birthday;
@ApiModelProperty(value = "邮箱")
private String email;
@ApiModelProperty(value = "头像图片地址")
private String headPicture;
@ApiModelProperty(value = "国籍")
private String nationality;
@ApiModelProperty(value = "单位全称")
private String unitName;
@ApiModelProperty(value = "微信OPENT_ID")
private String openId;
@ApiModelProperty(value = "是否开启指纹登录 0 未开启 1 已开启")
private String figerprintFalg;
@ApiModelProperty(value = "是否开启人脸识别登录 0 未开启 1 已开启")
private String faceidFalg;
@ApiModelProperty(value = "创建时间")
private Date createTime;
@ApiModelProperty(value = "更新时间")
private Date updateTime;
@ApiModelProperty(value = "是否有效标识 0 有效用户 1无效用户")
private String isEnable;
@ApiModelProperty(value = "token")
private String authorization;
@ApiModelProperty(value = "验证码登陆判断是否第一次登陆 0是 1否")
private String loginType;
}
package org.nafmii.app.user.controller;
import org.nafmii.app.user.param.LoginParam;
import org.nafmii.common.response.ApiResponse;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* @author lvyp
* @date 2021/5/11
*/
@FeignClient("nafmii-app")
@RequestMapping(value = "")
public interface TestClinet {
@PostMapping("/login")
@ResponseBody
public ApiResponse login(@RequestBody LoginParam loginParam);
}
......@@ -34,15 +34,6 @@ import java.io.File;
public class UserController {
@Resource
private UserService userService;
@Resource
private TestClinet testClinet;
@ApiOperation( value = "模拟用户登陆",notes = "模拟用户登陆")
@PostMapping("/loginTest")
@ResponseBody
public ApiResponse<UserVO> loginTest (){
ApiResponse<UserVO> login = userService.login();
return login;
}
@ApiOperation( value = "app用户注册接口",notes = "app用户注册接口")
@PostMapping("/register")
......@@ -52,14 +43,23 @@ public class UserController {
return register;
}
@ApiOperation( value = "app用户登陆接口(密码加验证码)",notes = "app用户登陆接口(密码加验证码)")
@ApiOperation( value = "app用户登陆接口",notes = "app用户登陆接口")
@PostMapping("/userLogin")
@ResponseBody
public ApiResponse<UserVO> login (@RequestBody @Validated LoginParam loginParam){
ApiResponse<UserVO> login = userService.userLogin(loginParam);
return login;
}
@ApiOperation( value = "app用户登陆接口(密码加验证码)",notes = "app用户登陆接口(密码加验证码)")
@ApiOperation( value = "app手机号登陆接口",notes = "app手机号登陆接口")
@PostMapping("/phoneLogin")
@ResponseBody
public ApiResponse<UserVO> phoneLogin (@RequestBody @Validated LoginParam loginParam){
ApiResponse<UserVO> phoneLogin = userService.phoneLogin(loginParam);
return phoneLogin;
}
@ApiOperation( value = "测试ftp",notes = "测试ftp")
@PostMapping("/testFtp")
@ResponseBody
public ApiResponse testFtp (){
......@@ -67,16 +67,4 @@ public class UserController {
System.out.println(ftpClient);
return new ApiResponse();
}
@ApiOperation( value = "app用户登陆接口(密码加验证码)",notes = "app用户登陆接口(密码加验证码)")
@PostMapping("/yyy")
@ResponseBody
public ApiResponse yyy (@RequestBody JSONObject object){
LoginParam loginParam = BeanTransferUtils.transfer(object,LoginParam.class);
if("001".equals(object.get("apiCode"))){
testClinet.login(loginParam);
}
return new ApiResponse();
}
}
......@@ -16,8 +16,6 @@ import org.nafmii.common.response.ApiResponse;
* @remark:
*/
public interface UserService {
//模拟用户登陆接口
ApiResponse<UserVO> login();
//手机号登陆接口
ApiResponse<UserVO> phoneLogin(LoginParam loginParam);
//app注册接口
......
......@@ -50,41 +50,6 @@ public class UserServiceImpl implements UserService {
@Autowired
StringRedisTemplate stringRedisTemplate;
/**
* 模拟用户登陆
* @return
*/
@Override
public ApiResponse<UserVO> login() {
ApiResponse result = new ApiResponse();
long EXPIRITION = 1000 * 60 * 60 * 24 * 7;
//假设验证数据通过
UserVO userVO = new UserVO();
userVO.setLoginPwd("zzz");
userVO.setUserName("zzz");
List<UserAndRoleVo> roleList =new ArrayList<>();
UserAndRoleVo roleVo = new UserAndRoleVo();
UserAndRoleVo roleTwoVo = new UserAndRoleVo();
roleVo.setRole("a");
roleList.add(roleVo);
roleTwoVo.setRole("b");
roleList.add(roleTwoVo);
// userVO.setAuthorities(roleList);
StringBuilder sbf = new StringBuilder();
for (UserAndRoleVo role:roleList
) {
sbf=sbf.append(role.getRole()+",");
}
//处理字符串
String sRole = sbf.toString();
String substring = sRole.substring(0, sRole.lastIndexOf(","));
Map<String,Object> map = new HashMap<>();
map.put(HttpClientHeaderEnum.USER_HEADER_USER_ID.getCode(),userVO.getId());
String token = JwtUtils.generateJsonWebToken(map,EXPIRITION);
// userVO.setToken(token);
result.setData(userVO);
return result;
}
/**
* 手机号登陆接口
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!