parent
29f516aa6d
commit
df9f40ade3
|
|
@ -15,4 +15,7 @@ public class OperateException extends BaseException {
|
||||||
super(errCode, msg, ErrorEnum.SHOW_MSG.getCode());
|
super(errCode, msg, ErrorEnum.SHOW_MSG.getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public OperateException(String msg, Integer errCode, Integer showCode) {
|
||||||
|
super(errCode, msg, showCode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,12 @@ import com.mdd.common.aop.NotPower;
|
||||||
import com.mdd.common.core.AjaxResult;
|
import com.mdd.common.core.AjaxResult;
|
||||||
import com.mdd.front.LikeFrontThreadLocal;
|
import com.mdd.front.LikeFrontThreadLocal;
|
||||||
import com.mdd.front.service.ILoginService;
|
import com.mdd.front.service.ILoginService;
|
||||||
|
import com.mdd.front.service.IUserService;
|
||||||
import com.mdd.front.validate.login.*;
|
import com.mdd.front.validate.login.*;
|
||||||
|
import com.mdd.front.validate.users.UserBindWechatValidate;
|
||||||
import com.mdd.front.vo.login.LoginUrlsVo;
|
import com.mdd.front.vo.login.LoginUrlsVo;
|
||||||
import com.mdd.front.vo.login.LoginTokenVo;
|
import com.mdd.front.vo.login.LoginTokenVo;
|
||||||
|
import com.mdd.front.vo.user.UserInfoVo;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
@ -27,6 +30,8 @@ public class LoginController {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
ILoginService iLoginService;
|
ILoginService iLoginService;
|
||||||
|
@Resource
|
||||||
|
IUserService iUserService;
|
||||||
|
|
||||||
@NotLogin
|
@NotLogin
|
||||||
@PostMapping("/register")
|
@PostMapping("/register")
|
||||||
|
|
@ -82,16 +87,16 @@ public class LoginController {
|
||||||
LoginTokenVo vo = iLoginService.officeLogin(code, terminal);
|
LoginTokenVo vo = iLoginService.officeLogin(code, terminal);
|
||||||
return AjaxResult.success(vo);
|
return AjaxResult.success(vo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotLogin
|
@NotLogin
|
||||||
@GetMapping("/oaCodeUrl")
|
@GetMapping("/codeUrl")
|
||||||
@ApiOperation(value="公众号链接")
|
@ApiOperation(value="公众号链接")
|
||||||
public AjaxResult<LoginUrlsVo> oaCodeUrl(@Validated @NotNull() @RequestParam("url") String url) {
|
public AjaxResult<LoginUrlsVo> codeUrl(@Validated @NotNull() @RequestParam("url") String url) {
|
||||||
LoginUrlsVo vo = new LoginUrlsVo();
|
LoginUrlsVo vo = new LoginUrlsVo();
|
||||||
vo.setUrl(iLoginService.oaCodeUrl(url));
|
vo.setUrl(iLoginService.oaCodeUrl(url));
|
||||||
return AjaxResult.success(vo);
|
return AjaxResult.success(vo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@NotLogin
|
@NotLogin
|
||||||
@GetMapping("/scanCodeUrl")
|
@GetMapping("/scanCodeUrl")
|
||||||
@ApiOperation(value="PC扫码链接")
|
@ApiOperation(value="PC扫码链接")
|
||||||
|
|
@ -122,4 +127,12 @@ public class LoginController {
|
||||||
return AjaxResult.success();
|
return AjaxResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotLogin
|
||||||
|
@PostMapping("/oaAuthBind")
|
||||||
|
@ApiOperation(value="绑定微信公众号")
|
||||||
|
public AjaxResult<Object> oaAuthBind(@Validated @RequestBody UserBindWechatValidate BindOaValidate) {
|
||||||
|
Integer userId = LikeFrontThreadLocal.getUserId();
|
||||||
|
iUserService.bindOa(BindOaValidate, userId);
|
||||||
|
return AjaxResult.success();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -225,7 +225,8 @@ public class LoginServiceImpl implements ILoginService {
|
||||||
public String oaCodeUrl(String url) {
|
public String oaCodeUrl(String url) {
|
||||||
WxMpService wxMpService = WxMnpDriver.oa();
|
WxMpService wxMpService = WxMnpDriver.oa();
|
||||||
WxMpOAuth2ServiceImpl wxMpOAuth2Service = new WxMpOAuth2ServiceImpl(wxMpService);
|
WxMpOAuth2ServiceImpl wxMpOAuth2Service = new WxMpOAuth2ServiceImpl(wxMpService);
|
||||||
return wxMpOAuth2Service.buildAuthorizationUrl(url, WxConsts.OAuth2Scope.SNSAPI_USERINFO, null);
|
String state = ToolUtils.makeMd5(ToolUtils.makeToken());
|
||||||
|
return wxMpOAuth2Service.buildAuthorizationUrl(url, WxConsts.OAuth2Scope.SNSAPI_USERINFO, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -375,6 +375,8 @@ public class UserServiceImpl implements IUserService {
|
||||||
String uniId = wxOAuth2AccessToken.getUnionId();
|
String uniId = wxOAuth2AccessToken.getUnionId();
|
||||||
String openId = wxOAuth2AccessToken.getOpenId();
|
String openId = wxOAuth2AccessToken.getOpenId();
|
||||||
String unionId = uniId == null ? "0" : uniId;
|
String unionId = uniId == null ? "0" : uniId;
|
||||||
|
Integer terminal = ClientEnum.OA.getCode();
|
||||||
|
String key = bindOaValidate.getKey();
|
||||||
|
|
||||||
// 授权校验,未授权创建授权,已授权返回
|
// 授权校验,未授权创建授权,已授权返回
|
||||||
bindWechatAuth(openId, unionId, ClientEnum.OA.getCode(), userId);
|
bindWechatAuth(openId, unionId, ClientEnum.OA.getCode(), userId);
|
||||||
|
|
@ -445,6 +447,18 @@ public class UserServiceImpl implements IUserService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotNull(unionId)) {
|
||||||
|
if (unionId.equals("0") == false) {
|
||||||
|
//在用unionid找记录,防止生成两个账号,同个unionid的问题
|
||||||
|
UserAuth userAuth = userAuthMapper.selectOne(new QueryWrapper<UserAuth>()
|
||||||
|
.eq("unionid", unionId)
|
||||||
|
.last("limit 1"));
|
||||||
|
if (StringUtils.isNotNull(userAuth)) {
|
||||||
|
throw new OperateException("该微信已被绑定");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 记录微信授权
|
// 记录微信授权
|
||||||
UserAuth authModel = new UserAuth();
|
UserAuth authModel = new UserAuth();
|
||||||
authModel.setUserId(userId);
|
authModel.setUserId(userId);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
package com.mdd.front.service.impl;
|
package com.mdd.front.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSONArray;
|
||||||
|
import com.mdd.common.enums.ErrorEnum;
|
||||||
|
import com.mdd.common.exception.OperateException;
|
||||||
import com.mdd.common.plugin.wechat.WxMnpDriver;
|
import com.mdd.common.plugin.wechat.WxMnpDriver;
|
||||||
import com.mdd.common.util.ConfigUtils;
|
import com.mdd.common.util.ConfigUtils;
|
||||||
import com.mdd.front.service.IWechatService;
|
import com.mdd.front.service.IWechatService;
|
||||||
|
|
@ -12,36 +15,41 @@ public class WechatServiceImpl implements IWechatService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> jsConfig(String url) throws Exception {
|
public Map<String, Object> jsConfig(String url) throws Exception {
|
||||||
String appId = ConfigUtils.get("oa_setting", "app_id");
|
try {
|
||||||
String accessToken = WxMnpDriver.mnp().getAccessToken();
|
String appId = ConfigUtils.get("oa_setting", "app_id");
|
||||||
String jsapiTicket = WxMnpDriver.getJsSdkGetTicket(accessToken);
|
String accessToken = WxMnpDriver.oa().getAccessToken();
|
||||||
String timestamp = Long.toString(System.currentTimeMillis() / 1000);
|
String jsapiTicket = WxMnpDriver.getJsSdkGetTicket(accessToken);
|
||||||
String nonceStr = UUID.randomUUID().toString();
|
String timestamp = Long.toString(System.currentTimeMillis() / 1000);
|
||||||
String signature = WxMnpDriver.buildJSSDKSignature(jsapiTicket,timestamp,nonceStr,url);
|
String nonceStr = UUID.randomUUID().toString();
|
||||||
|
String signature = WxMnpDriver.buildJSSDKSignature(jsapiTicket,timestamp,nonceStr,url);
|
||||||
|
|
||||||
List<String> array = Arrays.asList(
|
List<String> array = Arrays.asList(
|
||||||
"onMenuShareTimeline",
|
"onMenuShareTimeline",
|
||||||
"onMenuShareAppMessage",
|
"onMenuShareAppMessage",
|
||||||
"onMenuShareQQ",
|
"onMenuShareQQ",
|
||||||
"onMenuShareWeibo",
|
"onMenuShareWeibo",
|
||||||
"onMenuShareQZone",
|
"onMenuShareQZone",
|
||||||
"openLocation",
|
"openLocation",
|
||||||
"getLocation",
|
"getLocation",
|
||||||
"chooseWXPay",
|
"chooseWXPay",
|
||||||
"updateAppMessageShareData",
|
"updateAppMessageShareData",
|
||||||
"updateTimelineShareData",
|
"updateTimelineShareData",
|
||||||
"openAddress",
|
"openAddress",
|
||||||
"scanQRCode");
|
"scanQRCode");
|
||||||
|
|
||||||
Map<String,Object> map = new HashMap<>();
|
Map<String,Object> map = new HashMap<>();
|
||||||
map.put("url", url);
|
map.put("url", url);
|
||||||
map.put("jsapi_ticket", jsapiTicket);
|
map.put("jsapi_ticket", jsapiTicket);
|
||||||
map.put("nonceStr", nonceStr);
|
map.put("nonceStr", nonceStr);
|
||||||
map.put("timestamp", timestamp);
|
map.put("timestamp", timestamp);
|
||||||
map.put("signature", signature);
|
map.put("signature", signature);
|
||||||
map.put("appid", appId);
|
map.put("appId", appId);
|
||||||
map.put("jsApiList", array);
|
map.put("jsApiList", array);
|
||||||
return map;
|
map.put("openTagList", new JSONArray());
|
||||||
|
map.put("debug", false);
|
||||||
|
return map;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new OperateException(e.getMessage(), ErrorEnum.FAILED.getCode(), -1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,4 +17,6 @@ public class UserBindWechatValidate implements Serializable {
|
||||||
@ApiModelProperty(value = "微信code", required = true)
|
@ApiModelProperty(value = "微信code", required = true)
|
||||||
private String code;
|
private String code;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "key")
|
||||||
|
private String key;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue