|
@ -1,5 +1,7 @@ |
|
|
package com.epmet.service.impl; |
|
|
package com.epmet.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.RandomUtil; |
|
|
|
|
|
import cn.hutool.crypto.SecureUtil; |
|
|
import com.alibaba.fastjson.JSON; |
|
|
import com.alibaba.fastjson.JSON; |
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import com.epmet.auth.constants.AuthOperationConstants; |
|
|
import com.epmet.auth.constants.AuthOperationConstants; |
|
@ -46,6 +48,7 @@ import org.springframework.http.MediaType; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.util.CollectionUtils; |
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
import java.io.IOException; |
|
|
import java.io.IOException; |
|
|
import java.nio.charset.StandardCharsets; |
|
|
import java.nio.charset.StandardCharsets; |
|
|
import java.util.HashMap; |
|
|
import java.util.HashMap; |
|
@ -83,7 +86,7 @@ public class SsoServiceImpl implements SsoService { |
|
|
@Autowired |
|
|
@Autowired |
|
|
private CpUserDetailRedis cpUserDetailRedis; |
|
|
private CpUserDetailRedis cpUserDetailRedis; |
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Resource |
|
|
private EpmetUserFeignClient epmetUserFeignClient; |
|
|
private EpmetUserFeignClient epmetUserFeignClient; |
|
|
|
|
|
|
|
|
@Value("${epmet.third.urlPrefix}") |
|
|
@Value("${epmet.third.urlPrefix}") |
|
@ -220,13 +223,15 @@ public class SsoServiceImpl implements SsoService { |
|
|
if (result.getString("code").equals("200")) { |
|
|
if (result.getString("code").equals("200")) { |
|
|
String ticket = result.getString("data"); |
|
|
String ticket = result.getString("data"); |
|
|
String timestamp = String.valueOf(System.currentTimeMillis()); |
|
|
String timestamp = String.valueOf(System.currentTimeMillis()); |
|
|
|
|
|
String nonce = RandomUtil.randomString(18); |
|
|
httpPost = new HttpPost(SsoConstant.USER_INFO_URL); |
|
|
httpPost = new HttpPost(SsoConstant.USER_INFO_URL); |
|
|
infoJson = new JSONObject(); |
|
|
infoJson = new JSONObject(); |
|
|
infoJson.put("loginId", ticket); |
|
|
infoJson.put("loginId", ticket); |
|
|
infoJson.put("timestamp", timestamp); |
|
|
infoJson.put("timestamp", timestamp); |
|
|
infoJson.put("nonce", ""); |
|
|
infoJson.put("nonce", nonce); |
|
|
infoJson.put("sign", ""); |
|
|
infoJson.put("sign", Md5Params(ticket, timestamp, nonce)); |
|
|
stringEntity = new StringEntity(infoJson.toString(), "UTF-8"); |
|
|
String params = DigestUtils.md5Hex(infoJson.toString().getBytes(StandardCharsets.UTF_8)); |
|
|
|
|
|
stringEntity = new StringEntity(params, "UTF-8"); |
|
|
stringEntity.setContentEncoding("UTF-8"); |
|
|
stringEntity.setContentEncoding("UTF-8"); |
|
|
stringEntity.setContentType(MediaType.APPLICATION_JSON_VALUE); |
|
|
stringEntity.setContentType(MediaType.APPLICATION_JSON_VALUE); |
|
|
httpPost.setEntity(stringEntity); |
|
|
httpPost.setEntity(stringEntity); |
|
@ -302,6 +307,24 @@ public class SsoServiceImpl implements SsoService { |
|
|
return userTokenResultDTO; |
|
|
return userTokenResultDTO; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 签名 |
|
|
|
|
|
* |
|
|
|
|
|
* @param loginId |
|
|
|
|
|
* @return |
|
|
|
|
|
*/ |
|
|
|
|
|
private String Md5Params(String loginId, String timestamp, String nonce) { |
|
|
|
|
|
String prefix = "=${"; |
|
|
|
|
|
String suffix = "}&"; |
|
|
|
|
|
StringBuilder builder = new StringBuilder(); |
|
|
|
|
|
builder.append("loginId").append(prefix).append(loginId).append(suffix); |
|
|
|
|
|
builder.append("nonce").append(prefix).append(nonce).append(suffix); |
|
|
|
|
|
builder.append("timestamp").append(prefix).append(timestamp).append(suffix); |
|
|
|
|
|
builder.append("key").append("={").append(SsoConstant.SECRET_KEY).append("}"); |
|
|
|
|
|
return SecureUtil.md5(builder.toString()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @Description token放缓存 |
|
|
* @Description token放缓存 |
|
|
* @Param formDTO |
|
|
* @Param formDTO |
|
@ -657,24 +680,24 @@ public class SsoServiceImpl implements SsoService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
// public static void main(String[] args) {
|
|
|
String url = "https://epmet-ext9.elinkservice.cn/platform/unifiedAuth/loginCheck"; |
|
|
// String url = "https://epmet-ext9.elinkservice.cn/platform/unifiedAuth/loginCheck";
|
|
|
String platformToken = "1348803062424166401_dd08e23b0d524879a5c67e7f2ffd1468"; |
|
|
// String platformToken = "1348803062424166401_dd08e23b0d524879a5c67e7f2ffd1468";
|
|
|
String appId = "7a5aec009ba4eba8e254ee64fe3775e1"; |
|
|
// String appId = "7a5aec009ba4eba8e254ee64fe3775e1";
|
|
|
String appKey = "14faef9af508d1c253b720ea5a43f9de"; |
|
|
// String appKey = "14faef9af508d1c253b720ea5a43f9de";
|
|
|
String appSecret = "38e7c2604c8dd33c445705d25eebbfc12a2f7ed8a87111e9e10a40312d3a1595"; |
|
|
// String appSecret = "38e7c2604c8dd33c445705d25eebbfc12a2f7ed8a87111e9e10a40312d3a1595";
|
|
|
long ts = System.currentTimeMillis(); |
|
|
// long ts = System.currentTimeMillis();
|
|
|
String message = appId + appKey + appSecret + ts; |
|
|
// String message = appId + appKey + appSecret + ts;
|
|
|
String accessToken = DigestUtils.md5Hex(message.getBytes(StandardCharsets.UTF_8)); |
|
|
// String accessToken = DigestUtils.md5Hex(message.getBytes(StandardCharsets.UTF_8));
|
|
|
//ThirdPlatformEnum platformEnum = ThirdPlatformEnum.getEnum("pyld");
|
|
|
// //ThirdPlatformEnum platformEnum = ThirdPlatformEnum.getEnum("pyld");
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
// JSONObject jsonObject = new JSONObject();
|
|
|
jsonObject.put("platformToken", platformToken); |
|
|
// jsonObject.put("platformToken", platformToken);
|
|
|
|
|
|
//
|
|
|
Map<String, Object> headerMap = new HashMap<>(4); |
|
|
// Map<String, Object> headerMap = new HashMap<>(4);
|
|
|
headerMap.put("AppKey", appKey); |
|
|
// headerMap.put("AppKey", appKey);
|
|
|
headerMap.put("Timestamp", ts); |
|
|
// headerMap.put("Timestamp", ts);
|
|
|
headerMap.put("AccessToken", accessToken); |
|
|
// headerMap.put("AccessToken", accessToken);
|
|
|
Result<String> stringResult = HttpClientManager.getInstance().sendPost(url, url.startsWith("https://"), jsonObject.toJSONString(), headerMap); |
|
|
// Result<String> stringResult = HttpClientManager.getInstance().sendPost(url, url.startsWith("https://"), jsonObject.toJSONString(), headerMap);
|
|
|
System.out.println(stringResult); |
|
|
// System.out.println(stringResult);
|
|
|
} |
|
|
// }
|
|
|
} |
|
|
} |
|
|