|
|
@@ -73,127 +73,18 @@ public class OpenApiRequestService extends SuperService {
|
|
|
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));
|
|
|
}
|
|
|
APIResponseModel responseModel = requestAPI(projectIotInfo.getUrl(), apiName,
|
|
|
projectIotInfo.getAk(), projectIotInfo.getSk(), param);
|
|
|
if (responseModel.isFailed()) {
|
|
|
+ log.error("{}", responseModel.getMsg());
|
|
|
return ResultContent.buildFail(responseModel.getMsg());
|
|
|
}
|
|
|
return ResultContent.buildSuccess(responseModel);
|
|
|
}
|
|
|
|
|
|
-// /**
|
|
|
-// * 银联请求
|
|
|
-// *
|
|
|
-// * @param url
|
|
|
-// * @param data
|
|
|
-// * @param tClass
|
|
|
-// * @return
|
|
|
-// */
|
|
|
-// public SuperResponseModel requestUnionAPI(String url,
|
|
|
-// Object data,
|
|
|
-// Class<? extends SuperResponseModel> tClass) {
|
|
|
-// RequestInfoSaveParam param = new RequestInfoSaveParam();
|
|
|
-// param.setParam(data);
|
|
|
-// param.setApiParam(url);
|
|
|
-// param.setUserId(getCurrentUserId());
|
|
|
-// SuperResponseModel responseModel = null;
|
|
|
-// try {
|
|
|
-// responseModel = tClass.newInstance();
|
|
|
-// ApiConfParam apiConfParam = new ApiConfParam();
|
|
|
-// apiConfParam.setApiName(url);
|
|
|
-// apiConfParam.setMethodType(MethodType.Json);
|
|
|
-// String dataJsonStr = JSONUtil.toJsonStr(data);
|
|
|
-// String sign = AesUtils.signData(dataJsonStr);
|
|
|
-// // 请求时间记时
|
|
|
-// StopWatch stopWatch = new StopWatch();
|
|
|
-// stopWatch.start();
|
|
|
-//
|
|
|
-// String timestamp = DateUtils.paresTime(System.currentTimeMillis(), DateUtils.unionAuth);
|
|
|
-// String nonce = CommonUtil.UUID();
|
|
|
-// String c = String.format("%s%s%s%s", payConfig.getAppId(), timestamp, nonce, sign);
|
|
|
-//
|
|
|
-// String signature = AesUtils.signMacSHA256(c, payConfig.getAppKey());
|
|
|
-// String authorization = "OPEN-BODY-SIG AppId=" + "\"" + payConfig.getAppId() + "\""
|
|
|
-// + ",Timestamp=" + "\"" + timestamp + "\""
|
|
|
-// + ",Nonce=" + "\"" + nonce + "\""
|
|
|
-// + ",Signature=" + "\"" + signature + "\"";
|
|
|
-//
|
|
|
-//
|
|
|
-// String response = "";
|
|
|
-// PrintWriter out = null;
|
|
|
-// BufferedReader in = null;
|
|
|
-// int code = 400;
|
|
|
-// try {
|
|
|
-// URL realUrl = new URL(url);
|
|
|
-// URLConnection conn = realUrl.openConnection();
|
|
|
-// HttpURLConnection httpUrlConnection = (HttpURLConnection) conn;
|
|
|
-// httpUrlConnection.setRequestProperty("Content-Type", "application/json");
|
|
|
-// httpUrlConnection.setRequestProperty("authorization", authorization);
|
|
|
-// httpUrlConnection.setDoOutput(true);
|
|
|
-// httpUrlConnection.setDoInput(true);
|
|
|
-// out = new PrintWriter(httpUrlConnection.getOutputStream());
|
|
|
-// out.write(dataJsonStr);
|
|
|
-// out.flush();
|
|
|
-// httpUrlConnection.connect();
|
|
|
-// code = httpUrlConnection.getResponseCode();
|
|
|
-// in = new BufferedReader(new InputStreamReader(httpUrlConnection.getInputStream()));
|
|
|
-// String line;
|
|
|
-// while ((line = in.readLine()) != null) {
|
|
|
-// response += line;
|
|
|
-// }
|
|
|
-// log.info("response: {}", response);
|
|
|
-// responseModel = jsonHelper.toObject(response, tClass);
|
|
|
-// } catch (Exception e) {
|
|
|
-// e.printStackTrace();
|
|
|
-// responseModel.setCode(code);
|
|
|
-// responseModel.setMsg(e.getMessage());
|
|
|
-// } finally {
|
|
|
-// try {
|
|
|
-// if (out != null) {
|
|
|
-// out.close();
|
|
|
-// }
|
|
|
-// if (in != null) {
|
|
|
-// in.close();
|
|
|
-// }
|
|
|
-// } catch (Exception ex) {
|
|
|
-// ex.printStackTrace();
|
|
|
-// }
|
|
|
-// }
|
|
|
-// String errMsg = responseModel.getErrMsg();
|
|
|
-// if (StringUtils.isNotEmpty(errMsg) && !errMsg.equals("success")) {
|
|
|
-// code = 400;
|
|
|
-// }
|
|
|
-// log.info("response: {} {}", responseModel.getErrCode(), code);
|
|
|
-// responseModel.setCode(code);
|
|
|
-// if (code == 504) {
|
|
|
-// responseModel.setErrMsg("银联服务无法访问");
|
|
|
-// }
|
|
|
-// stopWatch.stop();
|
|
|
-// responseModel.setMillis(stopWatch.getTotalTimeMillis());
|
|
|
-// } catch (Exception e) {
|
|
|
-// e.printStackTrace();
|
|
|
-// responseModel.setFailed(String.format("请求出错:%s", e.getMessage()));
|
|
|
-// return responseModel;
|
|
|
-// }
|
|
|
-// param.setMillis(responseModel.getMillis());
|
|
|
-// param.setIsSuccess(responseModel.isSuccess);
|
|
|
-// param.setMsg(responseModel.getMsg());
|
|
|
-// param.setResponse(responseModel);
|
|
|
-// param.setRequestType(RequestType.UnionFrictionlessPay);
|
|
|
-// // 请求日志
|
|
|
-// requestInfoService.saveRequestInfo(param);
|
|
|
-// return responseModel;
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
public APIResponseModel requestAPI(
|
|
|
String url,
|
|
|
String apiName,
|
|
|
@@ -203,6 +94,8 @@ public class OpenApiRequestService extends SuperService {
|
|
|
String authorization = SignUtil.sign(JSONUtil.toJsonStr(data), ak, sk);
|
|
|
HashMap<String, Object> headers = new HashMap<>();
|
|
|
headers.put("Authorization", authorization);
|
|
|
+ headers.put("appId", ak);
|
|
|
+
|
|
|
ApiConfParam apiConfParam = new ApiConfParam();
|
|
|
apiConfParam.setApiName(url);
|
|
|
StopWatch stopWatch = new StopWatch();
|