|
@@ -3,7 +3,7 @@ package com.qmth.sop.business.service.impl;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.qmth.boot.core.solar.model.WxappAccessToken;
|
|
|
+import com.qmth.boot.core.solar.model.WxappPhoneNumber;
|
|
|
import com.qmth.boot.core.solar.model.WxappSession;
|
|
|
import com.qmth.boot.core.solar.service.SolarService;
|
|
|
import com.qmth.sop.business.bean.result.LoginResult;
|
|
@@ -18,8 +18,6 @@ import com.qmth.sop.common.contant.SystemConstant;
|
|
|
import com.qmth.sop.common.enums.AppSourceEnum;
|
|
|
import com.qmth.sop.common.enums.ExceptionResultEnum;
|
|
|
import com.qmth.sop.common.util.ByteUtil;
|
|
|
-import com.qmth.sop.common.util.HttpUtil;
|
|
|
-import com.qmth.sop.common.util.JacksonUtil;
|
|
|
import com.qmth.sop.common.util.ShaUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -31,7 +29,9 @@ import javax.crypto.Cipher;
|
|
|
import javax.crypto.spec.IvParameterSpec;
|
|
|
import javax.crypto.spec.SecretKeySpec;
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
-import java.util.*;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.Optional;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -67,7 +67,6 @@ public class TWxappInfoServiceImpl extends ServiceImpl<TWxappInfoMapper, TWxappI
|
|
|
WxappSession wxappSession = getAuthorization(loginCode);
|
|
|
String openId = ByteUtil.toHexAscii(ShaUtils.encode(wxappSession.getOpenId()));
|
|
|
TWxappInfo tWxappInfo = tWxappInfoService.getOne(new QueryWrapper<TWxappInfo>().lambda().eq(TWxappInfo::getOpenId, openId));
|
|
|
-// Optional.ofNullable(tWxappInfo).orElseThrow(() -> ParameterExceptions.OPENID_NOT_FOUND);
|
|
|
Optional.ofNullable(tWxappInfo).orElseThrow(() -> ExceptionResultEnum.WXAPP_OPENID_NO_DATA.exception());
|
|
|
List<SysUser> sysUserList = sysUserService.list(new QueryWrapper<SysUser>().lambda().eq(SysUser::getMobileNumber, tWxappInfo.getPhone()));
|
|
|
if (CollectionUtils.isEmpty(sysUserList)) {
|
|
@@ -96,26 +95,10 @@ public class TWxappInfoServiceImpl extends ServiceImpl<TWxappInfoMapper, TWxappI
|
|
|
SysConfig sysConfigWxappId = commonCacheService.addSysConfigCache(SystemConstant.WXAPP_APP_ID);
|
|
|
Optional.ofNullable(sysConfigWxappId).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未配置微信小程序appid"));
|
|
|
|
|
|
- SysConfig sysConfigWxappUrl = commonCacheService.addSysConfigCache(SystemConstant.WXAPP_PHONE_BIND_NEW_URL);
|
|
|
- Optional.ofNullable(sysConfigWxappUrl).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未配置微信小程序手机绑定url"));
|
|
|
+ WxappPhoneNumber wxappPhoneNumber = solarService.getWxappPhoneNumber(sysConfigWxappId.getConfigValue(), phoneCode);
|
|
|
+ Optional.ofNullable(wxappPhoneNumber).orElseThrow(() -> ExceptionResultEnum.WXAPP_PHONE_NO_DATA.exception());
|
|
|
|
|
|
- Map<String, Object> params = new HashMap<>();
|
|
|
- params.put(SystemConstant.CODE, phoneCode);
|
|
|
- String ret;
|
|
|
- try {
|
|
|
- WxappAccessToken wxappAccessToken = solarService.getWxappAccessToken(sysConfigWxappId.getConfigValue());
|
|
|
- Optional.ofNullable(wxappAccessToken).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未查询到微信accessToken"));
|
|
|
-
|
|
|
- ret = HttpUtil.postJson(sysConfigWxappUrl.getConfigValue() + wxappAccessToken.getAccessToken(), JacksonUtil.parseJson(params), null, null, false);
|
|
|
- } catch (Exception e) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("登录失败");
|
|
|
- }
|
|
|
- JSONObject jo = JSONObject.parseObject(ret);
|
|
|
- if (Objects.nonNull(jo.getInteger(SystemConstant.ERR_CODE)) && jo.getInteger(SystemConstant.ERR_CODE).intValue() != 0) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("登录失败," + jo.getString(SystemConstant.ERR_MSG));
|
|
|
- }
|
|
|
- String phone = jo.getJSONObject(SystemConstant.PHONE_INFO).getString(SystemConstant.PURE_PHONE_NUMBER);
|
|
|
- List<SysUser> sysUserList = sysUserService.list(new QueryWrapper<SysUser>().lambda().eq(SysUser::getMobileNumber, phone));
|
|
|
+ List<SysUser> sysUserList = sysUserService.list(new QueryWrapper<SysUser>().lambda().eq(SysUser::getMobileNumber, wxappPhoneNumber.getPurePhoneNumber()));
|
|
|
if (CollectionUtils.isEmpty(sysUserList)) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("用户不存在");
|
|
|
}
|
|
@@ -129,7 +112,7 @@ public class TWxappInfoServiceImpl extends ServiceImpl<TWxappInfoMapper, TWxappI
|
|
|
WxappSession wxappSession = getAuthorization(loginCode);
|
|
|
String openId = ByteUtil.toHexAscii(ShaUtils.encode(wxappSession.getOpenId()));
|
|
|
TWxappInfo tWxappInfo = tWxappInfoService.getOne(new QueryWrapper<TWxappInfo>().lambda().eq(TWxappInfo::getOpenId, openId));
|
|
|
- tWxappInfo = Objects.isNull(tWxappInfo) ? new TWxappInfo(openId, phone) : tWxappInfo;
|
|
|
+ tWxappInfo = Objects.isNull(tWxappInfo) ? new TWxappInfo(openId, wxappPhoneNumber.getPurePhoneNumber()) : tWxappInfo;
|
|
|
tWxappInfoService.saveOrUpdate(tWxappInfo);
|
|
|
return sysUserService.login(sysUser.getPassword(), sysUser, AppSourceEnum.SYSTEM);
|
|
|
}
|
|
@@ -146,7 +129,7 @@ public class TWxappInfoServiceImpl extends ServiceImpl<TWxappInfoMapper, TWxappI
|
|
|
@Transactional
|
|
|
public LoginResult wxappLoginByEncryptedData(String loginCode, String encryptedData, String iv) throws NoSuchAlgorithmException {
|
|
|
WxappSession wxappSession = getAuthorization(loginCode);
|
|
|
- String openId = ByteUtil.toHexAscii(ShaUtils.sha256(wxappSession.getOpenId()));
|
|
|
+ String openId = ByteUtil.toHexAscii(ShaUtils.encode(wxappSession.getOpenId()));
|
|
|
JSONObject jo = decrypt(encryptedData, iv, wxappSession.getSessionKey());
|
|
|
String phone = jo.getString(SystemConstant.PURE_PHONE_NUMBER);
|
|
|
List<SysUser> sysUserList = sysUserService.list(new QueryWrapper<SysUser>().lambda().eq(SysUser::getMobileNumber, phone));
|