公众号登录
This commit is contained in:
parent
959b3d84dc
commit
535cf29350
|
|
@ -10,7 +10,6 @@ public class FrontConfig {
|
||||||
|
|
||||||
// 免登录验证
|
// 免登录验证
|
||||||
public static String[] notLoginUri = new String[]{
|
public static String[] notLoginUri = new String[]{
|
||||||
"/api/login",
|
|
||||||
"/api/index",
|
"/api/index",
|
||||||
"/api/config",
|
"/api/config",
|
||||||
"/api/policy",
|
"/api/policy",
|
||||||
|
|
@ -21,6 +20,7 @@ public class FrontConfig {
|
||||||
"/api/upload/image",
|
"/api/upload/image",
|
||||||
|
|
||||||
"/api/login/check",
|
"/api/login/check",
|
||||||
|
"/api/login/codeUrl",
|
||||||
"/api/login/register",
|
"/api/login/register",
|
||||||
"/api/login/forgotPassword",
|
"/api/login/forgotPassword",
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,18 @@
|
||||||
package com.mdd.front.controller;
|
package com.mdd.front.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||||
import com.mdd.common.core.AjaxResult;
|
import com.mdd.common.core.AjaxResult;
|
||||||
|
import com.mdd.common.utils.ConfigUtil;
|
||||||
|
import com.mdd.common.utils.WeChatUtil;
|
||||||
import com.mdd.front.service.ILoginService;
|
import com.mdd.front.service.ILoginService;
|
||||||
import com.mdd.front.validate.RegParam;
|
import com.mdd.front.validate.RegParam;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import me.chanjar.weixin.common.api.WxConsts;
|
||||||
|
import me.chanjar.weixin.mp.api.WxMpService;
|
||||||
|
import me.chanjar.weixin.mp.api.impl.WxMpOAuth2ServiceImpl;
|
||||||
|
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
|
||||||
|
import me.chanjar.weixin.mp.enums.WxMpApiUrl;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
|
@ -14,6 +23,7 @@ import java.util.Map;
|
||||||
/**
|
/**
|
||||||
* 登录管理
|
* 登录管理
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/login")
|
@RequestMapping("/api/login")
|
||||||
public class LoginController {
|
public class LoginController {
|
||||||
|
|
@ -55,13 +65,32 @@ public class LoginController {
|
||||||
case "account":
|
case "account":
|
||||||
map = iLoginService.accountLogin(params);
|
map = iLoginService.accountLogin(params);
|
||||||
break;
|
break;
|
||||||
case "office":
|
|
||||||
map = iLoginService.officeLogin();
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return AjaxResult.success(map);
|
return AjaxResult.success(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/oaLogin")
|
||||||
|
public Object oaLogin(@RequestBody Map<String, String> params) {
|
||||||
|
log.error("微信公众号 ===================");
|
||||||
|
log.error(JSON.toJSONString(params));
|
||||||
|
// iLoginService.officeLogin(params);
|
||||||
|
return AjaxResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公众号跳转url
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param url 连接
|
||||||
|
* @return Object
|
||||||
|
*/
|
||||||
|
@GetMapping("/codeUrl")
|
||||||
|
public Object codeUrl(@RequestParam String url) {
|
||||||
|
Assert.notNull(url, "url参数不能为空");
|
||||||
|
String uri = iLoginService.codeUrl(url);
|
||||||
|
return AjaxResult.success(uri);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 忘记密码
|
* 忘记密码
|
||||||
*
|
*
|
||||||
|
|
@ -71,8 +100,8 @@ public class LoginController {
|
||||||
*/
|
*/
|
||||||
@PostMapping("/forgotPassword")
|
@PostMapping("/forgotPassword")
|
||||||
public Object forgotPassword(@RequestBody Map<String, String> params) {
|
public Object forgotPassword(@RequestBody Map<String, String> params) {
|
||||||
iLoginService.forgotPassword(params);
|
iLoginService.forgotPassword(params);
|
||||||
return AjaxResult.success();
|
return AjaxResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,9 +48,19 @@ public interface ILoginService {
|
||||||
* 公众号登录
|
* 公众号登录
|
||||||
*
|
*
|
||||||
* @author fzr
|
* @author fzr
|
||||||
|
* @param params 参数
|
||||||
* @return Map<String, Object>
|
* @return Map<String, Object>
|
||||||
*/
|
*/
|
||||||
Map<String, Object> officeLogin();
|
Map<String, Object> officeLogin(Map<String, String> params);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公众号跳转url
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param url 连接
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
String codeUrl(String url);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 忘记密码
|
* 忘记密码
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,11 @@ import com.mdd.common.utils.*;
|
||||||
import com.mdd.front.config.FrontConfig;
|
import com.mdd.front.config.FrontConfig;
|
||||||
import com.mdd.front.service.ILoginService;
|
import com.mdd.front.service.ILoginService;
|
||||||
import com.mdd.front.validate.RegParam;
|
import com.mdd.front.validate.RegParam;
|
||||||
|
import me.chanjar.weixin.common.api.WxConsts;
|
||||||
import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
|
import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
|
||||||
import me.chanjar.weixin.common.error.WxErrorException;
|
import me.chanjar.weixin.common.error.WxErrorException;
|
||||||
import me.chanjar.weixin.mp.api.WxMpService;
|
import me.chanjar.weixin.mp.api.WxMpService;
|
||||||
|
import me.chanjar.weixin.mp.api.impl.WxMpOAuth2ServiceImpl;
|
||||||
import me.chanjar.weixin.mp.bean.result.WxMpUser;
|
import me.chanjar.weixin.mp.bean.result.WxMpUser;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
@ -258,10 +260,13 @@ public class LoginServiceImpl implements ILoginService {
|
||||||
* @return Map<String, Object>
|
* @return Map<String, Object>
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> officeLogin() {
|
public Map<String, Object> officeLogin(Map<String, String> params) {
|
||||||
WxMpService wxMpService = WeChatUtil.official();
|
Assert.notNull(params.get("code"), "code参数缺失!");
|
||||||
|
String code = params.get("code");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
WxOAuth2AccessToken wxOAuth2AccessToken = wxMpService.getOAuth2Service().getAccessToken("aaa");
|
WxMpService wxMpService = WeChatUtil.official();
|
||||||
|
WxOAuth2AccessToken wxOAuth2AccessToken = wxMpService.getOAuth2Service().getAccessToken(code);
|
||||||
WxMpUser wxMpUser = wxMpService.getUserService().userInfo(wxOAuth2AccessToken.getAccessToken());
|
WxMpUser wxMpUser = wxMpService.getUserService().userInfo(wxOAuth2AccessToken.getAccessToken());
|
||||||
System.out.println(wxMpUser);
|
System.out.println(wxMpUser);
|
||||||
} catch (WxErrorException e) {
|
} catch (WxErrorException e) {
|
||||||
|
|
@ -270,6 +275,20 @@ public class LoginServiceImpl implements ILoginService {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公众号跳转url
|
||||||
|
*
|
||||||
|
* @author fzr
|
||||||
|
* @param url 连接
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String codeUrl(String url) {
|
||||||
|
WxMpService wxMpService = WeChatUtil.official();
|
||||||
|
WxMpOAuth2ServiceImpl wxMpOAuth2Service = new WxMpOAuth2ServiceImpl(wxMpService);
|
||||||
|
return wxMpOAuth2Service.buildAuthorizationUrl(url, WxConsts.OAuth2Scope.SNSAPI_USERINFO, null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 忘记密码
|
* 忘记密码
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue