SDK复用链接问题
This commit is contained in:
@@ -9,7 +9,9 @@ import org.apache.http.HttpStatus;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -24,10 +26,12 @@ public class AdminHttpUtils {
|
||||
|
||||
private static String adminUrl;
|
||||
private static String adminSecret;
|
||||
private static CloseableHttpClient httpClient;
|
||||
|
||||
public static void init(String url, String secret) {
|
||||
adminUrl = url;
|
||||
adminSecret = secret;
|
||||
httpClient = HttpClients.createDefault();
|
||||
}
|
||||
|
||||
public static <T> IMResult<T> httpJsonPost(String path, Object object, Class<T> clazz) throws Exception{
|
||||
@@ -42,15 +46,13 @@ public class AdminHttpUtils {
|
||||
|
||||
String url = adminUrl + path;
|
||||
HttpPost post = null;
|
||||
try {
|
||||
HttpClient httpClient = HttpClientBuilder.create().build();
|
||||
|
||||
try {
|
||||
int nonce = (int)(Math.random() * 100000 + 3);
|
||||
long timestamp = System.currentTimeMillis();
|
||||
String str = nonce + "|" + adminSecret + "|" + timestamp;
|
||||
String sign = DigestUtils.sha1Hex(str);
|
||||
|
||||
|
||||
post = new HttpPost(url);
|
||||
post.setHeader("Content-type", "application/json; charset=utf-8");
|
||||
post.setHeader("Connection", "Keep-Alive");
|
||||
|
||||
@@ -9,7 +9,9 @@ import org.apache.http.HttpStatus;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -25,11 +27,13 @@ public class ChannelHttpUtils {
|
||||
private String imurl;
|
||||
private String channelId;
|
||||
private String channelSecret;
|
||||
private final CloseableHttpClient httpClient;
|
||||
|
||||
public ChannelHttpUtils(String imurl, String channelId, String secret) {
|
||||
this.imurl = imurl;
|
||||
this.channelId = channelId;
|
||||
this.channelSecret = secret;
|
||||
this.httpClient = HttpClients.createDefault();
|
||||
}
|
||||
|
||||
public <T> IMResult<T> httpJsonPost(String path, Object object, Class<T> clazz) throws Exception{
|
||||
@@ -41,8 +45,6 @@ public class ChannelHttpUtils {
|
||||
String url = imurl + path;
|
||||
HttpPost post = null;
|
||||
try {
|
||||
HttpClient httpClient = HttpClientBuilder.create().build();
|
||||
|
||||
int nonce = (int)(Math.random() * 100000 + 3);
|
||||
long timestamp = System.currentTimeMillis();
|
||||
String str = nonce + "|" + channelSecret + "|" + timestamp;
|
||||
|
||||
@@ -10,7 +10,9 @@ import org.apache.http.HttpStatus;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -26,11 +28,13 @@ public class RobotHttpUtils {
|
||||
private final String url;
|
||||
private final String robotId;
|
||||
private final String robotSecret;
|
||||
private final CloseableHttpClient httpClient;
|
||||
|
||||
public RobotHttpUtils(String url, String robotId, String robotSecret) {
|
||||
this.url = url;
|
||||
this.robotId = robotId;
|
||||
this.robotSecret = robotSecret;
|
||||
this.httpClient = HttpClients.createDefault();
|
||||
}
|
||||
|
||||
|
||||
@@ -43,8 +47,6 @@ public class RobotHttpUtils {
|
||||
String url = this.url + path;
|
||||
HttpPost post = null;
|
||||
try {
|
||||
HttpClient httpClient = HttpClientBuilder.create().build();
|
||||
|
||||
int nonce = (int)(Math.random() * 100000 + 3);
|
||||
long timestamp = System.currentTimeMillis();
|
||||
String str = nonce + "|" + robotSecret + "|" + timestamp;
|
||||
|
||||
Reference in New Issue
Block a user