08-21-GPS登录
This commit is contained in:
@ -0,0 +1,63 @@
|
|||||||
|
package org.dromara.gps.controller;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.dromara.common.core.domain.R;
|
||||||
|
import org.dromara.gps.domain.GpsLogin;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.http.HttpClient;
|
||||||
|
import java.net.http.HttpRequest;
|
||||||
|
import java.net.http.HttpResponse;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/GPS")
|
||||||
|
public class GpsController {
|
||||||
|
|
||||||
|
HttpClient client = HttpClient.newBuilder()
|
||||||
|
.connectTimeout(Duration.ofSeconds(10)) // 设置连接超时
|
||||||
|
.build();
|
||||||
|
|
||||||
|
@GetMapping("/login")
|
||||||
|
public R<Void> login(@RequestParam GpsLogin loginData) throws IOException, InterruptedException {
|
||||||
|
|
||||||
|
//对象转HashMap
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
HashMap<String, Object> params = mapper.convertValue(loginData, HashMap.class);
|
||||||
|
|
||||||
|
//拼接URL
|
||||||
|
String baseUrl = "http://openapi.18gps.net//GetDateServices.asmx/loginSystem";
|
||||||
|
String query = params.entrySet().stream()
|
||||||
|
.map(entry -> entry.getKey() + "=" + entry.getValue())
|
||||||
|
.collect(Collectors.joining("&"));
|
||||||
|
String requestUrl = baseUrl + "?" + query;
|
||||||
|
|
||||||
|
HttpRequest request = HttpRequest.newBuilder()
|
||||||
|
.uri(URI.create(requestUrl))
|
||||||
|
.timeout(Duration.ofSeconds(10)) // 设置响应超时
|
||||||
|
.GET() // 使用GET请求方式
|
||||||
|
.build();
|
||||||
|
|
||||||
|
//获取响应
|
||||||
|
HttpResponse<String> response = client.send(
|
||||||
|
request,
|
||||||
|
HttpResponse.BodyHandlers.ofString()
|
||||||
|
);
|
||||||
|
|
||||||
|
log.info("响应体:{}", response.body());
|
||||||
|
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
package org.dromara.gps.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class GpsLogin {
|
||||||
|
|
||||||
|
private String LoginName;
|
||||||
|
|
||||||
|
private String LoginPassword;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登陆类型 [单位用户:ENTERPRISE/设备登录:USER]
|
||||||
|
*/
|
||||||
|
private String LoginType;
|
||||||
|
|
||||||
|
/***
|
||||||
|
* 语言类型 [cn,中文;en,英文]
|
||||||
|
*/
|
||||||
|
private String language;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用类型[默认APP]
|
||||||
|
*/
|
||||||
|
private String apply;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MD5验证[默认0不验证] 非必填
|
||||||
|
*/
|
||||||
|
private String ISMD5;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用域 Id,应用域请找台提供。可以不填,但最好填。
|
||||||
|
*/
|
||||||
|
private String ApiKey;
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user