|
@@ -1,78 +0,0 @@
|
|
|
-package com.xy.third.service;
|
|
|
-
|
|
|
-import cn.binarywang.wx.miniapp.api.WxMaService;
|
|
|
-import cn.binarywang.wx.miniapp.api.WxMaUserService;
|
|
|
-import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
|
|
-import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
|
|
-import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
|
|
|
-import cn.binarywang.wx.miniapp.util.WxMaConfigHolder;
|
|
|
-import cn.dev33.satoken.stp.StpUtil;
|
|
|
-import com.xy.dto.ThirdLoginDto;
|
|
|
-import com.xy.dto.WxMaDto;
|
|
|
-import com.xy.error.CommRuntimeException;
|
|
|
-import com.xy.service.ThirdLoginService;
|
|
|
-import com.xy.utils.FunctionUtils;
|
|
|
-import com.xy.utils.R;
|
|
|
-import io.swagger.annotations.Api;
|
|
|
-import io.swagger.annotations.ApiOperation;
|
|
|
-import lombok.AllArgsConstructor;
|
|
|
-import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.util.StringUtils;
|
|
|
-import org.springframework.validation.annotation.Validated;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
-
|
|
|
-import static com.xy.utils.Beans.copy;
|
|
|
-
|
|
|
-@Service
|
|
|
-@AllArgsConstructor
|
|
|
-@Api(tags = "第三方登录")
|
|
|
-public class ThirdLoginServiceImpl implements ThirdLoginService {
|
|
|
-
|
|
|
- private WxMaService wxMaService;
|
|
|
-
|
|
|
- @Override
|
|
|
- @ApiOperation("登录")
|
|
|
- public R<String> login(ThirdLoginDto thirdLoginDto) {
|
|
|
- StpUtil.login(thirdLoginDto.getLoginId());
|
|
|
- return R.ok(StpUtil.getTokenValue());
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- @ApiOperation("获取用户信息-微信小程序")
|
|
|
- public R<WxMaDto.Vo> getUserInfoWxMa(@RequestBody @Validated WxMaDto.GetUserInfo getUserInfo) {
|
|
|
- WxMaDto.Vo vo = new WxMaDto.Vo();
|
|
|
- WxMaUserService userService = wxMaService.getUserService();
|
|
|
- //获取用户信息
|
|
|
- FunctionUtils.NoParamsNoResult getInfo = () -> {
|
|
|
- String code = getUserInfo.getCode();
|
|
|
- if (StringUtils.isEmpty(code)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- WxMaJscode2SessionResult session;
|
|
|
- try {
|
|
|
- session = userService.getSessionInfo(code);
|
|
|
- } catch (WxErrorException e) {
|
|
|
- throw new CommRuntimeException("登录失败");
|
|
|
- }
|
|
|
- String openid = session.getOpenid();
|
|
|
- String sessionKey = session.getSessionKey();
|
|
|
- WxMaUserInfo userInfo = userService.getUserInfo(sessionKey, getUserInfo.getEncryptedData(), getUserInfo.getIv());
|
|
|
- copy(vo, userInfo).setOpenId(openid)
|
|
|
- .setSessionKey(sessionKey);
|
|
|
- };
|
|
|
- //获取手机信息
|
|
|
- FunctionUtils.NoParamsNoResult getTel = () -> {
|
|
|
- String sessionKey = getUserInfo.getSessionKey();
|
|
|
- if (StringUtils.isEmpty(sessionKey)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- WxMaPhoneNumberInfo phoneNoInfo = userService.getPhoneNoInfo(sessionKey, getUserInfo.getEncryptedData(), getUserInfo.getIv());
|
|
|
- vo.setTel(phoneNoInfo.getPhoneNumber());
|
|
|
- };
|
|
|
- getInfo.run();
|
|
|
- getTel.run();
|
|
|
- WxMaConfigHolder.remove();
|
|
|
- return R.ok(vo);
|
|
|
- }
|
|
|
-}
|