|
|
@@ -5,7 +5,9 @@ import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import com.jfirer.baseutil.encrypt.Md5Util;
|
|
|
import com.lc.ibps.api.org.constant.PartyRelType;
|
|
|
+import com.lc.ibps.cloud.oauth.server.util.CustomerSingle;
|
|
|
import com.lc.ibps.cloud.oauth.server.util.IpUtil;
|
|
|
import com.lc.ibps.cloud.util.AESUtil;
|
|
|
import com.lc.ibps.org.auth.persistence.entity.LoginLogPo;
|
|
|
@@ -17,6 +19,8 @@ import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
import org.apache.http.client.methods.HttpGet;
|
|
|
import org.apache.http.client.methods.HttpPost;
|
|
|
+import org.apache.http.conn.ssl.NoopHostnameVerifier;
|
|
|
+import org.apache.http.entity.StringEntity;
|
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
import org.apache.http.impl.client.HttpClients;
|
|
|
import org.apache.http.message.BasicNameValuePair;
|
|
|
@@ -105,6 +109,14 @@ import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
@Api(tags = "用户中心", value = "用户")
|
|
|
@Service
|
|
|
public class UserProvider extends BaseProvider implements IUserService {
|
|
|
+
|
|
|
+ private final static String APP_KEY = "9dfce6a89b275c1934180a7a3173b5cf5f1a8df536c3aa983d";
|
|
|
+
|
|
|
+ private final static String SECRET_KEY = "f9993caf72a475731925a9234daa584ad1e235fab9f4975c35";
|
|
|
+
|
|
|
+ private final static String TOKEN ="eb60e66ad1414a54b27ae3d899f43871";
|
|
|
+
|
|
|
+ private final static String ORG_CODE = "ZLYY";
|
|
|
|
|
|
@Autowired
|
|
|
private ITokenService tokenService;
|
|
|
@@ -126,25 +138,46 @@ public class UserProvider extends BaseProvider implements IUserService {
|
|
|
String requestId = loginVo.getRequestId();
|
|
|
String username = loginVo.getUsername();
|
|
|
String captcha = loginVo.getCaptcha();
|
|
|
-
|
|
|
- // 验证码校验
|
|
|
- captcha(requestId, username, captcha);
|
|
|
-
|
|
|
- // 用户登录
|
|
|
- try{
|
|
|
- String password = AESUtil.decryptUser(loginVo.getPassword());
|
|
|
- loginVo.setPassword(password);
|
|
|
- }catch (Exception e){
|
|
|
- //
|
|
|
- }
|
|
|
- PartyUserPo user = login0(loginVo);
|
|
|
- String statistic = getStatistic(user);
|
|
|
- result.addVariable("statistic", statistic);
|
|
|
-
|
|
|
+ String key = loginVo.getClientKey();
|
|
|
+ String orgCode = loginVo.getOrgCode();
|
|
|
+ String voToken = loginVo.getToken();
|
|
|
// 生成登录状态
|
|
|
- String state = uuid();
|
|
|
+ String state = "";
|
|
|
+ PartyUserPo user = new PartyUserPo();
|
|
|
+ if(BeanUtils.isNotEmpty(key)){//是否是第三方接入
|
|
|
+ int tokenStatus = 1 ;
|
|
|
+ tokenStatus = getWeChatAccessToken(key,orgCode, voToken,APP_KEY,SECRET_KEY); //验证对方提供的toke是来自对方
|
|
|
+ //tokenStatus = getWeChatAccessToken(key,ORG_CODE, TOKEN,APP_KEY,SECRET_KEY);
|
|
|
+ if(tokenStatus==0){ //云守护验证成功的状态码是0,其他客户依据实际情况判定
|
|
|
+ //跳过密码验证,直接依据工号拿到用户信息生成登入状态
|
|
|
+ user = loginSingle(loginVo);
|
|
|
+ String statistic = getStatistic(user);
|
|
|
+ result.addVariable("statistic", statistic);
|
|
|
+ //2选1即可,用对方的需要注意长度
|
|
|
+ //state = TOKEN; //用对方的token鉴权
|
|
|
+ state = uuid(); //我们自己鉴权
|
|
|
+ }else{
|
|
|
+ state = ""; //错误的token不返回状态让鉴权失效
|
|
|
+ result.setState(StateEnum.ILLEGAL_TOKEN_VERIFICATION_LOSE.getCode());
|
|
|
+ throw new ExpiredAccountException(StateEnum.ILLEGAL_TOKEN_VERIFICATION_LOSE.getText());
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ // 验证码校验
|
|
|
+ captcha(requestId, username, captcha);
|
|
|
+ // 用户登录
|
|
|
+ try{
|
|
|
+ String password = AESUtil.decryptUser(loginVo.getPassword());
|
|
|
+ loginVo.setPassword(password);
|
|
|
+ }catch (Exception e){
|
|
|
+ //
|
|
|
+ }
|
|
|
+ user = login0(loginVo);
|
|
|
+ String statistic = getStatistic(user);
|
|
|
+ result.addVariable("statistic", statistic);
|
|
|
+ state = uuid();
|
|
|
+ }
|
|
|
+
|
|
|
result.setData(state);
|
|
|
-
|
|
|
// 存入redis
|
|
|
RedisUtil.redisTemplateString.opsForValue().set(appConfig.getRedisKey(RedisKey.LOGIN_STATE, state),
|
|
|
username, tokenConfig.getAcexpires(), TimeUnit.SECONDS);
|
|
|
@@ -239,6 +272,64 @@ public class UserProvider extends BaseProvider implements IUserService {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 深圳肿瘤验证token
|
|
|
+ * @param orgCode
|
|
|
+ * @param token
|
|
|
+ * @param appKey
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public int getWeChatAccessToken(String key,String orgCode, String token, String appKey, String secretKey) {
|
|
|
+ // 构造请求体(JSON 格式)
|
|
|
+ JSONObject requestBody = new JSONObject();
|
|
|
+ String url = "";
|
|
|
+ String sign = "";
|
|
|
+ if(CustomerSingle.ZLYY.getCode().equals(key)){
|
|
|
+ url = CustomerSingle.ZLYY.getIp()+"/uusafe/mos/thirdaccess/rest/user/v1/checkToken";
|
|
|
+ sign = Md5Util.md5Str(appKey + orgCode + token + secretKey);
|
|
|
+ requestBody.put("orgCode", orgCode);
|
|
|
+ requestBody.put("token", token);
|
|
|
+ requestBody.put("appKey", appKey);
|
|
|
+ requestBody.put("sign", sign);
|
|
|
+ }
|
|
|
+ // 创建 Apache HttpClient
|
|
|
+ try (CloseableHttpClient client = HttpClients.createDefault()) {
|
|
|
+ //直接跳过ssl验证,仅限测试用
|
|
|
+ //try (CloseableHttpClient client = HttpClients.custom().setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).build()){
|
|
|
+ HttpPost post = new HttpPost(url);
|
|
|
+ // 设置请求头(JSON 格式)
|
|
|
+ post.setHeader("Content-Type", "application/json");
|
|
|
+ HttpEntity requestEntity = new StringEntity(requestBody.toString(), "UTF-8");
|
|
|
+ post.setEntity(requestEntity);
|
|
|
+ // 发送请求
|
|
|
+ try (CloseableHttpResponse resp = client.execute(post)) {
|
|
|
+ if (resp.getStatusLine().getStatusCode() == HttpStatus.OK.value()) {
|
|
|
+ HttpEntity entity = resp.getEntity();
|
|
|
+ String responseStr = EntityUtils.toString(entity, "UTF-8");
|
|
|
+ JSONObject res = JSONObject.fromObject(responseStr);
|
|
|
+ // 解析响应
|
|
|
+ if (res.has("code") && res.getInt("code") == 0) {
|
|
|
+ logger.warn("token验证完成,正确的token,状态码:" + res.getInt("code"));
|
|
|
+ return res.getInt("code"); // 返回状态码
|
|
|
+ //return 0;
|
|
|
+ } else {
|
|
|
+ //return 0;
|
|
|
+ logger.warn("token验证完成,验证结果,错误的token");
|
|
|
+ throw new RuntimeException("Token验证失败:" + res.getString("msg"));
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ logger.warn("token验证时无返回值");
|
|
|
+ throw new RuntimeException("HTTP请求失败,状态码: " + resp.getStatusLine().getStatusCode());
|
|
|
+ }
|
|
|
+ }catch (IOException e) {
|
|
|
+ e.printStackTrace(); // 打印完整堆栈
|
|
|
+ logger.warn("请求异常: " + e.getClass().getName() + ": " + e.getMessage());
|
|
|
+ throw new RuntimeException("请求异常: " + e.getClass().getName() + ": " + e.getMessage());
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException("请求异常: " + e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
/**
|
|
|
* 验证码校验
|
|
|
*
|