diff --git a/src/main/java/cn/com/tenlion/BusinessCardApplication.java b/src/main/java/cn/com/tenlion/BusinessCardApplication.java index 2aca092..8506519 100644 --- a/src/main/java/cn/com/tenlion/BusinessCardApplication.java +++ b/src/main/java/cn/com/tenlion/BusinessCardApplication.java @@ -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) { diff --git a/src/main/java/cn/com/tenlion/accesstokenmanager/AccessTokenManager.java b/src/main/java/cn/com/tenlion/accesstokenmanager/AccessTokenManager.java index 1e5b96a..303fe6f 100644 --- a/src/main/java/cn/com/tenlion/accesstokenmanager/AccessTokenManager.java +++ b/src/main/java/cn/com/tenlion/accesstokenmanager/AccessTokenManager.java @@ -37,6 +37,10 @@ public class AccessTokenManager { cardUserVOMap.remove(key); } + public Map getKeyList(){ + return cardUserVOMap; + } + public void updateLastActivityTime(String key){ CardUserDTO dto = this.getKey(key); diff --git a/src/main/java/cn/com/tenlion/config/CheckAuthInterceptor.java b/src/main/java/cn/com/tenlion/config/CheckAuthInterceptor.java index efb58ea..f4fbdd3 100644 --- a/src/main/java/cn/com/tenlion/config/CheckAuthInterceptor.java +++ b/src/main/java/cn/com/tenlion/config/CheckAuthInterceptor.java @@ -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; diff --git a/src/main/java/cn/com/tenlion/controller/apis/carduser/CardUserController.java b/src/main/java/cn/com/tenlion/controller/apis/carduser/CardUserController.java index 3958c3c..0abc55f 100644 --- a/src/main/java/cn/com/tenlion/controller/apis/carduser/CardUserController.java +++ b/src/main/java/cn/com/tenlion/controller/apis/carduser/CardUserController.java @@ -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") diff --git a/src/main/java/cn/com/tenlion/controller/app/apis/carduser/CardUserAppController.java b/src/main/java/cn/com/tenlion/controller/app/apis/carduser/CardUserAppController.java index ac92ce1..fb38865 100644 --- a/src/main/java/cn/com/tenlion/controller/app/apis/carduser/CardUserAppController.java +++ b/src/main/java/cn/com/tenlion/controller/app/apis/carduser/CardUserAppController.java @@ -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); + } diff --git a/src/main/java/cn/com/tenlion/pojo/dtos/carduser/CardUserDTO.java b/src/main/java/cn/com/tenlion/pojo/dtos/carduser/CardUserDTO.java index 92948aa..43956e6 100644 --- a/src/main/java/cn/com/tenlion/pojo/dtos/carduser/CardUserDTO.java +++ b/src/main/java/cn/com/tenlion/pojo/dtos/carduser/CardUserDTO.java @@ -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() { diff --git a/src/main/java/cn/com/tenlion/pojo/vos/carduser/CardUserVO.java b/src/main/java/cn/com/tenlion/pojo/vos/carduser/CardUserVO.java index 1755107..2bc42ea 100644 --- a/src/main/java/cn/com/tenlion/pojo/vos/carduser/CardUserVO.java +++ b/src/main/java/cn/com/tenlion/pojo/vos/carduser/CardUserVO.java @@ -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; } diff --git a/src/main/java/cn/com/tenlion/service/carduser/impl/CardUserServiceImpl.java b/src/main/java/cn/com/tenlion/service/carduser/impl/CardUserServiceImpl.java index cb2c366..a756ec2 100644 --- a/src/main/java/cn/com/tenlion/service/carduser/impl/CardUserServiceImpl.java +++ b/src/main/java/cn/com/tenlion/service/carduser/impl/CardUserServiceImpl.java @@ -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 params = HashMapUtil.beanToMap(cardUserVO); params.put("cardUserId", cardUserId); params.put("gmtCreate", DateUtil.getTime()); + params.put("isDelete", "0"); /* if (token != null) { setSaveInfo(token, params); } else { diff --git a/src/main/java/cn/com/tenlion/util/cons/ISystemConstant.java b/src/main/java/cn/com/tenlion/util/cons/ISystemConstant.java index edd93c0..b72f797 100644 --- a/src/main/java/cn/com/tenlion/util/cons/ISystemConstant.java +++ b/src/main/java/cn/com/tenlion/util/cons/ISystemConstant.java @@ -199,7 +199,7 @@ public interface ISystemConstant { /** * 小程序 appId* */ - String VX_APP_ID = "wxa49a60262e53d305 "; + String VX_APP_ID = "wxa49a60262e53d305"; /** * 小程序 appSecret */ diff --git a/src/main/java/cn/com/tenlion/util/vx/WxApiUtil.java b/src/main/java/cn/com/tenlion/util/vx/WxApiUtil.java index d690b5c..6d50217 100644 --- a/src/main/java/cn/com/tenlion/util/vx/WxApiUtil.java +++ b/src/main/java/cn/com/tenlion/util/vx/WxApiUtil.java @@ -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); diff --git a/src/main/resources/mybatis/mapper/carduser/carduser-mapper.xml b/src/main/resources/mybatis/mapper/carduser/carduser-mapper.xml index fedb65a..2e4ad6d 100644 --- a/src/main/resources/mybatis/mapper/carduser/carduser-mapper.xml +++ b/src/main/resources/mybatis/mapper/carduser/carduser-mapper.xml @@ -5,16 +5,37 @@ + - - + + + + + + + + + SELECT t1.user_name, + t1.user_password, t1.user_phone, t1.vx_union_id, t1.vx_open_id, @@ -128,6 +155,7 @@