From 9e2a59e6a38d969c2c6d50897209e81b4520cba8 Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期五, 03 七月 2020 09:13:37 +0800
Subject: [PATCH] 优化微信小程序自登录问题
---
service-front/src/main/java/com/java110/front/smo/wxLogin/impl/WxLoginSMOImpl.java | 73 ++++++++----------------------------
1 files changed, 16 insertions(+), 57 deletions(-)
diff --git a/service-front/src/main/java/com/java110/front/smo/wxLogin/impl/WxLoginSMOImpl.java b/service-front/src/main/java/com/java110/front/smo/wxLogin/impl/WxLoginSMOImpl.java
index 2985aec..6e10bf8 100644
--- a/service-front/src/main/java/com/java110/front/smo/wxLogin/impl/WxLoginSMOImpl.java
+++ b/service-front/src/main/java/com/java110/front/smo/wxLogin/impl/WxLoginSMOImpl.java
@@ -1,26 +1,28 @@
package com.java110.front.smo.wxLogin.impl;
-import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
+import com.java110.core.context.IPageData;
+import com.java110.core.factory.AuthenticationFactory;
+import com.java110.core.factory.CallApiServiceFactory;
+import com.java110.dto.owner.OwnerAppUserDto;
import com.java110.front.properties.WechatAuthProperties;
import com.java110.front.smo.AppAbstractComponentSMO;
import com.java110.front.smo.wxLogin.IWxLoginSMO;
-import com.java110.core.context.IPageData;
-import com.java110.core.factory.AuthenticationFactory;
-import com.java110.utils.cache.MappingCache;
-import com.java110.utils.constant.*;
+import com.java110.utils.constant.CommonConstant;
+import com.java110.utils.constant.ServiceCodeConstant;
import com.java110.utils.exception.SMOException;
import com.java110.utils.util.Assert;
+import com.java110.utils.util.BeanConvertUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
/**
@@ -82,64 +84,21 @@
String openId = responseObj.getString("openid");
String sessionKey = responseObj.getString("session_key");
- responseEntity = super.getUserInfoByOpenId(pd, restTemplate, openId);
-
- logger.debug("鏌ヨ鐢ㄦ埛淇℃伅杩斿洖鎶ユ枃锛�" + responseEntity);
- if (responseEntity.getStatusCode() != HttpStatus.OK) {
- throw new IllegalArgumentException("鏍圭粷openId 鏌ヨ鐢ㄦ埛淇℃伅寮傚父" + openId + ", " + responseEntity.getBody());
- }
-
- JSONObject userResult = JSONObject.parseObject(responseEntity.getBody());
- int total = userResult.getIntValue("total");
+ //responseEntity = super.getUserInfoByOpenId(pd, restTemplate, openId);
+ OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
+ ownerAppUserDto.setOpenId(openId);
+ List<OwnerAppUserDto> ownerAppUserDtos = CallApiServiceFactory.getForApis(pd, ownerAppUserDto, ServiceCodeConstant.LIST_APPUSERBINDINGOWNERS, OwnerAppUserDto.class);
JSONObject paramOut = new JSONObject();
- JSONObject userInfo = paramIn.getJSONObject("userInfo");
-
- if (total == 0) {
- //淇濆瓨鐢ㄦ埛淇℃伅
- /*JSONObject registerInfo = new JSONObject();
-
- //璁剧疆榛樿瀵嗙爜
- String userDefaultPassword = MappingCache.getValue(MappingConstant.KEY_STAFF_DEFAULT_PASSWORD);
- Assert.hasLength(userDefaultPassword, "鏄犲皠琛ㄤ腑鏈缃憳宸ラ粯璁ゅ瘑鐮侊紝璇锋鏌�" + MappingConstant.KEY_STAFF_DEFAULT_PASSWORD);
- userDefaultPassword = AuthenticationFactory.passwdMd5(userDefaultPassword);
-
- registerInfo.put("userId", "-1");
- registerInfo.put("email", "");
- registerInfo.put("address", userInfo.getString("country") + userInfo.getString("province") + userInfo.getString("city"));
- registerInfo.put("locationCd", "001");
- registerInfo.put("age", "1");
- registerInfo.put("sex", "2".equals(userInfo.getString("gender")) ? "1" : "0");
- registerInfo.put("tel", "-1");
- registerInfo.put("level_cd", "1");
- registerInfo.put("name", userInfo.getString("nickName"));
- registerInfo.put("password", userDefaultPassword);
- JSONArray userAttr = new JSONArray();
- JSONObject userAttrObj = new JSONObject();
- userAttrObj.put("attrId", "-1");
- userAttrObj.put("specCd", "100201911001");
- userAttrObj.put("value", openId);
- userAttr.add(userAttrObj);
- registerInfo.put("businessUserAttr", userAttr);
- responseEntity = this.callCenterService(restTemplate, pd, registerInfo.toJSONString(), ServiceConstant.SERVICE_API_URL + "/api/user.service.register", HttpMethod.POST);
- if (responseEntity.getStatusCode() != HttpStatus.OK) {
- throw new IllegalArgumentException("淇濆瓨鐢ㄦ埛淇℃伅澶辫触");
- }
- responseEntity = super.getUserInfoByOpenId(pd, restTemplate, openId);
-
- logger.debug("鏌ヨ鐢ㄦ埛淇℃伅杩斿洖鎶ユ枃锛�" + responseEntity);
- if (responseEntity.getStatusCode() != HttpStatus.OK) {
- throw new IllegalArgumentException("鏍圭粷openId 鏌ヨ鐢ㄦ埛淇℃伅寮傚父" + openId);
- }
- userResult = JSONObject.parseObject(responseEntity.getBody());*/
+ if (ownerAppUserDtos == null || ownerAppUserDtos.size() < 1) {
+ //灏唎penId鏀惧埌redis 缂撳瓨锛岀粰鍓嶆涓嬪彂涓存椂绁ㄦ嵁
paramOut.put("openId", openId);
paramOut.put("msg", "杩樻病鏈夋敞鍐岃鍏堟敞鍐�");
responseEntity = new ResponseEntity<String>(paramOut.toJSONString(), HttpStatus.UNAUTHORIZED);
return responseEntity;
}
-
- JSONObject realUserInfo = userResult.getJSONArray("users").getJSONObject(0);
- userInfo.putAll(realUserInfo);
+ JSONObject userInfo = paramIn.getJSONObject("userInfo");
+ userInfo.putAll(BeanConvertUtil.beanCovertMap(ownerAppUserDtos.get(0)));
userInfo.put("password", "");
try {
--
Gitblit v1.8.0