| | |
| | | package com.se.simu.service; |
| | | |
| | | import cn.hutool.json.JSONArray; |
| | | import cn.hutool.json.JSONObject; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * SDDB服务类 |
| | |
| | | @Slf4j |
| | | @Service |
| | | public class SedbService { |
| | | @Value("${sedb.url}") |
| | | String url; |
| | | @Value("${sedb.host}") |
| | | String host; |
| | | |
| | | @Value("${sedb.user}") |
| | | String user; |
| | |
| | | @Resource |
| | | RestTemplate restTemplate; |
| | | |
| | | public String getToken() { |
| | | //http://106.120.22.26:8013/account-service/security/publickey |
| | | String key = getPublicKey(); |
| | | public String test() { |
| | | String token = getToken(); |
| | | String dbid = getDbId(token); |
| | | |
| | | System.out.println(dbid); |
| | | |
| | | return key; |
| | | return dbid; |
| | | } |
| | | |
| | | public String getPublicKey() { |
| | | String uri = url + "account-service/security/publickey"; |
| | | |
| | | //{"datetime":"2024-09-12 17:24:38","code":200,"data":"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCtFwJCh2taVTEi05C8qT2oG7Y+rDmJhlO4zicpSeRtiro9LsytePeWI7BXM6sfDU0WeKun1izawcfgGkZgnoJuMBluAOKI1tL0uCrR+DreNLqMVtnXHwoWEIk/hGJedDWaf3q22aGDyEB5h9qCq0JklSShP1Ih4ppap4LmgxdTPQIDAQAB"} |
| | | JSONObject obj = restTemplate.getForObject(uri, JSONObject.class); |
| | | JSONObject obj = restTemplate.getForObject(host + "account-service/security/publickey", JSONObject.class); |
| | | |
| | | return obj.getStr("data"); |
| | | } |
| | | |
| | | public String getToken() { |
| | | String key = getPublicKey(); |
| | | |
| | | Map<String, Object> map = new HashMap<>(2); |
| | | map.put("userid", user); |
| | | map.put("password", pwd); |
| | | |
| | | JSONObject obj = restTemplate.postForObject(host + "account-service/security/login", map, JSONObject.class); |
| | | |
| | | JSONObject data = obj.getJSONObject("data"); |
| | | |
| | | return data.getStr("token"); |
| | | } |
| | | |
| | | public String getDbId(String token) { |
| | | Map<String, Object> map = new HashMap<>(1); |
| | | map.put("token", token); |
| | | |
| | | JSONObject obj = restTemplate.postForObject(host + "geo-service/entitydb/list/canview", map, JSONObject.class); |
| | | |
| | | JSONArray arr = obj.getJSONArray("data"); |
| | | if (null == arr || arr.size() == 0) { |
| | | return null; |
| | | } |
| | | |
| | | JSONObject dbObj = arr.getJSONObject(0); |
| | | |
| | | return dbObj.getStr("dbid"); |
| | | } |
| | | } |