|
|
|
|
package com.gszc.controller;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.gszc.build.Result;
|
|
|
|
|
import com.gszc.build.ResultBuilder;
|
|
|
|
|
import com.gszc.entity.MiniUser;
|
|
|
|
|
import com.gszc.service.LoginService;
|
|
|
|
|
import com.gszc.service.MiniAppService;
|
|
|
|
|
import com.gszc.util.JwtUtils;
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
|
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.Cookie;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
|
|
@Api(value = "工商注册 API", tags = {"登录api"})
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/login")
|
|
|
|
|
public class LoginController {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
LoginService loginService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MiniAppService miniAppService;
|
|
|
|
|
|
|
|
|
|
@PostMapping("/decryptUserInfo")
|
|
|
|
|
@ApiOperation(value = "解密用户信息", notes = "解密用户信息")
|
|
|
|
|
@ApiImplicitParams({
|
|
|
|
|
@ApiImplicitParam(name = "userId", value = "userId", dataType = "string", paramType = "query"),
|
|
|
|
|
@ApiImplicitParam(name = "encryptedData", value = "加密数据", dataType = "string", paramType = "query"),
|
|
|
|
|
@ApiImplicitParam(name = "ivStr", value = "iv", dataType = "string", paramType = "query"),
|
|
|
|
|
@ApiImplicitParam(name = "signature", value = "签名", dataType = "string", paramType = "query"),
|
|
|
|
|
@ApiImplicitParam(name = "rawData", value = "原始数据", dataType = "string", paramType = "query"),
|
|
|
|
|
})
|
|
|
|
|
public Result decryptUserInfo(String userId,String encryptedData ,String ivStr,String signature,String rawData){
|
|
|
|
|
MiniUser miniUser = miniAppService.decryptUserInfo(userId, encryptedData, ivStr, signature, rawData);
|
|
|
|
|
return ResultBuilder.withPayload(miniUser).build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/isNewUserLogin")
|
|
|
|
|
@ApiOperation(value = "是否新用户", notes = "是否新用户")
|
|
|
|
|
@ApiImplicitParams({
|
|
|
|
|
@ApiImplicitParam(name = "code", value = "code", dataType = "string", paramType = "query"),
|
|
|
|
|
})
|
|
|
|
|
public Result isNewUserLogin(String code,HttpServletResponse response){
|
|
|
|
|
JSONObject result = miniAppService.isNewUser(code);
|
|
|
|
|
Cookie cookie = new Cookie("username", result.getString("openId"));
|
|
|
|
|
cookie.setMaxAge(60 * 60);
|
|
|
|
|
cookie.setPath("/");
|
|
|
|
|
response.addCookie(cookie);
|
|
|
|
|
String sign = JwtUtils.sign(result.getString("openId"), result.getString("openId"),"miniUser");
|
|
|
|
|
result.put("token",sign);
|
|
|
|
|
result.remove("openId");
|
|
|
|
|
return ResultBuilder.withPayload(result).build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "获得手机号码", notes = "获得手机号码")
|
|
|
|
|
@ApiImplicitParams({
|
|
|
|
|
@ApiImplicitParam(name = "userId", value = "userId", dataType = "string", paramType = "query"),
|
|
|
|
|
@ApiImplicitParam(name = "encryptedData", value = "加密数据", dataType = "string", paramType = "query"),
|
|
|
|
|
@ApiImplicitParam(name = "ivStr", value = "iv", dataType = "string", paramType = "query"),
|
|
|
|
|
@ApiImplicitParam(name = "signature", value = "签名", dataType = "string", paramType = "query"),
|
|
|
|
|
@ApiImplicitParam(name = "rawData", value = "原始数据", dataType = "string", paramType = "query"),
|
|
|
|
|
})
|
|
|
|
|
@PostMapping("/decryptPhoneNumber")
|
|
|
|
|
public Result decryptPhoneNumber(String userId,String encryptedData ,String ivStr,String signature,String rawData){
|
|
|
|
|
MiniUser miniUser = miniAppService.decryptPhoneNumber(userId, encryptedData, ivStr, signature, rawData);
|
|
|
|
|
return ResultBuilder.withPayload(miniUser).build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// @RequestMapping("/")
|
|
|
|
|
// public void a(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
|
|
|
|
// //消息来源可靠性验证
|
|
|
|
|
// String signature = request.getParameter("signature");// 微信加密签名
|
|
|
|
|
// String timestamp = request.getParameter("timestamp");// 时间戳
|
|
|
|
|
// String nonce = request.getParameter("nonce"); // 随机数
|
|
|
|
|
// String echostr = request.getParameter("echostr");//成为开发者验证
|
|
|
|
|
// //确认此次GET请求来自微信服务器,原样返回echostr参数内容,则接入生效,成为开发者成功,否则接入失败
|
|
|
|
|
// System.out.println();
|
|
|
|
|
// response.getWriter().println(request.getParameter("echostr"));
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// public void post(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
|
|
|
|
// // TODO 消息的接收、处理、响应
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
/**
|
|
|
|
|
* pc端登录
|
|
|
|
|
*
|
|
|
|
|
* @param username
|
|
|
|
|
* @param password
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/login")
|
|
|
|
|
@ApiImplicitParams({
|
|
|
|
|
@ApiImplicitParam(name = "username", value = "用户名", dataType = "string", paramType = "query"),
|
|
|
|
|
@ApiImplicitParam(name = "password", value = "密码", dataType = "string", paramType = "query")
|
|
|
|
|
})
|
|
|
|
|
public Result login(String username, String password, HttpServletResponse response) {
|
|
|
|
|
boolean login = loginService.login(username, password);
|
|
|
|
|
if (login) {
|
|
|
|
|
Cookie cookie = new Cookie("username", username);
|
|
|
|
|
cookie.setMaxAge(60 * 60);
|
|
|
|
|
cookie.setPath("/");
|
|
|
|
|
response.addCookie(cookie);
|
|
|
|
|
String sign = JwtUtils.sign(username, password,"pcUser");
|
|
|
|
|
return ResultBuilder.withPayload(sign).build();
|
|
|
|
|
} else {
|
|
|
|
|
return ResultBuilder.error("登录失败").build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// @PostMapping("/getOpenid")
|
|
|
|
|
// public Result getOpenid(String code) {
|
|
|
|
|
//
|
|
|
|
|
// JSONObject token = loginService.getToken(code);
|
|
|
|
|
// String sign = JwtUtils.sign(token.getString("openid"), token.getString("openid"));
|
|
|
|
|
// return ResultBuilder.withPayload(sign).build();
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// @PostMapping("/getUser")
|
|
|
|
|
// @ApiImplicitParam(name = "token", value = "token", required = true, dataType = "String", paramType = "header")
|
|
|
|
|
// public Result getUser(HttpServletRequest request){
|
|
|
|
|
// String token = request.getHeader("token");
|
|
|
|
|
// String username = JwtUtils.getUsername(token);
|
|
|
|
|
// WxUser user = loginService.getUser(username);
|
|
|
|
|
// return ResultBuilder.withPayload(user).build();
|
|
|
|
|
// }
|
|
|
|
|
}
|