This commit is contained in:
dengqn 2024-07-22 17:42:31 +08:00
parent e91b127731
commit ff3e0de135
1 changed files with 30 additions and 4 deletions

View File

@ -1,5 +1,6 @@
package com.dengqn.igps2xingzhe.controller;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.crypto.KeyUtil;
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.RSA;
import cn.hutool.json.JSONUtil;
import com.dengqn.igps2xingzhe.config.IGPSport;
import com.dengqn.igps2xingzhe.config.XingZhe;
import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.security.SecurityUtil;
import org.apache.hc.client5.http.classic.HttpClient;
import org.apache.hc.client5.http.cookie.Cookie;
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.core5.http.ContentType;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.io.entity.BasicHttpEntity;
import org.apache.hc.core5.http.io.support.ClassicRequestBuilder;
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.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
@ -56,15 +61,39 @@ public class Trigger {
@Autowired
private XingZhe xingZhe;
@Autowired
private IGPSport igpSport;
@GetMapping("/sync/igps2xingzhe")
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
HttpResponse executed = httpClient.execute(ClassicRequestBuilder.get("https://www.imxingzhe.com/user/login").build());
System.out.println(executed.getCode());
// 2计算加密后的密码参数
RSA rsa = new RSA(AsymmetricAlgorithm.RSA_ECB_PKCS1.getValue(), null, xingZhe.getPubKey());
String rd = cookieStore.getCookies()
.stream().filter(a -> a.getName().equals("rd")).findFirst()
@ -81,10 +110,7 @@ public class Trigger {
.setEntity(JSONUtil.toJsonPrettyStr(loginData), ContentType.APPLICATION_JSON)
.build());
log.info("xingzhe login: {}", IoUtil.read(response.getEntity().getContent()));
return ResponseEntity.ok("ok");
}
}