You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.6 KiB
Java
59 lines
1.6 KiB
Java
package com.glxp.api.http;
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
import com.glxp.api.entity.thrsys.ThrSystemEntity;
|
|
import com.glxp.api.util.OkHttpCli;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import javax.annotation.Resource;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
@Slf4j
|
|
@Service
|
|
public class HttpOkClient {
|
|
|
|
@Resource
|
|
OkHttpCli okHttpCli;
|
|
|
|
public String uCloudPost(String url, Object object) {
|
|
|
|
String json = JSONUtil.toJsonStr(object);
|
|
log.info(url + "\n" + json);
|
|
String response = okHttpCli.doPostJson(url, json, "Content-Type", "application/json");
|
|
return response;
|
|
}
|
|
|
|
|
|
public String uCloudPost(String url, Object object, ThrSystemEntity thrSystemEntity) {
|
|
String json = JSONUtil.toJsonStr(object);
|
|
log.info(url + "\n" + json);
|
|
List<String> header = new ArrayList<>();
|
|
header.add("Content-Type");
|
|
header.add("application/json");
|
|
if (null != thrSystemEntity) {
|
|
|
|
if (StrUtil.isNotEmpty(thrSystemEntity.getApikey())) {
|
|
header.add("api_key");
|
|
header.add(thrSystemEntity.getApikey());
|
|
}
|
|
|
|
|
|
if (StrUtil.isNotEmpty(thrSystemEntity.getSecretkey())) {
|
|
header.add("secret_key");
|
|
header.add(thrSystemEntity.getSecretkey());
|
|
}
|
|
|
|
|
|
}
|
|
|
|
String[] strArray = new String[header.size()];
|
|
header.toArray(strArray);
|
|
|
|
return okHttpCli.doPostJson(url, json, strArray);
|
|
}
|
|
|
|
}
|