手机号注册-oauth返回格式
This commit is contained in:
@@ -20,6 +20,7 @@ import com.accompany.sms.service.SmsService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
@@ -64,6 +65,7 @@ public class AccountH5LoginService {
|
||||
return accountH5LoginRecord;
|
||||
}
|
||||
|
||||
@Async
|
||||
public Integer insertRecord(AccountH5LoginRecord accountH5LoginRecord){
|
||||
return accountH5LoginRecordMapper.insert(accountH5LoginRecord);
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ import cn.hutool.core.util.ObjectUtil;
|
||||
import com.accompany.common.constant.AppEnum;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.device.DeviceInfo;
|
||||
import com.accompany.common.exception.BusinessException;
|
||||
import com.accompany.common.netease.neteaseacc.result.TokenRet;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.common.result.BusiResult;
|
||||
@@ -393,8 +394,7 @@ public class AccountManageService {
|
||||
return account;
|
||||
}
|
||||
|
||||
public BusiResult<VisitorVo> genVisitorAccount() throws Exception {
|
||||
BusiResult busiResult = new BusiResult(BusiStatus.SUCCESS);
|
||||
public VisitorVo genVisitorAccount() throws Exception {
|
||||
String password = "visitoradmin999";
|
||||
Date date = new Date();
|
||||
Account account = new Account();
|
||||
@@ -408,19 +408,16 @@ public class AccountManageService {
|
||||
accountService.writeAche(account);
|
||||
String uidStr = String.valueOf(account.getUid());
|
||||
TokenRet tokenRet = netEaseService.createNetEaseAcc(uidStr, account.getNeteaseToken(), "");
|
||||
if (tokenRet.getCode() != 200) {
|
||||
busiResult.setCode(OAuthStatus.ACCESS_DENIED.value());
|
||||
busiResult.setMessage("获取游客账号异常" + tokenRet.getCode());
|
||||
if (tokenRet.getCode() != BusiStatus.SUCCESS.value()) {
|
||||
log.error("获取游客账号异常code=" + tokenRet.getCode());
|
||||
throw new Exception("获取游客账号异常code=注册异常,异常原因code=" + tokenRet.getCode());
|
||||
throw new BusinessException("获取游客账号异常code=注册异常,异常原因code=" + tokenRet.getCode());
|
||||
}
|
||||
VisitorVo visitorVo = new VisitorVo();
|
||||
visitorVo.setUid(account.getUid());
|
||||
visitorVo.setNetEaseToken(account.getNeteaseToken());
|
||||
visitorVo.setGender(new Byte("1"));
|
||||
visitorVo.setNick("游客");
|
||||
busiResult.setData(visitorVo);
|
||||
return busiResult;
|
||||
return visitorVo;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -507,8 +504,7 @@ public class AccountManageService {
|
||||
}
|
||||
}
|
||||
|
||||
public BusiResult registerForYiDun(YiDunDto yiDunDto, int type) {
|
||||
BusiResult busiResult = new BusiResult(BusiStatus.SUCCESS);
|
||||
public BusiResult<Void> registerForYiDun(YiDunDto yiDunDto, int type) {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("version", "200");
|
||||
params.put("secretId", yiDunDto.getSecretId());
|
||||
@@ -544,9 +540,9 @@ public class AccountManageService {
|
||||
if (action == 20) {
|
||||
log.error("账号注册异常 ip:{}, phone:{}", yiDunDto.getIp(), yiDunDto.getPhone());
|
||||
if (hitType == 6) {//表示模拟器注册
|
||||
return new BusiResult(BusiStatus.REGISTER_ERROR_PHONE);
|
||||
return new BusiResult<>(BusiStatus.REGISTER_ERROR_PHONE);
|
||||
}
|
||||
return new BusiResult(BusiStatus.REGISTER_ERROR);
|
||||
return new BusiResult<>(BusiStatus.REGISTER_ERROR);
|
||||
} else if (action == 10) {
|
||||
log.warn("账号注册有嫌疑 ip:{}, phone:{}", yiDunDto.getIp(), yiDunDto.getPhone());
|
||||
}
|
||||
@@ -558,12 +554,11 @@ public class AccountManageService {
|
||||
} finally {
|
||||
accountProtectRecordService.saveYiDunRecord(yiDunDto, null, "", (byte) 2, type);
|
||||
}
|
||||
return busiResult;
|
||||
return new BusiResult<>(BusiStatus.SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
public BusiResult loginForYiDun(YiDunDto yiDunDto,Account account, int type) {
|
||||
BusiResult busiResult = new BusiResult(BusiStatus.SUCCESS);
|
||||
public BusiResult<Void> loginForYiDun(YiDunDto yiDunDto,Account account, int type) {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("version", "200");
|
||||
params.put("secretId", yiDunDto.getSecretId());
|
||||
@@ -601,7 +596,7 @@ public class AccountManageService {
|
||||
YiDunResultDto.ResultBean result = yiDunResultDto.getResult();
|
||||
if(result.getAction() == 20) {//致命
|
||||
log.error("yidun login response error:{}",response);
|
||||
return new BusiResult(BusiStatus.LOGIN_ERROR);
|
||||
return new BusiResult<>(BusiStatus.LOGIN_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -610,7 +605,7 @@ public class AccountManageService {
|
||||
} finally {
|
||||
accountProtectRecordService.saveYiDunRecord(yiDunDto, account, md5String, (byte) 1, type);
|
||||
}
|
||||
return busiResult;
|
||||
return new BusiResult<>(BusiStatus.SUCCESS);
|
||||
}
|
||||
|
||||
public boolean checkRegisterLoginForShuMei(ShuMeiDto shuMeiDto, boolean isLogin, Long uid, int type){
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package com.accompany.oauth2.ticket;
|
||||
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.device.DeviceInfo;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.common.utils.DateTimeUtil;
|
||||
|
@@ -0,0 +1,60 @@
|
||||
package com.accompany.oauth2.vo;
|
||||
|
||||
import com.accompany.oauth2.ticket.Ticket;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TicketRes{
|
||||
private String issue_type;
|
||||
private List<TicketVo> tickets;
|
||||
private String accid;
|
||||
private Long uid;
|
||||
private String netEaseToken;
|
||||
|
||||
public String getIssue_type() {
|
||||
return issue_type;
|
||||
}
|
||||
|
||||
public String getAccid() {
|
||||
return accid;
|
||||
}
|
||||
|
||||
public Long getUid() {
|
||||
return uid;
|
||||
}
|
||||
|
||||
public String getNetEaseToken() {
|
||||
return netEaseToken;
|
||||
}
|
||||
|
||||
public void setIssue_type(String issue_type) {
|
||||
this.issue_type = issue_type;
|
||||
}
|
||||
|
||||
public List<TicketVo> getTickets() {
|
||||
return tickets;
|
||||
}
|
||||
|
||||
public void setAccid(String accid) {
|
||||
this.accid = accid;
|
||||
}
|
||||
|
||||
public void setUid(Long uid) {
|
||||
this.uid = uid;
|
||||
}
|
||||
|
||||
public void setNetEaseToken(String netEaseToken) {
|
||||
this.netEaseToken = netEaseToken;
|
||||
}
|
||||
|
||||
public void setTickets(List<Ticket> tickets){
|
||||
if(tickets == null){
|
||||
return;
|
||||
}
|
||||
this.tickets = new ArrayList<TicketVo>();
|
||||
for(Ticket ticket : tickets){
|
||||
this.tickets.add(new TicketVo(ticket));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,59 @@
|
||||
package com.accompany.oauth2.vo;
|
||||
|
||||
import com.accompany.oauth2.ticket.Ticket;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class TicketVo{
|
||||
private String ticket;
|
||||
private int expires_in;
|
||||
private String ticket_type;
|
||||
private String scope;
|
||||
|
||||
public TicketVo(Ticket ticket){
|
||||
setTicket(ticket.getValue());
|
||||
setExpires_in(ticket.getExpiresIn());
|
||||
setTicket_type(ticket.getTicketType());
|
||||
setScope(setToString(ticket.getScope()));
|
||||
}
|
||||
|
||||
public String getTicket() {
|
||||
return ticket;
|
||||
}
|
||||
|
||||
public void setTicket(String ticket) {
|
||||
this.ticket = ticket;
|
||||
}
|
||||
|
||||
public int getExpires_in() {
|
||||
return expires_in;
|
||||
}
|
||||
|
||||
public void setExpires_in(int expires_in) {
|
||||
this.expires_in = expires_in;
|
||||
}
|
||||
|
||||
public String getTicket_type() {
|
||||
return ticket_type;
|
||||
}
|
||||
|
||||
public void setTicket_type(String ticket_type) {
|
||||
this.ticket_type = ticket_type;
|
||||
}
|
||||
|
||||
public String getScope() {
|
||||
return scope;
|
||||
}
|
||||
|
||||
public void setScope(String scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
private String setToString(Set<String> stringSet){
|
||||
if(stringSet == null){
|
||||
return null;
|
||||
}
|
||||
return StringUtils.join(stringSet," ");
|
||||
}
|
||||
}
|
@@ -4,6 +4,7 @@ import com.accompany.common.annotation.Authorization;
|
||||
import com.accompany.common.constant.AppEnum;
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.device.DeviceInfo;
|
||||
import com.accompany.common.exception.BusinessException;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.common.result.BusiResult;
|
||||
import com.accompany.common.status.BusiStatus;
|
||||
@@ -15,7 +16,6 @@ import com.accompany.core.dto.ShuMeiDto;
|
||||
import com.accompany.core.dto.YiDunDto;
|
||||
import com.accompany.core.exception.ServiceException;
|
||||
import com.accompany.core.model.Account;
|
||||
import com.accompany.core.mybatismapper.UsersMapper;
|
||||
import com.accompany.core.service.SysConfService;
|
||||
import com.accompany.core.service.account.AccountService;
|
||||
import com.accompany.core.service.common.JedisLockService;
|
||||
@@ -23,6 +23,7 @@ import com.accompany.core.service.common.JedisService;
|
||||
import com.accompany.core.service.user.PhoneBlackService;
|
||||
import com.accompany.core.util.JwtUtils;
|
||||
import com.accompany.core.util.KeyStore;
|
||||
import com.accompany.core.vo.VisitorVo;
|
||||
import com.accompany.oauth2.common.BaseController;
|
||||
import com.accompany.oauth2.config.OAuthConfig;
|
||||
import com.accompany.oauth2.constant.LoginTypeEnum;
|
||||
@@ -56,8 +57,6 @@ import org.springframework.web.bind.annotation.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.accompany.common.constant.Constant.LOWEST_VERSION_FOR_USE;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/acc")
|
||||
public class AccountController extends BaseController {
|
||||
@@ -88,9 +87,8 @@ public class AccountController extends BaseController {
|
||||
@Autowired
|
||||
private MyUserDetailsService myUserDetailsService;
|
||||
@Autowired
|
||||
private UsersMapper usersMapper;
|
||||
@Autowired
|
||||
private PhoneBlackService phoneBlackService;
|
||||
|
||||
/**
|
||||
* 通过手机号码注册
|
||||
*
|
||||
@@ -102,13 +100,13 @@ public class AccountController extends BaseController {
|
||||
@Deprecated
|
||||
@RequestMapping(value = "signup", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public BusiResult signUp(String phone, @RequestParam String password,
|
||||
public BusiResult<Void> signUp(String phone, @RequestParam String password,
|
||||
String smsCode, DeviceInfo deviceInfo, HttpServletRequest request, String token,
|
||||
String shuMeiDeviceId,Double gpsLongitude,Double gpsLatitude) {
|
||||
|
||||
String closeSwitch = jedisService.get(RedisKey.close_signup_switch.getKey());
|
||||
if(StringUtils.isNotBlank(closeSwitch)){
|
||||
return new BusiResult(OAuthStatus.CLOSE_SIGNUP_ERROR.value(), OAuthStatus.CLOSE_SIGNUP_ERROR.getReasonPhrase(), null);
|
||||
return new BusiResult<>(OAuthStatus.CLOSE_SIGNUP_ERROR.value(), OAuthStatus.CLOSE_SIGNUP_ERROR.getReasonPhrase(), null);
|
||||
}
|
||||
|
||||
// 加入密码DES解密
|
||||
@@ -120,7 +118,7 @@ public class AccountController extends BaseController {
|
||||
|
||||
// 弱密码检查
|
||||
if(!password.matches(PASSWORD_REGIX_V2)){
|
||||
return new BusiResult(OAuthStatus.WEAK_PASSWORD.value(), OAuthStatus.WEAK_PASSWORD.getReasonPhrase(), null);
|
||||
return new BusiResult<>(OAuthStatus.WEAK_PASSWORD.value(), OAuthStatus.WEAK_PASSWORD.getReasonPhrase(), null);
|
||||
}
|
||||
|
||||
////检验验证码
|
||||
@@ -131,9 +129,9 @@ public class AccountController extends BaseController {
|
||||
//校验手机号是否已经被注册
|
||||
boolean exist = accountService.checkPhoneExists(phone);
|
||||
if (exist) {
|
||||
return new BusiResult(OAuthStatus.USER_HAS_SIGNED_UP.value(), "手机号码已经被注册,请直接登录!", null);
|
||||
return new BusiResult<>(OAuthStatus.USER_HAS_SIGNED_UP.value(), "手機號碼已經被註冊,請直接登錄!", null);
|
||||
}
|
||||
return new BusiResult(BusiStatus.SUCCESS);
|
||||
return new BusiResult<>(BusiStatus.SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
@@ -147,7 +145,7 @@ public class AccountController extends BaseController {
|
||||
*/
|
||||
@RequestMapping(value = "/register", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public BusiResult register(String phone, @RequestParam String password, String smsCode,
|
||||
public BusiResult<Account> register(String phone, @RequestParam String password, String smsCode,
|
||||
String verifyCode, DeviceInfo deviceInfo, HttpServletRequest request, String token,
|
||||
String shuMeiDeviceId,Double gpsLongitude,Double gpsLatitude) {
|
||||
phone = decryptSensitiveInfo(request, phone);
|
||||
@@ -163,7 +161,7 @@ public class AccountController extends BaseController {
|
||||
|
||||
// 弱密码检查
|
||||
if(!password.matches(PASSWORD_REGIX_V2)){
|
||||
return new BusiResult(OAuthStatus.WEAK_PASSWORD.value(), OAuthStatus.WEAK_PASSWORD.getReasonPhrase(), null);
|
||||
return new BusiResult<>(OAuthStatus.WEAK_PASSWORD.value(), OAuthStatus.WEAK_PASSWORD.getReasonPhrase(), null);
|
||||
}
|
||||
|
||||
boolean captchaSwitch = sysConfService.getCaptchaSwitch();
|
||||
@@ -172,7 +170,7 @@ public class AccountController extends BaseController {
|
||||
logger.info("register failed,phone:{},smsCode:{},verifyCode:{},registerCode:{},deviceInfo:{}",
|
||||
phone,smsCode,verifyCode,registerCode,deviceInfo);
|
||||
if(StringUtils.isBlank(registerCode) || !registerCode.equals(verifyCode)){
|
||||
return new BusiResult(OAuthStatus.VERIFY_CODE_ERROR.value(), OAuthStatus.VERIFY_CODE_ERROR.getReasonPhrase(), null);
|
||||
return new BusiResult<>(OAuthStatus.VERIFY_CODE_ERROR.value(), OAuthStatus.VERIFY_CODE_ERROR.getReasonPhrase(), null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,19 +184,19 @@ public class AccountController extends BaseController {
|
||||
final String lockVal = jedisLockService.lock(locKey, 10 * 1000);
|
||||
try {
|
||||
if (BlankUtil.isBlank(lockVal)){
|
||||
return new BusiResult(BusiStatus.REQUEST_FAST);
|
||||
return new BusiResult<>(BusiStatus.REQUEST_FAST);
|
||||
}
|
||||
//校验手机号是否已经被注册
|
||||
boolean exist = accountService.checkPhoneExists(phone);
|
||||
if (exist) {
|
||||
return new BusiResult(OAuthStatus.USER_HAS_SIGNED_UP.value(), "手机号码已经被注册,请直接登录!", null);
|
||||
return new BusiResult<>(OAuthStatus.USER_HAS_SIGNED_UP.value(), "手机号码已经被注册,请直接登录!", null);
|
||||
}
|
||||
if (oAuthConfig.isRegisterSwitch() && token != null) {
|
||||
YiDunDto yiDunDto = accountManageService.buildYiDunDto(oAuthConfig, ipAddress, token, phone,null, deviceInfo);
|
||||
BusiResult busiResult = accountManageService.registerForYiDun(yiDunDto, 3);
|
||||
BusiResult<Void> busiResult = accountManageService.registerForYiDun(yiDunDto, 3);
|
||||
logger.info("yidun register opened:{},code:{}",oAuthConfig.isRegisterOpened(),busiResult.getCode());
|
||||
if (oAuthConfig.isRegisterOpened() && busiResult.getCode() != 200) {
|
||||
return busiResult;
|
||||
return new BusiResult<>(busiResult.getCode(), busiResult.getMessage());
|
||||
}
|
||||
}
|
||||
if (oAuthConfig.isShuMeiRegisterSwitch() && StringUtils.isNotBlank(shuMeiDeviceId)){
|
||||
@@ -207,14 +205,14 @@ public class AccountController extends BaseController {
|
||||
|
||||
logger.info("shumei register opened:{},checkResult:{}",oAuthConfig.isRegisterOpened(),checkResult);
|
||||
if(oAuthConfig.isRegisterOpened() && !checkResult){
|
||||
return new BusiResult(BusiStatus.SHUMEI_REGISTER_ERROR);
|
||||
return new BusiResult<>(BusiStatus.SHUMEI_REGISTER_ERROR);
|
||||
}
|
||||
}
|
||||
return new BusiResult(accountManageService.
|
||||
return new BusiResult<>(accountManageService.
|
||||
saveSignUpByPhone(phone, password, deviceInfo, ipAddress));
|
||||
} catch (Exception e) {
|
||||
logger.error("注册失败,当前注册手机号码phone=" + phone + "失败原因:" + e.getMessage());
|
||||
return new BusiResult(BusiStatus.SERVER_BUSY);
|
||||
return new BusiResult<>(BusiStatus.SERVER_BUSY);
|
||||
} finally {
|
||||
jedisLockService.unlock(locKey, lockVal);
|
||||
}
|
||||
@@ -222,15 +220,13 @@ public class AccountController extends BaseController {
|
||||
|
||||
@RequestMapping(value = "getvisitor", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public BusiResult getVisitorAccount() {
|
||||
BusiResult busiResult = new BusiResult(BusiStatus.SUCCESS);
|
||||
public BusiResult<VisitorVo> getVisitorAccount() {
|
||||
try {
|
||||
busiResult = accountManageService.genVisitorAccount();
|
||||
VisitorVo vo = accountManageService.genVisitorAccount();
|
||||
return new BusiResult<>(vo);
|
||||
} catch (Exception e) {
|
||||
busiResult.setCode(BusiStatus.BUSIERROR.value());
|
||||
logger.error("获取游客账号失败");
|
||||
throw new BusinessException(e);
|
||||
}
|
||||
return busiResult;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "logout", method = RequestMethod.POST)
|
||||
@@ -245,23 +241,22 @@ public class AccountController extends BaseController {
|
||||
|
||||
@RequestMapping(value = "h5/logout", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public BusiResult h5Logout(Long uid, String token) {
|
||||
BusiResult busiResult = new BusiResult(BusiStatus.SUCCESS);
|
||||
public BusiResult<Void> h5Logout(Long uid, String token) {
|
||||
try {
|
||||
Claims claims = jwtUtils.parseJWT(token);
|
||||
String uidStr = claims.get("uid") + "";
|
||||
jedisService.hdel(RedisKey.h5loginjwtoken.getKey(), uidStr);
|
||||
} catch (ExpiredJwtException e) {
|
||||
logger.error("jwttoken is expired,uid={},token={}", uid, token, e);
|
||||
return new BusiResult(406, "expired", "");
|
||||
return new BusiResult<>(406, "expired", null);
|
||||
} catch (SignatureException e) {
|
||||
logger.error("signature is illegal,uid={},token={}", uid, token, e);
|
||||
return new BusiResult(407, "illegal", "");
|
||||
return new BusiResult<>(407, "illegal", null);
|
||||
} catch (Exception e) {
|
||||
logger.error("log out error,uid={},token={}", uid, token, e);
|
||||
return new BusiResult(BusiStatus.BUSIERROR);
|
||||
return new BusiResult<>(BusiStatus.BUSIERROR);
|
||||
}
|
||||
return busiResult;
|
||||
return new BusiResult<>(BusiStatus.SUCCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -346,13 +341,6 @@ public class AccountController extends BaseController {
|
||||
return new ServiceRes(status);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param phone
|
||||
* @param pwd
|
||||
* @param newPwd
|
||||
* @return
|
||||
*/
|
||||
@Authorization
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "pwd/modify", method = RequestMethod.POST)
|
||||
@@ -439,19 +427,18 @@ public class AccountController extends BaseController {
|
||||
*/
|
||||
@ResponseBody
|
||||
@RequestMapping("third/isExistsQqAccount")
|
||||
public BusiResult isExistsQqAccount(String qqOpenid, DeviceInfo deviceInfo, HttpServletRequest request) throws Exception {
|
||||
BusiResult result = null;
|
||||
public BusiResult<Void> isExistsQqAccount(String qqOpenid, DeviceInfo deviceInfo, HttpServletRequest request) throws Exception {
|
||||
try {
|
||||
Account account = accountService.getAccountByOpenid(qqOpenid, 2);
|
||||
if (account != null) {
|
||||
result = new BusiResult(BusiStatus.SUCCESS);
|
||||
return new BusiResult<>(BusiStatus.SUCCESS);
|
||||
} else {
|
||||
result = new BusiResult(BusiStatus.ACCOUNT_NOT_EXISTS, "不存在对应账号", null);
|
||||
return new BusiResult<>(BusiStatus.ACCOUNT_NOT_EXISTS, "不存在对应账号", null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed . Cause by: {}", e.getMessage());
|
||||
return new BusiResult<>(BusiStatus.SERVERERROR);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private ResponseEntity<OAuth2AccessToken> getResponse(OAuth2AccessToken accessToken) {
|
||||
@@ -496,20 +483,18 @@ public class AccountController extends BaseController {
|
||||
*/
|
||||
@RequestMapping(value = "/getUidByUsername", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public BusiResult getUidByNickAndPassword(Long username, String password) {
|
||||
public BusiResult<Long> getUidByNickAndPassword(Long username, String password) {
|
||||
if (username == null || StringUtils.isEmpty(password)) {
|
||||
return new BusiResult(BusiStatus.ALERT_PARAMETER_ILLEGAL);
|
||||
return new BusiResult<>(BusiStatus.ALERT_PARAMETER_ILLEGAL);
|
||||
}
|
||||
Long uid = accountService.getUidByNickAndPassword(username, password);
|
||||
if (uid.equals(0L)) {
|
||||
return new BusiResult(BusiStatus.ERBAN_NO_NOT_EXIST);
|
||||
return new BusiResult<>(BusiStatus.ERBAN_NO_NOT_EXIST);
|
||||
}
|
||||
if (uid.equals(-1L)) {
|
||||
return new BusiResult(BusiStatus.PASSWORD_ERROR);
|
||||
return new BusiResult<>(BusiStatus.PASSWORD_ERROR);
|
||||
}
|
||||
BusiResult busiResult = new BusiResult(BusiStatus.SUCCESS);
|
||||
busiResult.setData(uid);
|
||||
return busiResult;
|
||||
return new BusiResult<>(uid);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -40,69 +40,60 @@ public class H5LoginController extends BaseController {
|
||||
*/
|
||||
@Authorization
|
||||
@RequestMapping(value = "/authorized/login",method = RequestMethod.POST)
|
||||
public BusiResult loginAuthorizedByH5(HttpServletRequest request, @RequestParam String code, @RequestParam Long uid, @RequestBody DeviceInfo deviceInfo){
|
||||
|
||||
BusiResult busiResult = new BusiResult(BusiStatus.SUCCESS);
|
||||
String ip = IPUitls.getRealIpAddress(request);
|
||||
public BusiResult<Void> loginAuthorizedByH5(HttpServletRequest request, @RequestParam String code, @RequestParam Long uid, @RequestBody DeviceInfo deviceInfo){
|
||||
logger.info("h5 authorized login params is: code={},uid={},deviceInfo={}",code,uid, JSONObject.toJSON(deviceInfo));
|
||||
try{
|
||||
String ip = IPUitls.getRealIpAddress(request);
|
||||
this.accountH5LoginService.h5AuthLogin(code,uid,ip,deviceInfo.getOs(),deviceInfo.getAppVersion(),deviceInfo.getDeviceId());
|
||||
return new BusiResult<>(BusiStatus.SUCCESS);
|
||||
}catch (CustomOAuth2Exception e) {
|
||||
return new BusiResult(BusiStatus.ACCOUNT_ERROR);
|
||||
return new BusiResult<>(BusiStatus.ACCOUNT_ERROR);
|
||||
}catch (BusinessException e){
|
||||
return new BusiResult(500,e.getMessage(),null);
|
||||
return new BusiResult<>(BusiStatus.SERVERERROR, e.getMessage(),null);
|
||||
}catch (Exception e){
|
||||
logger.error("h5 authorized login failed,param is: code={},uid={},deviceInfo={}",code,uid, JSONObject.toJSON(deviceInfo),e);
|
||||
return new BusiResult(BusiStatus.BUSIERROR);
|
||||
return new BusiResult<>(BusiStatus.BUSIERROR);
|
||||
}
|
||||
return busiResult;
|
||||
}
|
||||
|
||||
// 获取授权码
|
||||
@RequestMapping(value = "/code/get",method = RequestMethod.GET)
|
||||
public BusiResult getAuthCode(){
|
||||
BusiResult busiResult = new BusiResult(BusiStatus.SUCCESS);
|
||||
public BusiResult<String> getAuthCode(){
|
||||
String code = this.accountH5LoginService.getAuthCode();
|
||||
busiResult.setData(code);
|
||||
return busiResult;
|
||||
return new BusiResult<>(BusiStatus.SUCCESS, code);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/code/check", method = RequestMethod.GET)
|
||||
public BusiResult checkCodeIsUsed(String code){
|
||||
BusiResult busiResult = new BusiResult(BusiStatus.SUCCESS);
|
||||
public BusiResult<String> checkCodeIsUsed(String code){
|
||||
if(StringUtils.isEmpty(code)){
|
||||
return new BusiResult(BusiStatus.PARAMERROR);
|
||||
return new BusiResult<>(BusiStatus.PARAMERROR);
|
||||
}
|
||||
try{
|
||||
String token = this.accountH5LoginService.checkCodeIsUsed(code);
|
||||
|
||||
if(StringUtils.isEmpty(token)){
|
||||
return new BusiResult(1001,"no used",null);
|
||||
return new BusiResult<>(1001,"no used",null);
|
||||
}
|
||||
busiResult.setData(token);
|
||||
return busiResult;
|
||||
return new BusiResult<>(BusiStatus.SUCCESS, token);
|
||||
}catch (BusinessException e){
|
||||
return new BusiResult(500,e.getMessage(),null);
|
||||
return new BusiResult<>(500,e.getMessage(),null);
|
||||
}catch (Exception e){
|
||||
return new BusiResult(BusiStatus.BUSIERROR);
|
||||
return new BusiResult<>(BusiStatus.BUSIERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/login", method = RequestMethod.POST)
|
||||
public BusiResult loginByToken(String token){
|
||||
BusiResult busiResult = new BusiResult(BusiStatus.SUCCESS);
|
||||
public BusiResult<Map<String, String>> loginByToken(String token){
|
||||
try{
|
||||
Map<String,String> map = this.accountH5LoginService.h5Login(token);
|
||||
logger.info("h5 login ...... token={},result={}",token,JSONObject.toJSON(map));
|
||||
busiResult.setData(map);
|
||||
return busiResult;
|
||||
return new BusiResult<>(BusiStatus.SUCCESS, map);
|
||||
}catch (ApiException e){
|
||||
return new BusiResult(e.getResponseCode(),e.getMessage(),null);
|
||||
return new BusiResult<>(e.getResponseCode(),e.getMessage(),null);
|
||||
}catch (CustomOAuth2Exception e){
|
||||
return new BusiResult(BusiStatus.ACCOUNT_ERROR);
|
||||
return new BusiResult<>(BusiStatus.ACCOUNT_ERROR);
|
||||
}catch (Exception e){
|
||||
logger.error("h5 login failed,token={}",token,e);
|
||||
return new BusiResult(BusiStatus.BUSIERROR);
|
||||
return new BusiResult<>(BusiStatus.BUSIERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,19 +104,18 @@ public class H5LoginController extends BaseController {
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/smsLogin", method = RequestMethod.POST)
|
||||
public BusiResult loginBySms(String mobile, String code){
|
||||
public BusiResult<Map<String, String>> loginBySms(String mobile, String code){
|
||||
logger.info("h5 smsLogin, mobile:{}, code:{}", mobile, code);
|
||||
return new BusiResult(accountH5LoginService.smsLogin(mobile, code));
|
||||
return new BusiResult<>(accountH5LoginService.smsLogin(mobile, code));
|
||||
}
|
||||
|
||||
@PostMapping("/register")
|
||||
public BusiResult registerByPhone(String mobile, String code, String inviteCode, Long inviteUid, HttpServletRequest request) {
|
||||
public BusiResult<Void> registerByPhone(String mobile, String code, String inviteCode, Long inviteUid, HttpServletRequest request) {
|
||||
logger.info("h5 registerByPhone, mobile:{}, code:{}, inviteCode: {}", mobile, code, inviteCode);
|
||||
DeviceInfo deviceInfo = getDeviceInfo(request);
|
||||
String ipAddress = IPUitls.getRealIpAddress(request);
|
||||
accountH5LoginService.register(mobile, code, inviteCode, inviteUid, deviceInfo, ipAddress);
|
||||
|
||||
return new BusiResult(BusiStatus.SUCCESS);
|
||||
return new BusiResult<>(BusiStatus.SUCCESS);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package com.accompany.oauth2.controller;
|
||||
|
||||
import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.result.BusiResult;
|
||||
import com.accompany.common.status.BusiStatus;
|
||||
import com.accompany.common.utils.AppVersionUtil;
|
||||
import com.accompany.core.exception.ServiceException;
|
||||
@@ -9,7 +10,7 @@ import com.accompany.core.model.AccountLoginRecord;
|
||||
import com.accompany.core.service.SysConfService;
|
||||
import com.accompany.core.service.account.AccountService;
|
||||
import com.accompany.core.service.account.LoginRecordService;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.accompany.oauth2.vo.TicketRes;
|
||||
import com.accompany.common.device.DeviceInfo;
|
||||
import com.accompany.common.utils.IPUitls;
|
||||
import com.accompany.oauth2.common.BaseController;
|
||||
@@ -18,9 +19,7 @@ import com.accompany.oauth2.exception.UnsupportedIssueTypeException;
|
||||
import com.accompany.oauth2.service.MyUserDetailsService;
|
||||
import com.accompany.oauth2.ticket.Ticket;
|
||||
import com.accompany.oauth2.ticket.TicketServices;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.security.oauth2.common.exceptions.InvalidTokenException;
|
||||
@@ -38,9 +37,9 @@ import java.util.*;
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/oauth")
|
||||
@Slf4j
|
||||
public class TicketController extends BaseController {
|
||||
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
@Autowired
|
||||
private TicketServices ticketServices;
|
||||
@Autowired
|
||||
@@ -56,57 +55,41 @@ public class TicketController extends BaseController {
|
||||
@ResponseBody
|
||||
public Object issueTicket(String issue_type, String access_token, HttpServletRequest request,
|
||||
HttpServletResponse response, DeviceInfo deviceInfo){
|
||||
logger.info("oauth/ticket="+access_token+".........");
|
||||
log.info("oauth/ticket="+access_token+".........");
|
||||
checkAppVersion(deviceInfo);
|
||||
try{
|
||||
String ipAddress = IPUitls.getRealIpAddress(request);
|
||||
Map<String,Object> ret = Maps.newHashMap();
|
||||
TicketRes ticketRes = new TicketRes();
|
||||
switch (issue_type){
|
||||
case Ticket.ONCE_TYPE:{
|
||||
Map<String,Object> ticketsMap = ticketServices.issueTicket(access_token);
|
||||
ticketRes.setIssue_type(Ticket.ONCE_TYPE);
|
||||
ticketRes.setTickets((List<Ticket>)ticketsMap.get("tickets"));
|
||||
ticketRes.setAccid((String)ticketsMap.get("accid"));
|
||||
ticketRes.setNetEaseToken((String)ticketsMap.get("netEaseToken"));
|
||||
ticketRes.setUid((Long)ticketsMap.get("uid"));
|
||||
ret.put("code",200);
|
||||
ret.put("data",ticketRes);
|
||||
saveLoginRecord((Long) ticketsMap.get("uid"), ipAddress, deviceInfo);
|
||||
return ret;
|
||||
}
|
||||
case Ticket.MULTI_TYPE:{
|
||||
Map<String,Object> ticketsMap = ticketServices.issueTicket(access_token);
|
||||
ticketRes.setIssue_type(Ticket.MULTI_TYPE);
|
||||
ticketRes.setTickets((List<Ticket>)ticketsMap.get("tickets"));
|
||||
ticketRes.setAccid((String)ticketsMap.get("accid"));
|
||||
ticketRes.setNetEaseToken((String)ticketsMap.get("netEaseToken"));
|
||||
ticketRes.setUid((Long)ticketsMap.get("uid"));
|
||||
ret.put("code",200);
|
||||
ret.put("data",ticketRes);
|
||||
saveLoginRecord((Long) ticketsMap.get("uid"), ipAddress, deviceInfo);
|
||||
return ret;
|
||||
}
|
||||
default:{
|
||||
throw new UnsupportedIssueTypeException("unsupported ticket issue type");
|
||||
}
|
||||
if (Ticket.ONCE_TYPE.equals(issue_type) || Ticket.MULTI_TYPE.equals(issue_type)){
|
||||
Map<String,Object> ticketsMap = ticketServices.issueTicket(access_token);
|
||||
|
||||
TicketRes ticketRes = new TicketRes();
|
||||
ticketRes.setIssue_type(issue_type);
|
||||
ticketRes.setTickets((List<Ticket>)ticketsMap.get("tickets"));
|
||||
ticketRes.setAccid((String)ticketsMap.get("accid"));
|
||||
ticketRes.setNetEaseToken((String)ticketsMap.get("netEaseToken"));
|
||||
ticketRes.setUid((Long)ticketsMap.get("uid"));
|
||||
|
||||
String ipAddress = IPUitls.getRealIpAddress(request);
|
||||
saveLoginRecord((Long) ticketsMap.get("uid"), ipAddress, deviceInfo);
|
||||
|
||||
return new BusiResult<>(ticketRes);
|
||||
}
|
||||
throw new UnsupportedIssueTypeException("unsupported ticket issue type");
|
||||
}catch (InvalidTokenException e){
|
||||
logger.error("issueTicket InvalidTokenException, issue_type=" + issue_type + ", access_token=" + access_token, e);
|
||||
log.error("issueTicket InvalidTokenException, issue_type=" + issue_type + ", access_token=" + access_token, e);
|
||||
response.setStatus(401);
|
||||
return e;
|
||||
}catch (UnsupportedIssueTypeException e1){
|
||||
logger.error("issueTicket UnsupportedIssueTypeException, issue_type=" + issue_type + ", access_token=" + access_token, e1);
|
||||
log.error("issueTicket UnsupportedIssueTypeException, issue_type=" + issue_type + ", access_token=" + access_token, e1);
|
||||
response.setStatus(400);
|
||||
return e1;
|
||||
}catch (Exception ex){
|
||||
logger.error("issueTicket Exception, issue_type=" + issue_type + ", access_token=" + access_token, ex);
|
||||
log.error("issueTicket Exception, issue_type=" + issue_type + ", access_token=" + access_token, ex);
|
||||
return ex;
|
||||
}
|
||||
}
|
||||
|
||||
@Async
|
||||
private void saveLoginRecord(Long uid, String ipAddress, DeviceInfo deviceInfo) {
|
||||
public void saveLoginRecord(Long uid, String ipAddress, DeviceInfo deviceInfo) {
|
||||
Optional.ofNullable(uid).ifPresent(id -> {
|
||||
int count = loginRecordService.countLoginRecordToday(id);
|
||||
if (count == 0) {
|
||||
@@ -127,111 +110,4 @@ public class TicketController extends BaseController {
|
||||
throw new ServiceException(BusiStatus.VERSIONTOOOLD);
|
||||
}
|
||||
}
|
||||
|
||||
private class TicketRes{
|
||||
private String issue_type;
|
||||
private List<TicketVo> tickets;
|
||||
private String accid;
|
||||
private Long uid;
|
||||
private String netEaseToken;
|
||||
|
||||
public String getIssue_type() {
|
||||
return issue_type;
|
||||
}
|
||||
|
||||
public String getAccid() {
|
||||
return accid;
|
||||
}
|
||||
|
||||
public Long getUid() {
|
||||
return uid;
|
||||
}
|
||||
|
||||
public String getNetEaseToken() {
|
||||
return netEaseToken;
|
||||
}
|
||||
|
||||
public void setIssue_type(String issue_type) {
|
||||
this.issue_type = issue_type;
|
||||
}
|
||||
|
||||
public List<TicketVo> getTickets() {
|
||||
return tickets;
|
||||
}
|
||||
|
||||
public void setAccid(String accid) {
|
||||
this.accid = accid;
|
||||
}
|
||||
|
||||
public void setUid(Long uid) {
|
||||
this.uid = uid;
|
||||
}
|
||||
|
||||
public void setNetEaseToken(String netEaseToken) {
|
||||
this.netEaseToken = netEaseToken;
|
||||
}
|
||||
|
||||
public void setTickets(List<Ticket> tickets){
|
||||
if(tickets == null){
|
||||
return;
|
||||
}
|
||||
this.tickets = new ArrayList<TicketVo>();
|
||||
for(Ticket ticket : tickets){
|
||||
this.tickets.add(new TicketVo(ticket));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class TicketVo{
|
||||
private String ticket;
|
||||
private int expires_in;
|
||||
private String ticket_type;
|
||||
private String scope;
|
||||
|
||||
public TicketVo(Ticket ticket){
|
||||
setTicket(ticket.getValue());
|
||||
setExpires_in(ticket.getExpiresIn());
|
||||
setTicket_type(ticket.getTicketType());
|
||||
setScope(setToString(ticket.getScope()));
|
||||
}
|
||||
|
||||
public String getTicket() {
|
||||
return ticket;
|
||||
}
|
||||
|
||||
public void setTicket(String ticket) {
|
||||
this.ticket = ticket;
|
||||
}
|
||||
|
||||
public int getExpires_in() {
|
||||
return expires_in;
|
||||
}
|
||||
|
||||
public void setExpires_in(int expires_in) {
|
||||
this.expires_in = expires_in;
|
||||
}
|
||||
|
||||
public String getTicket_type() {
|
||||
return ticket_type;
|
||||
}
|
||||
|
||||
public void setTicket_type(String ticket_type) {
|
||||
this.ticket_type = ticket_type;
|
||||
}
|
||||
|
||||
public String getScope() {
|
||||
return scope;
|
||||
}
|
||||
|
||||
public void setScope(String scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
private String setToString(Set<String> stringSet){
|
||||
if(stringSet == null){
|
||||
return null;
|
||||
}
|
||||
return StringUtils.join(stringSet," ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user