2 changed files with 58 additions and 25 deletions
@ -1,25 +0,0 @@ |
|||||
package com.elink.esua.epdc.commons.tools.security.epmet; |
|
||||
|
|
||||
import com.elink.esua.epdc.jwt.JwtUtils; |
|
||||
import lombok.Data; |
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
|
||||
|
|
||||
import java.util.HashMap; |
|
||||
import java.util.Map; |
|
||||
@Data |
|
||||
public class EpmetTokenUtils { |
|
||||
// 应用id
|
|
||||
public static String appId = "dbfad3110c124c89948d16e8b06a8888"; |
|
||||
// 客户id
|
|
||||
private static String customerId = "b09527201c4409e19d1dbc5e3c3429a1"; |
|
||||
// 秘钥
|
|
||||
private static String secret = "0f7e983b017ac180b0da1877abe11bab22ab6288580e64d39b5e415dbb0fcc8f"; |
|
||||
|
|
||||
public static String getToken (){ |
|
||||
Map<String,Object> claims = new HashMap<String,Object>(); |
|
||||
claims.put("appId",appId); |
|
||||
claims.put("customerId",customerId); |
|
||||
claims.put("ts",System.currentTimeMillis()); |
|
||||
return JwtUtils.generateEpmetToken(claims,secret); |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,58 @@ |
|||||
|
package com.elink.esua.epdc.commons.tools.security.epmet; |
||||
|
|
||||
|
import cn.hutool.http.HttpRequest; |
||||
|
import cn.hutool.http.HttpResponse; |
||||
|
import com.elink.esua.epdc.jwt.JwtUtils; |
||||
|
import lombok.Data; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
|
||||
|
import java.util.HashMap; |
||||
|
import java.util.Map; |
||||
|
@Data |
||||
|
public class EpmetUtils { |
||||
|
// 应用id
|
||||
|
public static String appId = "dbfad3110c124c89948d16e8b06a8888"; |
||||
|
// 客户id
|
||||
|
private static String customerId = "b09527201c4409e19d1dbc5e3c3429a1"; |
||||
|
// 秘钥
|
||||
|
private static String secret = "0f7e983b017ac180b0da1877abe11bab22ab6288580e64d39b5e415dbb0fcc8f"; |
||||
|
private static String commonUrl = ""; |
||||
|
|
||||
|
/** |
||||
|
* 生成token |
||||
|
* |
||||
|
|
||||
|
* @return String |
||||
|
*/ |
||||
|
public static String getToken (){ |
||||
|
Map<String,Object> claims = new HashMap<String,Object>(); |
||||
|
claims.put("appId",appId); |
||||
|
claims.put("customerId",customerId); |
||||
|
claims.put("ts",System.currentTimeMillis()); |
||||
|
return JwtUtils.generateEpmetToken(claims,secret); |
||||
|
} |
||||
|
/** |
||||
|
* 采集接口请求 |
||||
|
* |
||||
|
* @param url |
||||
|
* @param param |
||||
|
* @return String |
||||
|
*/ |
||||
|
public static String httpPost(String url,String param) { |
||||
|
|
||||
|
String requestUrl = commonUrl + url; |
||||
|
HttpResponse response = null; |
||||
|
try { |
||||
|
response = HttpRequest.post(requestUrl).body(param) |
||||
|
.header("lan", "zh") |
||||
|
.header("Content-Type", "application/json") |
||||
|
.header("AccessToken", getToken()) |
||||
|
.header("AppId",appId) |
||||
|
.execute(); |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
return response.body(); |
||||
|
|
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue