|
|
@@ -8,17 +8,16 @@ import com.github.microservice.core.util.net.apache.HttpModel;
|
|
|
import com.github.microservice.core.util.net.apache.MethodType;
|
|
|
import com.github.microservice.core.util.net.apache.ResponseModel;
|
|
|
import com.github.microservice.http.APIResponseModel;
|
|
|
+import com.github.microservice.http.ApiConfParam;
|
|
|
import com.github.microservice.models.iot.IotSendParam;
|
|
|
import com.github.microservice.net.ResultContent;
|
|
|
-import com.zhongshu.card.client.utils.DateUtils;
|
|
|
import com.zhongshu.card.server.core.dao.org.OrganizationDao;
|
|
|
import com.zhongshu.card.server.core.dao.projectAbout.ProjectIotInfoDao;
|
|
|
import com.zhongshu.card.server.core.domain.projectAbout.ProjectIotInfo;
|
|
|
+import com.zhongshu.card.server.core.httpRequest.conf.IotCenterAPIConfig;
|
|
|
import com.zhongshu.card.server.core.service.base.SuperService;
|
|
|
import com.zhongshu.card.server.core.service.payment.RequestInfoService;
|
|
|
-import com.zhongshu.card.server.core.util.CommonUtil;
|
|
|
import com.zhongshu.opengateway.client.util.SignUtil;
|
|
|
-import com.zhongshu.payment.client.payModel.unionFrictionlessPay.model.ApiConfParam;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
@@ -50,6 +49,18 @@ public class OpenApiRequestService extends SuperService {
|
|
|
@Autowired
|
|
|
private ProjectIotInfoDao projectIotInfoDao;
|
|
|
|
|
|
+ /**
|
|
|
+ * 发送发下数据
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ * @param projectOid
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent sendIotSendMessage(IotSendParam param, String projectOid) {
|
|
|
+ ApiConfParam apiConfParam = IotCenterAPIConfig.getApiConfParam(IotCenterAPIConfig.openAPISendMessage);
|
|
|
+ return sendIotRequest(param, projectOid, apiConfParam.getApiName());
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 请求物联网接口
|
|
|
*
|
|
|
@@ -57,16 +68,25 @@ public class OpenApiRequestService extends SuperService {
|
|
|
* @param projectOid
|
|
|
* @return
|
|
|
*/
|
|
|
- public ResultContent sendIotRequest(IotSendParam param, String projectOid) {
|
|
|
+ public ResultContent sendIotRequest(IotSendParam param, String projectOid, String apiName) {
|
|
|
if (StringUtils.isEmpty(projectOid)) {
|
|
|
return ResultContent.buildFail("projectOid为空");
|
|
|
}
|
|
|
ProjectIotInfo projectIotInfo = projectIotInfoDao.findTopByProjectOid(projectOid);
|
|
|
+ projectIotInfo = new ProjectIotInfo();
|
|
|
+ projectIotInfo.setUrl("http://192.168.32.113:9601");
|
|
|
+ projectIotInfo.setAk("");
|
|
|
+ projectIotInfo.setSk("");
|
|
|
+
|
|
|
if (ObjectUtils.isEmpty(projectIotInfo)) {
|
|
|
return ResultContent.buildFail(String.format("项目未配置物联网AK/SK信息", projectOid));
|
|
|
}
|
|
|
-
|
|
|
- return ResultContent.buildSuccess();
|
|
|
+ APIResponseModel responseModel = requestAPI(projectIotInfo.getUrl(), apiName,
|
|
|
+ projectIotInfo.getAk(), projectIotInfo.getSk(), param);
|
|
|
+ if (responseModel.isFailed()) {
|
|
|
+ return ResultContent.buildFail(responseModel.getMsg());
|
|
|
+ }
|
|
|
+ return ResultContent.buildSuccess(responseModel);
|
|
|
}
|
|
|
|
|
|
// /**
|
|
|
@@ -174,7 +194,10 @@ public class OpenApiRequestService extends SuperService {
|
|
|
// }
|
|
|
|
|
|
|
|
|
- public APIResponseModel requestAPI(String url, String ak, String sk, Object data) {
|
|
|
+ public APIResponseModel requestAPI(
|
|
|
+ String url,
|
|
|
+ String apiName,
|
|
|
+ String ak, String sk, Object data) {
|
|
|
APIResponseModel responseModel = new APIResponseModel();
|
|
|
try {
|
|
|
String authorization = SignUtil.sign(JSONUtil.toJsonStr(data), ak, sk);
|
|
|
@@ -185,7 +208,7 @@ public class OpenApiRequestService extends SuperService {
|
|
|
StopWatch stopWatch = new StopWatch();
|
|
|
stopWatch.start();
|
|
|
ResponseModel request = HttpClientUtil.request(HttpModel.builder()
|
|
|
- .url(url).method(MethodType.Json)
|
|
|
+ .url(url + apiName).method(MethodType.Json)
|
|
|
.header(headers)
|
|
|
.charset("utf-8").body(data).build());
|
|
|
int code = request.getCode();
|