登录x3
This commit is contained in:
parent
e91b127731
commit
ff3e0de135
|
@ -1,5 +1,6 @@
|
||||||
package com.dengqn.igps2xingzhe.controller;
|
package com.dengqn.igps2xingzhe.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.io.IoUtil;
|
import cn.hutool.core.io.IoUtil;
|
||||||
import cn.hutool.crypto.KeyUtil;
|
import cn.hutool.crypto.KeyUtil;
|
||||||
import cn.hutool.crypto.SecureUtil;
|
import cn.hutool.crypto.SecureUtil;
|
||||||
|
@ -7,18 +8,22 @@ import cn.hutool.crypto.asymmetric.AsymmetricAlgorithm;
|
||||||
import cn.hutool.crypto.asymmetric.KeyType;
|
import cn.hutool.crypto.asymmetric.KeyType;
|
||||||
import cn.hutool.crypto.asymmetric.RSA;
|
import cn.hutool.crypto.asymmetric.RSA;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import com.dengqn.igps2xingzhe.config.IGPSport;
|
||||||
import com.dengqn.igps2xingzhe.config.XingZhe;
|
import com.dengqn.igps2xingzhe.config.XingZhe;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.catalina.security.SecurityUtil;
|
import org.apache.catalina.security.SecurityUtil;
|
||||||
import org.apache.hc.client5.http.classic.HttpClient;
|
import org.apache.hc.client5.http.classic.HttpClient;
|
||||||
import org.apache.hc.client5.http.cookie.Cookie;
|
import org.apache.hc.client5.http.cookie.Cookie;
|
||||||
import org.apache.hc.client5.http.cookie.CookieStore;
|
import org.apache.hc.client5.http.cookie.CookieStore;
|
||||||
|
import org.apache.hc.client5.http.entity.UrlEncodedFormEntity;
|
||||||
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
|
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
|
||||||
import org.apache.hc.core5.http.ContentType;
|
import org.apache.hc.core5.http.ContentType;
|
||||||
|
import org.apache.hc.core5.http.HttpEntity;
|
||||||
import org.apache.hc.core5.http.HttpResponse;
|
import org.apache.hc.core5.http.HttpResponse;
|
||||||
import org.apache.hc.core5.http.io.entity.BasicHttpEntity;
|
import org.apache.hc.core5.http.io.entity.BasicHttpEntity;
|
||||||
import org.apache.hc.core5.http.io.support.ClassicRequestBuilder;
|
import org.apache.hc.core5.http.io.support.ClassicRequestBuilder;
|
||||||
import org.apache.hc.core5.http.message.BasicHttpResponse;
|
import org.apache.hc.core5.http.message.BasicHttpResponse;
|
||||||
|
import org.apache.hc.core5.http.message.BasicNameValuePair;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
@ -56,15 +61,39 @@ public class Trigger {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private XingZhe xingZhe;
|
private XingZhe xingZhe;
|
||||||
|
@Autowired
|
||||||
|
private IGPSport igpSport;
|
||||||
|
|
||||||
@GetMapping("/sync/igps2xingzhe")
|
@GetMapping("/sync/igps2xingzhe")
|
||||||
public ResponseEntity<String> onSyncIGPS2XingZhe() throws IOException, NoSuchAlgorithmException, InvalidKeySpecException {
|
public ResponseEntity<String> onSyncIGPS2XingZhe() throws IOException, NoSuchAlgorithmException, InvalidKeySpecException {
|
||||||
|
// 1. 登录行者
|
||||||
|
// xingzheLogin();
|
||||||
|
// 2. 登录igps
|
||||||
|
igpsLogin();
|
||||||
|
|
||||||
|
return ResponseEntity.ok("ok");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void igpsLogin() throws IOException {
|
||||||
|
// 3. igps 登录 formData
|
||||||
|
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(CollUtil.toList(
|
||||||
|
new BasicNameValuePair("username", igpSport.getUsername()),
|
||||||
|
new BasicNameValuePair("password", igpSport.getPassword())
|
||||||
|
));
|
||||||
|
|
||||||
|
ClassicRequestBuilder igpsLoginReq = ClassicRequestBuilder
|
||||||
|
.post("https://my.igpsport.com/Auth/Login")
|
||||||
|
.setEntity(formEntity);
|
||||||
|
|
||||||
|
CloseableHttpResponse response = (CloseableHttpResponse) httpClient.execute(igpsLoginReq.build());
|
||||||
|
log.info("igps login: {}", IoUtil.read(response.getEntity().getContent()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void xingzheLogin() throws IOException {
|
||||||
// 1、获取行者平台的cookie
|
// 1、获取行者平台的cookie
|
||||||
HttpResponse executed = httpClient.execute(ClassicRequestBuilder.get("https://www.imxingzhe.com/user/login").build());
|
HttpResponse executed = httpClient.execute(ClassicRequestBuilder.get("https://www.imxingzhe.com/user/login").build());
|
||||||
System.out.println(executed.getCode());
|
System.out.println(executed.getCode());
|
||||||
// 2、计算加密后的密码参数
|
// 2、计算加密后的密码参数
|
||||||
|
|
||||||
RSA rsa = new RSA(AsymmetricAlgorithm.RSA_ECB_PKCS1.getValue(), null, xingZhe.getPubKey());
|
RSA rsa = new RSA(AsymmetricAlgorithm.RSA_ECB_PKCS1.getValue(), null, xingZhe.getPubKey());
|
||||||
String rd = cookieStore.getCookies()
|
String rd = cookieStore.getCookies()
|
||||||
.stream().filter(a -> a.getName().equals("rd")).findFirst()
|
.stream().filter(a -> a.getName().equals("rd")).findFirst()
|
||||||
|
@ -81,10 +110,7 @@ public class Trigger {
|
||||||
.setEntity(JSONUtil.toJsonPrettyStr(loginData), ContentType.APPLICATION_JSON)
|
.setEntity(JSONUtil.toJsonPrettyStr(loginData), ContentType.APPLICATION_JSON)
|
||||||
.build());
|
.build());
|
||||||
log.info("xingzhe login: {}", IoUtil.read(response.getEntity().getContent()));
|
log.info("xingzhe login: {}", IoUtil.read(response.getEntity().getContent()));
|
||||||
|
|
||||||
return ResponseEntity.ok("ok");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue