|
@@ -31,6 +31,7 @@ import com.zhongzheng.modules.goods.domain.Goods;
|
|
|
import com.zhongzheng.modules.goods.service.IGoodsService;
|
|
|
import com.zhongzheng.modules.goods.vo.GoodsVo;
|
|
|
import com.zhongzheng.modules.grade.domain.ClassGradeUser;
|
|
|
+import com.zhongzheng.modules.system.domain.SysConfig;
|
|
|
import com.zhongzheng.modules.system.domain.SysTenant;
|
|
|
import com.zhongzheng.modules.system.service.ISysConfigService;
|
|
|
import com.zhongzheng.modules.system.service.ISysTenantService;
|
|
@@ -51,6 +52,7 @@ import org.springframework.stereotype.Component;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
+import java.io.InputStream;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -169,6 +171,9 @@ public class WxLoginService implements IWxLoginService {
|
|
|
@Autowired
|
|
|
private ISysTenantService iSysTenantService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ISysConfigService iSysConfigService;
|
|
|
+
|
|
|
private final String KEY_PREFIX = "GOODS_SHARE";
|
|
|
|
|
|
public void initData(){
|
|
@@ -199,7 +204,8 @@ public class WxLoginService implements IWxLoginService {
|
|
|
String scanCode = ToolsUtils.getCharAndNumr(6);
|
|
|
String key = "SCAN_LOGIN_" + scanCode;
|
|
|
String keyStatus = "SCAN_LOGIN_STATUS_" + scanCode; //0未扫码 1已扫码 2已登录
|
|
|
- String codeUrl = scanLoginHost + "pc/login/" + scanCode;
|
|
|
+// String codeUrl = scanLoginHost + "pc/login/" + scanCode;
|
|
|
+ String codeUrl = scanLoginHost + "pages4/login/pcLogin?q=" + scanCode;
|
|
|
String urlBase64 = null;
|
|
|
try {
|
|
|
QRCodeWriter qrCodeWriter = new QRCodeWriter();
|
|
@@ -1517,4 +1523,79 @@ public class WxLoginService implements IWxLoginService {
|
|
|
}
|
|
|
return vo;
|
|
|
}
|
|
|
+
|
|
|
+ public Map<String, String> checkGzh_openId(WxLoginBody loginBody) {
|
|
|
+ initData();
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ String param = String.format(gzh_wxAuthParam, gzh_appid, gzh_appsrcret, loginBody.getCode());
|
|
|
+ String resultString = HttpUtils.sendGet(gzh_wxAuthUrl, param);
|
|
|
+ //解析json
|
|
|
+ JSONObject jsonObject = (JSONObject) JSONObject.parse(resultString);
|
|
|
+ String access_token = String.valueOf(jsonObject.get("access_token"));
|
|
|
+ if(access_token.equals("null")){
|
|
|
+ throw new CustomException( String.valueOf(jsonObject.get("errmsg")));
|
|
|
+ }
|
|
|
+ String openId = String.valueOf(jsonObject.get("openid"));
|
|
|
+ //通过域名获取商户ID
|
|
|
+ SysConfig config = iSysConfigService.getOne(new LambdaQueryWrapper<SysConfig>()
|
|
|
+ .eq(SysConfig::getConfigValue, scanLoginHost)
|
|
|
+ .eq(SysConfig::getConfigKey, "wx.scanLogin.host")
|
|
|
+ .last("limit 1"));
|
|
|
+ if (ObjectUtils.isNull(config)){
|
|
|
+ throw new CustomException("域名配置获取失败,请检查!");
|
|
|
+ }
|
|
|
+ ServletUtils.getResponse().setHeader("TenantId",config.getTenantId().toString());
|
|
|
+ if (StringUtils.isNotBlank(loginBody.getAccount()) && StringUtils.isNotBlank(loginBody.getPassword())){
|
|
|
+ LambdaQueryWrapper<User> queryWrapper =new LambdaQueryWrapper<User>();
|
|
|
+ queryWrapper.and(wq -> wq
|
|
|
+ .eq(User::getTelphone,EncryptHandler.encrypt(loginBody.getAccount()))
|
|
|
+ .or()
|
|
|
+ .eq(User::getIdCard,EncryptHandler.encrypt(loginBody.getAccount())));
|
|
|
+ User user = iUserService.getOne(queryWrapper);
|
|
|
+ if (ObjectUtils.isNull(user)){
|
|
|
+ throw new CustomException("登入信息有误,请检查账号或者密码!");
|
|
|
+ }
|
|
|
+ String password = null;
|
|
|
+ if(loginBody.getPassword().length()>20){
|
|
|
+ String rsaPrivate = null;
|
|
|
+ try {
|
|
|
+ InputStream certStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("config/pri.key");
|
|
|
+ rsaPrivate = AES.getStringByInputStream_1(certStream);
|
|
|
+ certStream.close();
|
|
|
+ password = AES.decrypt(loginBody.getPassword(),rsaPrivate);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ password = loginBody.getPassword();
|
|
|
+ }
|
|
|
+ if (!SecurityUtils.matchesPassword(password,user.getPassword()))
|
|
|
+ {
|
|
|
+ throw new CustomException("登入信息有误,请检查账号或者密码!");
|
|
|
+ }
|
|
|
+ //校验公众号openId
|
|
|
+ if (StringUtils.isNotBlank(user.getGzhOpenId()) && !user.getGzhOpenId().equals(openId)){
|
|
|
+ throw new CustomException("该账号已绑定微信,请使用绑定微信扫码登入");
|
|
|
+ }
|
|
|
+ //登入和补充公众号openId
|
|
|
+ user.setGzhOpenId(openId);
|
|
|
+ iUserService.updateById(user);
|
|
|
+ ClientLoginUser loginUser = new ClientLoginUser();
|
|
|
+ loginUser.setUser(user);
|
|
|
+ map.put(Constants.TOKEN, wxTokenService.createToken(loginUser));
|
|
|
+ map.put("gzhStatus", "1");
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ //校验公众号openId
|
|
|
+ User user = iUserService.getUserByGzhOpenId(openId);
|
|
|
+ if (ObjectUtils.isNull(user)){
|
|
|
+ map.put("gzhStatus", "0");
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ ClientLoginUser loginUser = new ClientLoginUser();
|
|
|
+ loginUser.setUser(user);
|
|
|
+ map.put(Constants.TOKEN, wxTokenService.createToken(loginUser));
|
|
|
+ map.put("gzhStatus", "1");
|
|
|
+ return map;
|
|
|
+ }
|
|
|
}
|