扫码登录二维码
This commit is contained in:
parent
444ea6b4cb
commit
43983deb48
|
|
@ -28,6 +28,8 @@ public class FrontConfig {
|
|||
"/api/article/category",
|
||||
"/api/article/detail",
|
||||
"/api/article/list",
|
||||
|
||||
"/api/login/getScanCode"
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,10 @@ import org.springframework.validation.annotation.Validated;
|
|||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
|
|
@ -104,4 +108,12 @@ public class LoginController {
|
|||
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.vo.LoginTokenVo;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
|
@ -71,4 +72,5 @@ public interface ILoginService {
|
|||
*/
|
||||
void forgotPassword(Map<String, String> params);
|
||||
|
||||
String getScanCode(HttpSession session);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import com.mdd.front.config.FrontConfig;
|
|||
import com.mdd.front.service.ILoginService;
|
||||
import com.mdd.front.validate.UserRegisterValidate;
|
||||
import com.mdd.front.vo.LoginTokenVo;
|
||||
import jdk.nashorn.internal.runtime.regexp.joni.Config;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
|
||||
|
|
@ -27,6 +28,9 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
|
@ -414,6 +418,36 @@ public class LoginServiceImpl implements ILoginService {
|
|||
userMapper.updateById(user);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成用户编号
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue