|
|
@@ -0,0 +1,183 @@
|
|
|
+//package com.xunmei.auth.service;
|
|
|
+//
|
|
|
+//import cn.hutool.core.util.ObjectUtil;
|
|
|
+//import cn.hutool.json.JSONObject;
|
|
|
+//import com.xunmei.common.core.utils.StringUtils;
|
|
|
+//import io.netty.util.internal.StringUtil;
|
|
|
+//import lombok.extern.flogger.Flogger;
|
|
|
+//import org.apache.http.HttpEntity;
|
|
|
+//import org.apache.http.StatusLine;
|
|
|
+//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.entity.StringEntity;
|
|
|
+//import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
+//import org.apache.http.impl.client.HttpClients;
|
|
|
+//import org.apache.http.message.BasicHeader;
|
|
|
+//import org.apache.http.protocol.HTTP;
|
|
|
+//import org.apache.http.util.EntityUtils;
|
|
|
+//import org.slf4j.ILoggerFactory;
|
|
|
+//import org.springframework.beans.factory.annotation.Value;
|
|
|
+//import org.springframework.stereotype.Component;
|
|
|
+//
|
|
|
+//import java.io.IOException;
|
|
|
+//import java.nio.charset.StandardCharsets;
|
|
|
+//import java.util.ArrayList;
|
|
|
+//import java.util.List;
|
|
|
+//
|
|
|
+//import com.union.api.TUnionTransInfo;
|
|
|
+//import com.union.api.UnionEsscAPI;
|
|
|
+//
|
|
|
+//@Component
|
|
|
+//public class FJNXLoginService {
|
|
|
+// @Value("${fjnx.host}")
|
|
|
+// private String host;
|
|
|
+//
|
|
|
+// @Value("${fjnx.systemCode}")
|
|
|
+// private String systemCode;
|
|
|
+//
|
|
|
+// @Value("${fjnx.passIp}")
|
|
|
+// private String passIp;
|
|
|
+//
|
|
|
+// @Value("${fjnx.passPort}")
|
|
|
+// private String passPort;
|
|
|
+//
|
|
|
+// @Value("${fjnx.appCode}")
|
|
|
+// private String appCode;
|
|
|
+//
|
|
|
+// @Value("${fjnx.secretName}")
|
|
|
+// private String secretName;
|
|
|
+//
|
|
|
+// public String logingByPassword(String username, String password) {
|
|
|
+// CloseableHttpClient client = null;
|
|
|
+// try {
|
|
|
+// List<String> ipList = new ArrayList<>();
|
|
|
+// List<Integer> portList = new ArrayList<>();
|
|
|
+// UnionEsscAPI shortApi = null;
|
|
|
+// TUnionTransINfo transInfo = null;
|
|
|
+// ipList.add(0, passIp);
|
|
|
+// portList.add(0, Integer.parseInt(passPort));
|
|
|
+// shortApi = new UnionEsscAPI(ipList, portList, 5, appCode, appCode, "0");
|
|
|
+// String pass = StringUtil.toHexString(password.getBytes());
|
|
|
+// transInfo = shortApi.unionAPIServiceE160(1, secretName, "", 0, 1, pass, "", 1);
|
|
|
+// if (ObjectUtil.isNull(transInfo)) {
|
|
|
+// return null;
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (ObjectUtil.notEqual(transInfo.getResponseCode(), 0) || ObjectUtil.notEqual(transInfo.getIsSucess(), 1)) {
|
|
|
+// logger.error("密码加密失败!" + transInfo.getResponseRemark());
|
|
|
+// return null;
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (ObjectUtil.isNull(transInfo.getReturnBode())) {
|
|
|
+// logger.error("密码加密失败,数据为空!");
|
|
|
+// return null;
|
|
|
+// }
|
|
|
+//
|
|
|
+// String url = host + "yusp-group/api/login?systemCode=" + systemCode;
|
|
|
+// logger.info(url);
|
|
|
+//
|
|
|
+// HttpPost post = new HttpPost(url);
|
|
|
+// client = HttpClients.createDefault();
|
|
|
+// JSONObject object = new JSONObject();
|
|
|
+// object.accumulate("loginName", username);
|
|
|
+// object.accumulate("pass", transInfo.getReturnBody().getData());
|
|
|
+// object.accumulate("type", 1);
|
|
|
+// object.accumulate("systemCode", 1);
|
|
|
+// object.accumulate("passwordType", 1);
|
|
|
+// StringEntity s = new StringEntity(object.toString(), "utf-8");
|
|
|
+// s.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
|
|
|
+// post.setEntity(s);
|
|
|
+// post.setHeader("Content-type", "application/json");
|
|
|
+// CloseableHttpResponse response = client.execute(post);
|
|
|
+// HttpEntity entity = response.getEntity();
|
|
|
+// if (ObjectUtil.isNull(entity)) {
|
|
|
+// logger.error("登录失败,返回数据为空!");
|
|
|
+// return null;
|
|
|
+// }
|
|
|
+//
|
|
|
+// String body = EntityUtils.toString(entity, "utf-8");
|
|
|
+// logger.warn("登录body返回:" + body);
|
|
|
+// JSONObject jsonObject = new JSONObject(body);
|
|
|
+// String code = jsonObject.getStr("code");
|
|
|
+//
|
|
|
+// if (StringUtils.isNotNull(code) && ObjectUtil.equal("0", code)) {
|
|
|
+// String data = jsonObject.getStr("data");
|
|
|
+// JSONObject jsonObject1 = new JSONObject(data);
|
|
|
+// String userStatus = jsonObject1.getStr("userStatus");
|
|
|
+// String tokenThird = jsonObject1.getStr("token");
|
|
|
+// logger.info(tokenThird);
|
|
|
+// EntityUtils.consume(entity);
|
|
|
+// response.close();
|
|
|
+// return tokenThird;
|
|
|
+// } else {
|
|
|
+// logger.error("登录失败," + jsonObject.getStr("message"));
|
|
|
+// return null;
|
|
|
+// }
|
|
|
+// } catch (Exception e) {
|
|
|
+// logger.error(e.getMessage());
|
|
|
+// return null;
|
|
|
+// } finally {
|
|
|
+// if (client != null) {
|
|
|
+// try {
|
|
|
+// client.close();
|
|
|
+// } catch (IOException e) {
|
|
|
+// logger.error(e.getMessage());
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+//
|
|
|
+// public String loginByToken(String token) throws Exception {
|
|
|
+// String userName = "";
|
|
|
+// CloseableHttpClient client = null;
|
|
|
+//
|
|
|
+// try {
|
|
|
+// client = HttpClients.createDefault();
|
|
|
+// HttpGet get = new HttpGet(host + "yusp-group/api/session?systemCode=" + systemCode);
|
|
|
+// get.setHeader("Content-Type", "application/json");
|
|
|
+// get.setHeader("Authorization", "Bearer " + token);
|
|
|
+//
|
|
|
+// CloseableHttpResponse response = client.execute(get);
|
|
|
+// HttpEntity entity = response.getEntity();
|
|
|
+// StatusLine status = response.getStatusLine();
|
|
|
+// int statusCode = status.getStatusCode();
|
|
|
+// if (statusCode == 200) {
|
|
|
+// if (entity != null) {
|
|
|
+// String body = EntityUtils.toString(entity, "utf-8");
|
|
|
+// logger.warn(body);
|
|
|
+// JSONObject jsonObject = new JSONObject(body);
|
|
|
+// String code = jsonObject.getStr("code");
|
|
|
+// if (StringUtils.isNotNull(code) && "0".equals(code)) {
|
|
|
+// String data = jsonObject.getStr("data");
|
|
|
+// JSONObject jsonObject1 = new JSONObject();
|
|
|
+// String userStatus = (String) jsonObject1.get("userStatus");
|
|
|
+// String loginName = (String) jsonObject1.get("loginName");
|
|
|
+// if (ObjectUtil.notEqual("0", userStatus)) {
|
|
|
+// userName = loginName;
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// logger.warn("服务异常");
|
|
|
+// }
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// if (statusCode == 401) {
|
|
|
+// logger.warn("无效的token");
|
|
|
+//
|
|
|
+// } else {
|
|
|
+// logger.warn("调用单点登录失败");
|
|
|
+// }
|
|
|
+// }
|
|
|
+// } catch (Exception e) {
|
|
|
+// logger.error("token登录错误:", e);
|
|
|
+// } finally {
|
|
|
+// if (client != null) {
|
|
|
+// client.close();
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// return userName;
|
|
|
+// }
|
|
|
+//}
|