1小程序登录完
This commit is contained in:
parent
1ce0cca488
commit
b9be77fd2c
@ -4,12 +4,14 @@ import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
@EnableSwagger2
|
||||
@SpringBootApplication
|
||||
@ComponentScan("cn.com")
|
||||
@MapperScan({"cn.com.**.dao"})
|
||||
@EnableScheduling
|
||||
public class BusinessCardApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
@ -37,6 +37,10 @@ public class AccessTokenManager {
|
||||
cardUserVOMap.remove(key);
|
||||
}
|
||||
|
||||
public Map<String, CardUserDTO> getKeyList(){
|
||||
return cardUserVOMap;
|
||||
}
|
||||
|
||||
|
||||
public void updateLastActivityTime(String key){
|
||||
CardUserDTO dto = this.getKey(key);
|
||||
|
@ -7,6 +7,8 @@ import cn.com.tenlion.service.carduser.ICardUserService;
|
||||
import cn.com.tenlion.util.AesUtil;
|
||||
import cn.com.tenlion.util.annotation.AccessRightsCheck;
|
||||
import cn.com.tenlion.util.enumeration.Auth;
|
||||
import cn.com.tenlion.util.enumeration.ErrorResultCodeEnum;
|
||||
import cn.com.tenlion.util.result.ErrorResult;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.pagehelper.util.StringUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -20,6 +22,8 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import static cn.com.tenlion.util.enumeration.ErrorResultCodeEnum.TOKEN_ERROR;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @version 1.0
|
||||
@ -74,12 +78,12 @@ public class CheckAuthInterceptor implements HandlerInterceptor {
|
||||
response.setStatus(response.SC_UNAUTHORIZED);
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setContentType("application/json; charset=utf-8");
|
||||
JSONObject res = new JSONObject();
|
||||
res.put("status","401");
|
||||
res.put("msg","token不合法");
|
||||
ErrorResult error= new ErrorResult();
|
||||
error.setCode(TOKEN_ERROR.getValue());
|
||||
error.setMsg("token不合法");
|
||||
PrintWriter out = null ;
|
||||
out = response.getWriter();
|
||||
out.write(res.toString());
|
||||
out.write(error.toString());
|
||||
out.flush();
|
||||
out.close();
|
||||
return false;
|
||||
|
@ -32,6 +32,19 @@ import java.util.Map;
|
||||
public class CardUserController {
|
||||
@Autowired
|
||||
private ICardUserService cardUserService;
|
||||
|
||||
@ApiOperation(value = "用户登录", notes = "用户登录接口")
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("logincarduser")
|
||||
@CheckRequestBodyAnnotation
|
||||
public SuccessResult loginCardUser(@RequestBody CardUserVO cardUserVO) throws Exception {
|
||||
return cardUserService.saveCardUser(cardUserVO);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ApiOperation(value = "新增用户表", notes = "新增用户表接口")
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@PostMapping("savecarduser")
|
||||
|
@ -6,8 +6,10 @@ import cn.com.tenlion.pojo.dtos.weixinresult.WeiXinAuthResult;
|
||||
import cn.com.tenlion.pojo.vos.carduser.CardUserVO;
|
||||
import cn.com.tenlion.service.carduser.ICardUserService;
|
||||
import cn.com.tenlion.util.AesUtil;
|
||||
import cn.com.tenlion.util.annotation.AccessRightsCheck;
|
||||
import cn.com.tenlion.util.check.CheckRequestBodyAnnotation;
|
||||
import cn.com.tenlion.util.cons.ISystemConstant;
|
||||
import cn.com.tenlion.util.enumeration.Auth;
|
||||
import cn.com.tenlion.util.exception.ParamsException;
|
||||
import cn.com.tenlion.util.exception.RemoveException;
|
||||
import cn.com.tenlion.util.exception.SearchException;
|
||||
@ -16,6 +18,7 @@ import cn.com.tenlion.util.result.SuccessResult;
|
||||
import cn.com.tenlion.util.result.SuccessResultData;
|
||||
import cn.com.tenlion.util.vx.WxApiUtil;
|
||||
import io.swagger.annotations.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import cn.com.tenlion.controller.AbstractController;
|
||||
@ -50,42 +53,64 @@ public class CardUserAppController extends AbstractController {
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@GetMapping("weiXinLoginBySmallRoutine"+ISystemConstant.RELEASE_SUFFIX+"/{vxCode}/{vxPhone}")
|
||||
public SuccessResult weiXinLoginBySmallRoutine(
|
||||
@PathVariable("vxCode") String vxCode, @PathVariable("vxPhone") String vxPhone
|
||||
) throws Exception {
|
||||
@GetMapping("weiXinLoginBySmallRoutine/{vxCode}")
|
||||
@AccessRightsCheck(auth= Auth.NOCHECK,authUrl="",operation="小程序登录")
|
||||
public SuccessResult weiXinLoginBySmallRoutine(@PathVariable("vxCode") String vxCode) throws Exception {
|
||||
WxApiUtil wxapi = new WxApiUtil();
|
||||
WeiXinAuthResult austerest = wxapi.weiXinLoginGetAuth(vxCode, ISystemConstant.VX_APP_ID, ISystemConstant.VX_APP_SECRET, ISystemConstant.VX_GRANT_TYPE);
|
||||
if (austerest == null) {
|
||||
throw new ParamsException("系统异常-1");
|
||||
}
|
||||
if (!austerest.getErrcode().equals("0")) {
|
||||
if (austerest.getOpenid() == null || StringUtils.isEmpty(austerest.getOpenid())) {
|
||||
throw new ParamsException("系统异常-2");
|
||||
}
|
||||
CardUserDTO carduserdto = cardUserService.getCardUserByVxOpenId(austerest.getOpenid());
|
||||
String userId;
|
||||
CardUserDTO userdto = null;
|
||||
String checkPhone = "_0"; //未绑定手机号
|
||||
if (carduserdto != null) {
|
||||
userId = carduserdto.getCardUserId();
|
||||
userdto = carduserdto;
|
||||
checkPhone = "_1";
|
||||
} else {
|
||||
CardUserVO carduservo = new CardUserVO();
|
||||
carduservo.setUserName("user1");
|
||||
carduservo.setUserPassword("123456");
|
||||
carduservo.setVxOpenId(austerest.getOpenid());
|
||||
carduservo.setVxUnionId(austerest.getUnionid());
|
||||
carduservo.setUserPhone(vxPhone);
|
||||
carduservo.setUserName(vxPhone);
|
||||
userId = cardUserService.saveCardUserReturnId(carduservo);
|
||||
userdto = cardUserService.getCardUserByVxOpenId(userId);
|
||||
userdto = cardUserService.getCardUserById(userId);
|
||||
}
|
||||
String token = AesUtil.aesCommonEncoder(ISystemConstant.APP_TOKEN_AES_KEY, userId);
|
||||
token = token+checkPhone;
|
||||
AccessTokenManager.getInstance().setKey(token, userdto);
|
||||
AccessTokenManager.getInstance().updateLastActivityTime(token);
|
||||
return new SuccessResultData<>(token);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 小程序登录绑定手机号
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@GetMapping("weiXinLoginBindPhone/{phone}")
|
||||
@AccessRightsCheck(auth= Auth.NOCHECK,authUrl="",operation="小程序登录")
|
||||
public SuccessResult weiXinLoginBySmallRoutine(@PathVariable("phone") String phone,@RequestHeader("token") String token) throws Exception {
|
||||
CardUserDTO user = AccessTokenManager.getInstance().getKey(token);
|
||||
user.setUserPhone(phone);
|
||||
user.setUserName(phone);
|
||||
CardUserVO vo = new CardUserVO();
|
||||
vo.setUserName(phone);
|
||||
vo.setUserPhone(phone);
|
||||
cardUserService.updateCardUser(user.getCardUserId(),vo);
|
||||
String token2 = AesUtil.aesCommonEncoder(ISystemConstant.APP_TOKEN_AES_KEY, user.getCardUserId());
|
||||
token2 = token2+"_1";
|
||||
AccessTokenManager.getInstance().setKey(token2, user);
|
||||
AccessTokenManager.getInstance().updateLastActivityTime(token2);
|
||||
AccessTokenManager.getInstance().removeKey(token);
|
||||
return new SuccessResultData<>(token2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -19,6 +19,11 @@ public class CardUserDTO {
|
||||
* 用户姓名
|
||||
*/
|
||||
private String userName;
|
||||
/**
|
||||
* 用户密码
|
||||
*/
|
||||
private String userPassword;
|
||||
|
||||
/**
|
||||
* 用户手机
|
||||
*/
|
||||
@ -26,11 +31,11 @@ public class CardUserDTO {
|
||||
/**
|
||||
* 用户开放平台唯一标识
|
||||
*/
|
||||
private String VxUnionId;
|
||||
private String vxUnionId;
|
||||
/**
|
||||
* 微信用户唯一标识
|
||||
*/
|
||||
private String VxOpenId;
|
||||
private String vxOpenId;
|
||||
|
||||
/**
|
||||
* 账号最后活动时间(用于token过期判断)
|
||||
@ -53,6 +58,14 @@ public class CardUserDTO {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public String getUserPassword() {
|
||||
return userPassword;
|
||||
}
|
||||
|
||||
public void setUserPassword(String userPassword) {
|
||||
this.userPassword = userPassword;
|
||||
}
|
||||
|
||||
public String getUserPhone() {
|
||||
return userPhone == null ? "" : userPhone.trim();
|
||||
}
|
||||
@ -62,19 +75,19 @@ public class CardUserDTO {
|
||||
}
|
||||
|
||||
public String getVxUnionId() {
|
||||
return VxUnionId == null ? "" : VxUnionId.trim();
|
||||
return vxUnionId == null ? "" : vxUnionId.trim();
|
||||
}
|
||||
|
||||
public void setVxUnionId(String VxUnionId) {
|
||||
this.VxUnionId = VxUnionId;
|
||||
public void setVxUnionId(String vxUnionId) {
|
||||
this.vxUnionId = vxUnionId;
|
||||
}
|
||||
|
||||
public String getVxOpenId() {
|
||||
return VxOpenId == null ? "" : VxOpenId.trim();
|
||||
return vxOpenId == null ? "" : vxOpenId.trim();
|
||||
}
|
||||
|
||||
public void setVxOpenId(String VxOpenId) {
|
||||
this.VxOpenId = VxOpenId;
|
||||
public void setVxOpenId(String vxOpenId) {
|
||||
this.vxOpenId = vxOpenId;
|
||||
}
|
||||
|
||||
public long getLastActivityTime() {
|
||||
|
@ -14,6 +14,11 @@ public class CardUserVO {
|
||||
* 用户姓名
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 用户密码
|
||||
*/
|
||||
private String userPassword;
|
||||
/**
|
||||
* 用户手机
|
||||
*/
|
||||
@ -21,11 +26,11 @@ public class CardUserVO {
|
||||
/**
|
||||
* 用户开放平台唯一标识
|
||||
*/
|
||||
private String VxUnionId;
|
||||
private String vxUnionId;
|
||||
/**
|
||||
* 微信用户唯一标识
|
||||
*/
|
||||
private String VxOpenId;
|
||||
private String vxOpenId;
|
||||
|
||||
|
||||
public String getUserName() {
|
||||
@ -36,6 +41,14 @@ public class CardUserVO {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public String getUserPassword() {
|
||||
return userPassword;
|
||||
}
|
||||
|
||||
public void setUserPassword(String userPassword) {
|
||||
this.userPassword = userPassword;
|
||||
}
|
||||
|
||||
public String getUserPhone() {
|
||||
return userPhone == null ? "" : userPhone.trim();
|
||||
}
|
||||
@ -45,19 +58,19 @@ public class CardUserVO {
|
||||
}
|
||||
|
||||
public String getVxUnionId() {
|
||||
return VxUnionId == null ? "" : VxUnionId.trim();
|
||||
return vxUnionId == null ? "" : vxUnionId.trim();
|
||||
}
|
||||
|
||||
public void setVxUnionId(String VxUnionId) {
|
||||
this.VxUnionId = VxUnionId;
|
||||
public void setVxUnionId(String vxUnionId) {
|
||||
this.vxUnionId = vxUnionId;
|
||||
}
|
||||
|
||||
public String getVxOpenId() {
|
||||
return VxOpenId == null ? "" : VxOpenId.trim();
|
||||
return vxOpenId == null ? "" : vxOpenId.trim();
|
||||
}
|
||||
|
||||
public void setVxOpenId(String VxOpenId) {
|
||||
this.VxOpenId = VxOpenId;
|
||||
public void setVxOpenId(String vxOpenId) {
|
||||
this.vxOpenId = vxOpenId;
|
||||
}
|
||||
|
||||
|
||||
|
@ -35,6 +35,15 @@ public class CardUserServiceImpl extends AbstractService implements ICardUserSer
|
||||
@Autowired
|
||||
private ICardUserDao cardUserDao;
|
||||
|
||||
|
||||
/* public SuccessResult loginCardUser(String userName,String userPassword)throws Exception{
|
||||
this.getCardUserById()
|
||||
|
||||
|
||||
|
||||
}*/
|
||||
|
||||
|
||||
/**
|
||||
* 根据微信open_id获取用户详情
|
||||
* @param vxOpenId
|
||||
@ -94,6 +103,7 @@ public class CardUserServiceImpl extends AbstractService implements ICardUserSer
|
||||
Map<String, Object> params = HashMapUtil.beanToMap(cardUserVO);
|
||||
params.put("cardUserId", cardUserId);
|
||||
params.put("gmtCreate", DateUtil.getTime());
|
||||
params.put("isDelete", "0");
|
||||
/* if (token != null) {
|
||||
setSaveInfo(token, params);
|
||||
} else {
|
||||
|
@ -55,6 +55,8 @@ public class WxApiUtil {
|
||||
param.put("secret", secret);
|
||||
param.put("js_code", code);
|
||||
param.put("grant_type", grantType);
|
||||
|
||||
//String url = VX_SMALL_ROUTINE_SESSION_KEY +"?appid="+appId+"&secret="+secret+"&js_code="+code+"&grant_type="+grantType;
|
||||
String str = WxUtil.doGet(VX_SMALL_ROUTINE_SESSION_KEY, param);
|
||||
JSONObject json = JSONObject.parseObject(str);
|
||||
return JSON.toJavaObject(json, WeiXinAuthResult.class);
|
||||
|
@ -5,16 +5,37 @@
|
||||
<resultMap id="cardUserDTO" type="cn.com.tenlion.pojo.dtos.carduser.CardUserDTO">
|
||||
<id column="card_user_id" property="cardUserId"/>
|
||||
<result column="user_name" property="userName"/>
|
||||
<result column="user_password" property="userPassword"/>
|
||||
<result column="user_phone" property="userPhone"/>
|
||||
<result column="vx_union_id" property="VxUnionId"/>
|
||||
<result column="vx_open_id" property="VxOpenId"/>
|
||||
<result column="vx_union_id" property="vxUnionId"/>
|
||||
<result column="vx_open_id" property="vxOpenId"/>
|
||||
</resultMap>
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- 根据用户名获取用户表详情 -->
|
||||
<select id="getCardUserByUserName" parameterType="map" resultMap="cardUserDTO">
|
||||
SELECT
|
||||
t1.user_name,
|
||||
t1.user_password,
|
||||
t1.user_phone,
|
||||
t1.vx_union_id,
|
||||
t1.vx_open_id,
|
||||
t1.card_user_id
|
||||
FROM
|
||||
card_user t1
|
||||
WHERE
|
||||
t1.is_delete = 0 AND t1.user_name = #{userName}
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
<!-- 根据微信openId获取用户表详情 -->
|
||||
<select id="getCardUserByVxOpenId" parameterType="map" resultMap="cardUserDTO">
|
||||
SELECT
|
||||
t1.user_name,
|
||||
t1.user_password,
|
||||
t1.user_phone,
|
||||
t1.vx_union_id,
|
||||
t1.vx_open_id,
|
||||
@ -35,6 +56,7 @@
|
||||
INSERT INTO card_user(
|
||||
card_user_id,
|
||||
user_name,
|
||||
user_password,
|
||||
user_phone,
|
||||
vx_union_id,
|
||||
vx_open_id,
|
||||
@ -46,9 +68,10 @@
|
||||
) VALUES(
|
||||
#{cardUserId},
|
||||
#{userName},
|
||||
#{userPassword},
|
||||
#{userPhone},
|
||||
#{VxUnionId},
|
||||
#{VxOpenId},
|
||||
#{vxUnionId},
|
||||
#{vxOpenId},
|
||||
#{creator},
|
||||
#{gmtCreate},
|
||||
#{modifier},
|
||||
@ -91,14 +114,17 @@
|
||||
<if test="userName != null and userName != ''">
|
||||
user_name = #{userName},
|
||||
</if>
|
||||
<if test="userPassword != null and userPassword != ''">
|
||||
user_password = #{userPassword},
|
||||
</if>
|
||||
<if test="userPhone != null and userPhone != ''">
|
||||
user_phone = #{userPhone},
|
||||
</if>
|
||||
<if test="VxUnionId != null and VxUnionId != ''">
|
||||
vx_union_id = #{VxUnionId},
|
||||
<if test="vxUnionId != null and vxUnionId != ''">
|
||||
vx_union_id = #{vxUnionId},
|
||||
</if>
|
||||
<if test="VxOpenId != null and VxOpenId != ''">
|
||||
vx_open_id = #{VxOpenId},
|
||||
<if test="vxOpenId != null and vxOpenId != ''">
|
||||
vx_open_id = #{vxOpenId},
|
||||
</if>
|
||||
modifier = #{modifier},
|
||||
gmt_modified = #{gmtModified}
|
||||
@ -110,6 +136,7 @@
|
||||
<select id="getCardUser" parameterType="map" resultMap="cardUserDTO">
|
||||
SELECT
|
||||
t1.user_name,
|
||||
t1.user_password,
|
||||
t1.user_phone,
|
||||
t1.vx_union_id,
|
||||
t1.vx_open_id,
|
||||
@ -128,6 +155,7 @@
|
||||
<select id="listCardUser" parameterType="map" resultMap="cardUserDTO">
|
||||
SELECT
|
||||
t1.user_name,
|
||||
t1.user_password,
|
||||
t1.user_phone,
|
||||
t1.vx_union_id,
|
||||
t1.vx_open_id,
|
||||
|
Loading…
Reference in New Issue
Block a user