123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- package com.caimei.controller.wechat;
- import com.alibaba.fastjson.JSONObject;
- import com.caimei.model.ResponseJson;
- import com.caimei.model.vo.WxClubUserVo;
- import com.caimei.service.wechat.LoginService;
- import com.caimei.utils.HttpRequest;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiImplicitParam;
- import io.swagger.annotations.ApiOperation;
- import lombok.RequiredArgsConstructor;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.web.bind.annotation.*;
- import javax.servlet.http.HttpServletRequest;
- /**
- * 微信机构用户登录API
- *
- * @author : Aslee
- * @date : 2021/5/11
- */
- @Api(tags = "微信机构用户登录API")
- @RestController
- @RequiredArgsConstructor
- @RequestMapping("/wx/user/login")
- public class LoginApi {
- private final LoginService loginService;
- @ApiOperation("服务号授权登录")
- @ApiImplicitParam(name = "params", value = "code登录凭证;appId;", required = true)
- @PostMapping("/authorization")
- public ResponseJson<WxClubUserVo> authorizationLogin(@RequestBody String params) {
- JSONObject parseObject = JSONObject.parseObject(params);
- String code = parseObject.getString("code");
- String appId = parseObject.getString("appId");
- return loginService.loginByAuthorization(code, appId);
- }
- @ApiOperation("登录验证码发送")
- @ApiImplicitParam(name = "params", value = "mobile:手机号;appId:公众号appId;type:1订阅号验证码,2服务号验证码", required = true)
- @PostMapping("/verify/code/send")
- public ResponseJson sendVerifyCode(@RequestBody String params) {
- JSONObject parseObject = JSONObject.parseObject(params);
- String mobile = parseObject.getString("mobile");
- Integer authUserId = parseObject.getInteger("authUserId");
- Integer type = parseObject.getInteger("type");
- return loginService.sendVerifyCode(mobile, authUserId, type);
- }
- @ApiOperation("服务号验证码登录")
- @ApiImplicitParam(name = "params", value = "mobile:手机号;verifyCode:验证码;invitationCode:邀请码;accessToken;openId;appId", required = true)
- @PostMapping("/service/invitation/code")
- public ResponseJson<WxClubUserVo> invitationCode(@RequestBody String params) throws Exception {
- JSONObject parseObject = JSONObject.parseObject(params);
- String mobile = parseObject.getString("mobile");
- String verifyCode = parseObject.getString("verifyCode");
- String accessToken = parseObject.getString("accessToken");
- String openId = parseObject.getString("openId");
- String appId = parseObject.getString("appId");
- return loginService.loginByVerifyCode(mobile, verifyCode, accessToken, openId, appId);
- }
- @ApiOperation("订阅号验证码登录")
- @ApiImplicitParam(name = "params", value = "mobile:手机号;verifyCode:验证码;openId;appId", required = true)
- @PostMapping("/subscribe/verify/code")
- public ResponseJson<WxClubUserVo> loginByVerifyCode(@RequestBody String params){
- JSONObject parseObject = JSONObject.parseObject(params);
- String mobile = parseObject.getString("mobile");
- String verifyCode = parseObject.getString("verifyCode");
- Integer authUserId = parseObject.getInteger("authUserId");
- return loginService.loginByVerifyCode(mobile, verifyCode, authUserId);
- }
- @ApiOperation("密码登录")
- @ApiImplicitParam(name = "params", value = "mobile:手机号;password:密码;authUserId:供应商用户id", required = true)
- @PostMapping("/password")
- public ResponseJson<WxClubUserVo> passwordLogin(@RequestBody String params) {
- JSONObject parseObject = JSONObject.parseObject(params);
- String mobile = parseObject.getString("mobile");
- String password = parseObject.getString("password");
- Integer authUserId = parseObject.getInteger("authUserId");
- if (StringUtils.isEmpty(mobile) || StringUtils.isEmpty(password)) {
- return ResponseJson.error("参数异常", null);
- }
- if (null == authUserId) {
- return ResponseJson.error("供应商用户id不能为空", null);
- }
- return loginService.passwordLogin(mobile, password, authUserId);
- }
- @ApiOperation("根据token获取用户信息")
- @GetMapping("/token/check")
- public ResponseJson<WxClubUserVo> getUserInfoByToken(HttpServletRequest httpRequest) {
- return loginService.getUserInfoByToken(httpRequest);
- }
- }
|