import cn.hutool.core.date.DateUtil; import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpUtil; import com.alibaba.fastjson.JSONObject; import com.newfiber.common.core.utils.file.FileUtils; import com.newfiber.termite.domain.jingchu.JingChuUpload; import com.newfiber.termite.util.CosUtil; import java.io.File; import java.util.ArrayList; import java.util.Date; import java.util.List; import lombok.extern.slf4j.Slf4j; import org.junit.Test; import org.springframework.web.multipart.MultipartFile; @Slf4j public class CommonTest { @Test public void fileUploadTest(){ MultipartFile file = FileUtils.getMultipartFile(new File("C:\\Users\\Administrator\\Pictures\\201210133348076.jpg")); System.out.println(CosUtil.putFile(file)); } @Test public void jingchuTest(){ String url = "https://sk.hubeishuiyi.cn/bylr"; String token = "eyJraWQiOiJrMSIsImFsZyI6IlJTMjU2In0.eyJpc3MiOiJhZG1pbkBnaXN1bmkuY29tIiwiYXVkIjoidXVtcyIsImp0aSI6IjYwMGZiYmMyLWE1NDgtNGZmNC04ZGNhLTZkNTdkZjY1OTYxNyIsImlhdCI6MTcxNzcyNDA1MywibmJmIjoxNzE3NzIzNDUzLCJzdWIiOiJzdXBlciIsImV4cCI6MTcxNzc4NTQ5Mywia2V5IjoiMmQ5ZWY2MTNlYTkxNDc4MDhlOGZiYTMxYWNlOTE0NmEiLCJpZCI6IjEiLCJuYW1lIjoic3VwZXIiLCJuaWNrTmFtZSI6Iui2hee6p-euoeeQhuWRmCIsImFjY291bnQiOiJzdXBlciIsInR5cGUiOiIyIiwiY2xpZW50IjpudWxsLCJjbGllbnRfaWQiOiIiLCJ0b2tlblR5cGUiOiJVU0VSIn0.VzETse76m1rkRsMjst9kDr1oCnHrPq81pRs-34bjVXPDRiPT6ekVCm-63hLfoH4GAp25oTL9dWA1ax-t1KWlSzHUn82myEBokwCVWlkZZPVMzFMCgP_SNdFeYlvguVhige1nQ6B0wo5crGYKKsfllt0_bp98TFg3I3zF03WsORk7HlsZfsY7ROwYkXXkIgbdw5gIRYlZJ6W1MiMET9TOyAzWGJvEyTPewaW4XMoq-okZoAe_7gV2u_tylngqRCohxTSuA7xf59gK8OrstwTeId_qQp4remoEDdLJfYyzLXCX5xBKns8gw2i1MZfpq9rizDT-Qdz23VQDQdmeHWK7zQ"; JingChuUpload jingChuUpload = new JingChuUpload(); jingChuUpload.setMnNo("4202813006"); jingChuUpload.setObDate(DateUtil.formatDateTime(new Date()).replace(" ", "T")); jingChuUpload.setObTime(DateUtil.format(new Date(), "yyMMddHHmm")); jingChuUpload.setOrder("123456"); jingChuUpload.setReceiveType(0); jingChuUpload.setStationId(1625); jingChuUpload.setStationName("大晚垅水库"); jingChuUpload.setDeviceId(5858); jingChuUpload.setDeviceName("大晚垅水库白蚁监测站"); List<JingChuUpload> jingChuUploadList = new ArrayList<>(); jingChuUploadList.add(jingChuUpload); HttpResponse httpResponse = HttpUtil.createPost(url.concat("/waterDataTermites/insertDataBatch")). body(JSONObject.toJSONString(jingChuUploadList)).timeout(1000). header("Authorization", token).execute(); log.info("同步荆楚监测数据.请求:{},响应:{}", JSONObject.toJSONString(jingChuUploadList), httpResponse.body()); } }