Merge branch 'develop' of https://gitee.com/likeadmin/likeadmin_java into develop
# Conflicts: # server/like-front/src/main/java/com/mdd/front/config/FrontConfig.java
This commit is contained in:
commit
864b54951a
|
|
@ -0,0 +1,47 @@
|
||||||
|
package com.mdd.admin.controller.channel;
|
||||||
|
|
||||||
|
import com.mdd.admin.service.IChannelOpService;
|
||||||
|
import com.mdd.admin.validate.channel.ChannelOpValidate;
|
||||||
|
import com.mdd.admin.vo.channel.ChannelOpVo;
|
||||||
|
import com.mdd.common.core.AjaxResult;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微信开发平台渠道设置
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("api/channel/op")
|
||||||
|
public class ChannelOpController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
IChannelOpService iChannelOpService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开放平台设置详情
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @return AjaxResult<Object>
|
||||||
|
*/
|
||||||
|
@GetMapping("/detail")
|
||||||
|
public AjaxResult<Object> detail() {
|
||||||
|
ChannelOpVo vo = iChannelOpService.detail();
|
||||||
|
return AjaxResult.success(vo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开放平台设置保存
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param opValidate 参数
|
||||||
|
* @return AjaxResult<Object>
|
||||||
|
*/
|
||||||
|
@PostMapping("/save")
|
||||||
|
public AjaxResult<Object> save(@Validated @RequestBody ChannelOpValidate opValidate) {
|
||||||
|
iChannelOpService.save(opValidate);
|
||||||
|
return AjaxResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.mdd.admin.service;
|
||||||
|
|
||||||
|
import com.mdd.admin.validate.channel.ChannelOpValidate;
|
||||||
|
import com.mdd.admin.vo.channel.ChannelOpVo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微信开放渠道设置接口服务类
|
||||||
|
*/
|
||||||
|
public interface IChannelOpService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开放平台设置详情
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @return ChannelOpVo
|
||||||
|
*/
|
||||||
|
ChannelOpVo detail();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开放平台设置保存
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param opValidate 参数
|
||||||
|
*/
|
||||||
|
void save(ChannelOpValidate opValidate);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
package com.mdd.admin.service.impl;
|
||||||
|
|
||||||
|
import com.mdd.admin.service.IChannelOpService;
|
||||||
|
import com.mdd.admin.validate.channel.ChannelOpValidate;
|
||||||
|
import com.mdd.admin.vo.channel.ChannelOpVo;
|
||||||
|
import com.mdd.common.util.ConfigUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开放平台设置服务类
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class ChannelOpServiceImpl implements IChannelOpService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开放平台设置详情
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @return ChannelOpVo
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ChannelOpVo detail() {
|
||||||
|
String appId = ConfigUtils.get("op_channel", "appId", "");
|
||||||
|
String appSecret = ConfigUtils.get("op_channel", "appSecret", "");
|
||||||
|
|
||||||
|
ChannelOpVo vo = new ChannelOpVo();
|
||||||
|
vo.setAppId(appId);
|
||||||
|
vo.setAppSecret(appSecret);
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开放平台设置保存
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param opValidate 参数
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void save(ChannelOpValidate opValidate) {
|
||||||
|
ConfigUtils.set("op_channel", "appId", opValidate.getAppId());
|
||||||
|
ConfigUtils.set("op_channel", "appSecret", opValidate.getAppId());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.mdd.admin.validate.channel;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开发平台渠道参数
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ChannelOpValidate implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private String appId;
|
||||||
|
|
||||||
|
private String appSecret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.mdd.admin.vo.channel;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开发平台Vo
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ChannelOpVo implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private String appId;
|
||||||
|
private String appSecret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -30,6 +30,8 @@ public class FrontConfig {
|
||||||
"/api/article/list",
|
"/api/article/list",
|
||||||
"/api/pc/getConfig",
|
"/api/pc/getConfig",
|
||||||
"/api/pc/index",
|
"/api/pc/index",
|
||||||
|
"/api/login/getScanCode",
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,10 @@ import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -104,4 +108,12 @@ public class LoginController {
|
||||||
return AjaxResult.success();
|
return AjaxResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/getScanCode")
|
||||||
|
public AjaxResult<Map<String, String>> getScanCode(HttpSession session) {
|
||||||
|
String qrcodeUrl = iLoginService.getScanCode(session);
|
||||||
|
Map<String, String> map = new LinkedHashMap<>();
|
||||||
|
map.put("url", qrcodeUrl);
|
||||||
|
return AjaxResult.success(map);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.mdd.front.service;
|
||||||
import com.mdd.front.validate.UserRegisterValidate;
|
import com.mdd.front.validate.UserRegisterValidate;
|
||||||
import com.mdd.front.vo.LoginTokenVo;
|
import com.mdd.front.vo.LoginTokenVo;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -19,13 +20,13 @@ public interface ILoginService {
|
||||||
void register(UserRegisterValidate userRegisterValidate);
|
void register(UserRegisterValidate userRegisterValidate);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信登录
|
* 账号登录
|
||||||
*
|
*
|
||||||
* @author fzr
|
* @author fzr
|
||||||
* @param params 参数
|
* @param params 参数
|
||||||
* @return LoginTokenVo
|
* @return LoginTokenVo
|
||||||
*/
|
*/
|
||||||
LoginTokenVo mnpLogin(Map<String, String> params);
|
LoginTokenVo accountLogin(Map<String, String> params);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 手机登录
|
* 手机登录
|
||||||
|
|
@ -37,13 +38,13 @@ public interface ILoginService {
|
||||||
LoginTokenVo mobileLogin(Map<String, String> params);
|
LoginTokenVo mobileLogin(Map<String, String> params);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 账号登录
|
* 微信登录
|
||||||
*
|
*
|
||||||
* @author fzr
|
* @author fzr
|
||||||
* @param params 参数
|
* @param params 参数
|
||||||
* @return LoginTokenVo
|
* @return LoginTokenVo
|
||||||
*/
|
*/
|
||||||
LoginTokenVo accountLogin(Map<String, String> params);
|
LoginTokenVo mnpLogin(Map<String, String> params);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 公众号登录
|
* 公众号登录
|
||||||
|
|
@ -71,4 +72,5 @@ public interface ILoginService {
|
||||||
*/
|
*/
|
||||||
void forgotPassword(Map<String, String> params);
|
void forgotPassword(Map<String, String> params);
|
||||||
|
|
||||||
|
String getScanCode(HttpSession session);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,9 @@ import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -75,6 +78,81 @@ public class LoginServiceImpl implements ILoginService {
|
||||||
userMapper.insert(user);
|
userMapper.insert(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 账号登录
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param params 参数
|
||||||
|
* @return LoginTokenVo
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public LoginTokenVo accountLogin(Map<String, String> params) {
|
||||||
|
Assert.notNull(params.get("username"), "username参数缺失!");
|
||||||
|
Assert.notNull(params.get("password"), "password参数缺失!");
|
||||||
|
String username = params.get("username");
|
||||||
|
String password = params.get("password");
|
||||||
|
|
||||||
|
User user = userMapper.selectOne(new QueryWrapper<User>()
|
||||||
|
.select("id,username,password,salt,mobile,is_disable")
|
||||||
|
.eq("username", username)
|
||||||
|
.eq("is_delete", 0)
|
||||||
|
.last("limit 1"));
|
||||||
|
|
||||||
|
Assert.notNull(user, "账号不存在!");
|
||||||
|
String pwd = ToolsUtils.makeMd5(password+user.getSalt());
|
||||||
|
Assert.isFalse(!pwd.equals(user.getPassword()), "账号或密码错误!");
|
||||||
|
Assert.isFalse(user.getIsDisable() != 0, "账号已被禁用!");
|
||||||
|
|
||||||
|
// 更新登录信息
|
||||||
|
user.setLastLoginIp(IpUtils.getHostIp());
|
||||||
|
user.setLastLoginTime(System.currentTimeMillis() / 1000);
|
||||||
|
userMapper.updateById(user);
|
||||||
|
|
||||||
|
return this.makeLoginToken(user.getId(), user.getMobile());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手机号登录
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param params 参数
|
||||||
|
* @return LoginTokenVo
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public LoginTokenVo mobileLogin(Map<String, String> params) {
|
||||||
|
Assert.notNull(params.get("mobile"), "mobile参数缺失!");
|
||||||
|
Assert.notNull(params.get("code"), "code参数缺失!");
|
||||||
|
String mobile = params.get("mobile");
|
||||||
|
String code = params.get("code").toLowerCase();
|
||||||
|
|
||||||
|
// 校验验证码
|
||||||
|
int typeCode = NoticeEnum.SMS_LOGIN_CODE.getCode();
|
||||||
|
Object smsCode = RedisUtils.get(GlobalConfig.redisSmsCode+typeCode+":"+mobile);
|
||||||
|
if (StringUtils.isNull(smsCode) || !smsCode.toString().equals(code)) {
|
||||||
|
throw new OperateException("验证码错误!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除验证码
|
||||||
|
RedisUtils.del(GlobalConfig.redisSmsCode+typeCode+":"+mobile);
|
||||||
|
|
||||||
|
// 查询手机号
|
||||||
|
User user = userMapper.selectOne(new QueryWrapper<User>()
|
||||||
|
.select("id,username,mobile,is_disable")
|
||||||
|
.eq("mobile", mobile)
|
||||||
|
.eq("is_delete", 0)
|
||||||
|
.last("limit 1"));
|
||||||
|
|
||||||
|
Assert.notNull(user, "账号不存在!");
|
||||||
|
Assert.isFalse(user.getIsDisable() != 0, "账号已禁用!");
|
||||||
|
|
||||||
|
// 更新登录信息
|
||||||
|
user.setLastLoginIp(IpUtils.getHostIp());
|
||||||
|
user.setLastLoginTime(System.currentTimeMillis() / 1000);
|
||||||
|
userMapper.updateById(user);
|
||||||
|
|
||||||
|
return this.makeLoginToken(user.getId(), user.getMobile());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信小程序登录
|
* 微信小程序登录
|
||||||
*
|
*
|
||||||
|
|
@ -162,111 +240,13 @@ public class LoginServiceImpl implements ILoginService {
|
||||||
userMapper.updateById(user);
|
userMapper.updateById(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
String token = ToolsUtils.makeToken();
|
|
||||||
int tokenValidTime = Integer.parseInt(YmlUtils.get("like.token-valid-time"));
|
|
||||||
RedisUtils.set(FrontConfig.frontendTokenKey+token, userId, tokenValidTime);
|
|
||||||
|
|
||||||
LoginTokenVo vo = new LoginTokenVo();
|
return this.makeLoginToken(userId, user.getMobile());
|
||||||
vo.setId(userId);
|
|
||||||
vo.setIsBindMobile(!user.getMobile().equals(""));
|
|
||||||
vo.setToken(token);
|
|
||||||
return vo;
|
|
||||||
} catch (WxErrorException e) {
|
} catch (WxErrorException e) {
|
||||||
throw new OperateException(e.getError().getErrorCode() + ", " + e.getError().getErrorMsg());
|
throw new OperateException(e.getError().getErrorCode() + ", " + e.getError().getErrorMsg());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 手机号登录
|
|
||||||
*
|
|
||||||
* @author fzr
|
|
||||||
* @param params 参数
|
|
||||||
* @return LoginTokenVo
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public LoginTokenVo mobileLogin(Map<String, String> params) {
|
|
||||||
Assert.notNull(params.get("mobile"), "mobile参数缺失!");
|
|
||||||
Assert.notNull(params.get("code"), "code参数缺失!");
|
|
||||||
String mobile = params.get("mobile");
|
|
||||||
String code = params.get("code").toLowerCase();
|
|
||||||
|
|
||||||
// 校验验证码
|
|
||||||
int typeCode = NoticeEnum.SMS_LOGIN_CODE.getCode();
|
|
||||||
Object smsCode = RedisUtils.get(GlobalConfig.redisSmsCode+typeCode+":"+mobile);
|
|
||||||
if (StringUtils.isNull(smsCode) || !smsCode.toString().equals(code)) {
|
|
||||||
throw new OperateException("验证码错误!");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 删除验证码
|
|
||||||
RedisUtils.del(GlobalConfig.redisSmsCode+typeCode+":"+mobile);
|
|
||||||
|
|
||||||
// 查询手机号
|
|
||||||
User user = userMapper.selectOne(new QueryWrapper<User>()
|
|
||||||
.select("id,username,mobile,is_disable")
|
|
||||||
.eq("mobile", mobile)
|
|
||||||
.eq("is_delete", 0)
|
|
||||||
.last("limit 1"));
|
|
||||||
|
|
||||||
Assert.notNull(user, "账号不存在!");
|
|
||||||
Assert.isFalse(user.getIsDisable() != 0, "账号已禁用!");
|
|
||||||
|
|
||||||
// 更新登录信息
|
|
||||||
user.setLastLoginIp(IpUtils.getHostIp());
|
|
||||||
user.setLastLoginTime(System.currentTimeMillis() / 1000);
|
|
||||||
userMapper.updateById(user);
|
|
||||||
|
|
||||||
String token = ToolsUtils.makeToken();
|
|
||||||
int tokenValidTime = Integer.parseInt(YmlUtils.get("like.token-valid-time"));
|
|
||||||
RedisUtils.set(FrontConfig.frontendTokenKey+token, user.getId(), tokenValidTime);
|
|
||||||
|
|
||||||
LoginTokenVo vo = new LoginTokenVo();
|
|
||||||
vo.setId(user.getId());
|
|
||||||
vo.setIsBindMobile(!user.getMobile().equals(""));
|
|
||||||
vo.setToken(token);
|
|
||||||
return vo;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 账号登录
|
|
||||||
*
|
|
||||||
* @author fzr
|
|
||||||
* @param params 参数
|
|
||||||
* @return LoginTokenVo
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public LoginTokenVo accountLogin(Map<String, String> params) {
|
|
||||||
Assert.notNull(params.get("username"), "username参数缺失!");
|
|
||||||
Assert.notNull(params.get("password"), "password参数缺失!");
|
|
||||||
String username = params.get("username");
|
|
||||||
String password = params.get("password");
|
|
||||||
|
|
||||||
User user = userMapper.selectOne(new QueryWrapper<User>()
|
|
||||||
.select("id,username,password,salt,mobile,is_disable")
|
|
||||||
.eq("username", username)
|
|
||||||
.eq("is_delete", 0)
|
|
||||||
.last("limit 1"));
|
|
||||||
|
|
||||||
Assert.notNull(user, "账号不存在!");
|
|
||||||
String pwd = ToolsUtils.makeMd5(password+user.getSalt());
|
|
||||||
Assert.isFalse(!pwd.equals(user.getPassword()), "账号或密码错误!");
|
|
||||||
Assert.isFalse(user.getIsDisable() != 0, "账号已被禁用!");
|
|
||||||
|
|
||||||
// 更新登录信息
|
|
||||||
user.setLastLoginIp(IpUtils.getHostIp());
|
|
||||||
user.setLastLoginTime(System.currentTimeMillis() / 1000);
|
|
||||||
userMapper.updateById(user);
|
|
||||||
|
|
||||||
String token = ToolsUtils.makeToken();
|
|
||||||
int tokenValidTime = Integer.parseInt(YmlUtils.get("like.token-valid-time"))+1;
|
|
||||||
RedisUtils.set(FrontConfig.frontendTokenKey+token, user.getId(), tokenValidTime-1);
|
|
||||||
|
|
||||||
LoginTokenVo vo = new LoginTokenVo();
|
|
||||||
vo.setId(user.getId());
|
|
||||||
vo.setIsBindMobile(!user.getMobile().equals(""));
|
|
||||||
vo.setToken(token);
|
|
||||||
return vo;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 公众号登录
|
* 公众号登录
|
||||||
*
|
*
|
||||||
|
|
@ -341,15 +321,7 @@ public class LoginServiceImpl implements ILoginService {
|
||||||
userMapper.updateById(user);
|
userMapper.updateById(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
String token = ToolsUtils.makeToken();
|
return this.makeLoginToken(userId, user.getMobile());
|
||||||
int tokenValidTime = Integer.parseInt(YmlUtils.get("like.token-valid-time"))+1;
|
|
||||||
RedisUtils.set(FrontConfig.frontendTokenKey+token, userId, tokenValidTime-1);
|
|
||||||
|
|
||||||
LoginTokenVo vo = new LoginTokenVo();
|
|
||||||
vo.setId(user.getId());
|
|
||||||
vo.setIsBindMobile(!user.getMobile().equals(""));
|
|
||||||
vo.setToken(token);
|
|
||||||
return vo;
|
|
||||||
} catch (WxErrorException e) {
|
} catch (WxErrorException e) {
|
||||||
throw new OperateException(e.getError().getErrorCode() + ", " + e.getError().getErrorMsg());
|
throw new OperateException(e.getError().getErrorCode() + ", " + e.getError().getErrorMsg());
|
||||||
}
|
}
|
||||||
|
|
@ -414,6 +386,63 @@ public class LoginServiceImpl implements ILoginService {
|
||||||
userMapper.updateById(user);
|
userMapper.updateById(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 扫码链接
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param session session
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getScanCode(HttpSession session) {
|
||||||
|
// 获取AppId
|
||||||
|
String appId = ConfigUtils.get("op_channel", "appId", "");
|
||||||
|
|
||||||
|
// 微信开放平台授权
|
||||||
|
String baseUrl = "https://open.weixin.qq.com/connect/qrconnect" +
|
||||||
|
"?appid=%s" +
|
||||||
|
"&redirect_uri=%s" +
|
||||||
|
"&response_type=code" +
|
||||||
|
"&scope=snsapi_login" +
|
||||||
|
"&state=%s" +
|
||||||
|
"#wechat_redirect";
|
||||||
|
|
||||||
|
// 回调地址
|
||||||
|
String redirectUrl = "https://www.baidu.com/";
|
||||||
|
try {
|
||||||
|
redirectUrl = URLEncoder.encode(redirectUrl, "UTF-8");
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
throw new OperateException(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 防止csrf攻击
|
||||||
|
String state = ToolsUtils.makeUUID().replaceAll("-", "");
|
||||||
|
RedisUtils.set("wechat-open-state-"+session.getId(), state, 600);
|
||||||
|
|
||||||
|
//生成qrcodeUrl
|
||||||
|
return String.format(baseUrl, appId, redirectUrl, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成登录Token
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @param mobile 用户手机
|
||||||
|
* @return LoginTokenVo
|
||||||
|
*/
|
||||||
|
private LoginTokenVo makeLoginToken(Integer userId, String mobile) {
|
||||||
|
String token = ToolsUtils.makeToken();
|
||||||
|
int tokenValidTime = Integer.parseInt(YmlUtils.get("like.token-valid-time"));
|
||||||
|
RedisUtils.set(FrontConfig.frontendTokenKey+token, userId, tokenValidTime);
|
||||||
|
|
||||||
|
LoginTokenVo vo = new LoginTokenVo();
|
||||||
|
vo.setId(userId);
|
||||||
|
vo.setIsBindMobile(!mobile.equals(""));
|
||||||
|
vo.setToken(token);
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成用户编号
|
* 生成用户编号
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue