|
@@ -17,6 +17,7 @@ import org.apache.http.NameValuePair;
|
|
|
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
import org.apache.http.client.methods.HttpPost;
|
|
|
+import org.apache.http.entity.FileEntity;
|
|
|
import org.apache.http.entity.StringEntity;
|
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
import org.apache.http.impl.client.HttpClients;
|
|
@@ -27,6 +28,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import java.io.*;
|
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.URL;
|
|
|
+import java.net.URLConnection;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.text.DecimalFormat;
|
|
@@ -84,18 +86,14 @@ public class EntityAnalyse {
|
|
|
* @return
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
- public static String uploadImage(File image) throws IOException {
|
|
|
+ public static String uploadImage(File image,String token) throws IOException {
|
|
|
String url = "http://116.182.4.67:50065/platform/file/uploadImage";
|
|
|
CloseableHttpClient httpClient = HttpClients.createDefault();
|
|
|
// 模拟登陆,按实际服务器端要求选用 Post 或 Get 请求方式
|
|
|
HttpPost httpPost = new HttpPost(url);
|
|
|
- JSONObject params = new JSONObject();
|
|
|
- params.put("image", image);
|
|
|
-
|
|
|
- httpPost.setEntity(new StringEntity(params.toString(), StandardCharsets.UTF_8));
|
|
|
+ httpPost.setEntity(new FileEntity(image));
|
|
|
// 设置header信息
|
|
|
httpPost.setHeader("Content-type", "application/json");
|
|
|
- String token = EntityAnalyse.GetJTToken();
|
|
|
httpPost.setHeader("token", token);
|
|
|
CloseableHttpResponse response = httpClient.execute(httpPost);
|
|
|
try {
|
|
@@ -111,6 +109,7 @@ public class EntityAnalyse {
|
|
|
// 释放链接
|
|
|
response.close();
|
|
|
httpClient.close();
|
|
|
+ image.delete();
|
|
|
}
|
|
|
return "";
|
|
|
}
|
|
@@ -136,11 +135,11 @@ public class EntityAnalyse {
|
|
|
params.put("qualificationCertificate", hyDriverInfo.getQualificationCertificateNumber());
|
|
|
params.put("telephone", hyDriverInfo.getDriverPhone());
|
|
|
params.put("remark", hyDriverInfo.getDriverName() + hyDriverInfo.getDriverPhone());
|
|
|
- params.put("idCardFrontImg", EntityAnalyse.uploadImage(new File(hyDriverInfo.getCardAddressUrl())));
|
|
|
- params.put("idCardBackImg", EntityAnalyse.uploadImage(new File(hyDriverInfo.getCardBackAddressUrl())));
|
|
|
- params.put("driverLicenseFirstSheetImg", EntityAnalyse.uploadImage(new File(hyDriverInfo.getDriverLicenseHomePage())));
|
|
|
- params.put("driverLicenseSecondSheetImg", EntityAnalyse.uploadImage(new File(hyDriverInfo.getDriverLicenseBackPage())));
|
|
|
- params.put("transportCertificationImg", EntityAnalyse.uploadImage(new File(hyDriverInfo.getQualificationCertificate())));
|
|
|
+ params.put("idCardFrontImg", EntityAnalyse.uploadImage(EntityAnalyse.urlToFile(new URL(hyDriverInfo.getCardAddressUrl())),hyDriverInfo.getToken()));
|
|
|
+ params.put("idCardBackImg", EntityAnalyse.uploadImage(EntityAnalyse.urlToFile(new URL(hyDriverInfo.getCardBackAddressUrl())),hyDriverInfo.getToken()));
|
|
|
+ params.put("driverLicenseFirstSheetImg", EntityAnalyse.uploadImage(EntityAnalyse.urlToFile(new URL(hyDriverInfo.getDriverLicenseHomePage())),hyDriverInfo.getToken()));
|
|
|
+ params.put("driverLicenseSecondSheetImg", EntityAnalyse.uploadImage(EntityAnalyse.urlToFile(new URL(hyDriverInfo.getDriverLicenseBackPage())),hyDriverInfo.getToken()));
|
|
|
+ params.put("transportCertificationImg", EntityAnalyse.uploadImage(EntityAnalyse.urlToFile(new URL(hyDriverInfo.getQualificationCertificate())),hyDriverInfo.getToken()));
|
|
|
params.put("idCardValidPeriodTo", hyDriverInfo.getCardValidityDate());
|
|
|
params.put("transportCertificationValidPeriodTo", hyDriverInfo.getQualificationCertificateValidityDate());
|
|
|
if ("男".equals(hyDriverInfo.getDriverSex())){
|
|
@@ -226,10 +225,10 @@ public class EntityAnalyse {
|
|
|
}
|
|
|
params.put("licenseValidPeriodTo", hyDriverCarInfo.getDrivingLicenseValidityDate());
|
|
|
params.put("transportValidPeriodTo", hyDriverCarInfo.getOperationCertificateValidityDate());
|
|
|
- params.put("vehicleLicenseFirstSheetImg", EntityAnalyse.uploadImage(new File(hyDriverCarInfo.getDrivingLicenseHomePage())));
|
|
|
- params.put("vehicleLicenseSecondSheetImg", EntityAnalyse.uploadImage(new File(hyDriverCarInfo.getDrivingLicenseBackPage())));
|
|
|
- params.put("transportLicenseFirstSheetImg", EntityAnalyse.uploadImage(new File(hyDriverCarInfo.getOperationCertificate())));
|
|
|
- params.put("vehicleDriverImg", EntityAnalyse.uploadImage(new File(hyDriverCarInfo.getAddressUrl())));
|
|
|
+ params.put("vehicleLicenseFirstSheetImg", EntityAnalyse.uploadImage(EntityAnalyse.urlToFile(new URL(hyDriverCarInfo.getDrivingLicenseHomePage())),hyDriverCarInfo.getToken()));
|
|
|
+ params.put("vehicleLicenseSecondSheetImg", EntityAnalyse.uploadImage(EntityAnalyse.urlToFile(new URL(hyDriverCarInfo.getDrivingLicenseBackPage())),hyDriverCarInfo.getToken()));
|
|
|
+ params.put("transportLicenseFirstSheetImg", EntityAnalyse.uploadImage(EntityAnalyse.urlToFile(new URL(hyDriverCarInfo.getOperationCertificate())),hyDriverCarInfo.getToken()));
|
|
|
+ params.put("vehicleDriverImg", EntityAnalyse.uploadImage(EntityAnalyse.urlToFile(new URL(hyDriverCarInfo.getAddressUrl())),hyDriverCarInfo.getToken()));
|
|
|
|
|
|
httpPost.setEntity(new StringEntity(params.toString(), StandardCharsets.UTF_8));
|
|
|
// 设置header信息
|
|
@@ -866,4 +865,44 @@ public class EntityAnalyse {
|
|
|
br.close();
|
|
|
return sb.toString();
|
|
|
}
|
|
|
+ /**
|
|
|
+ * url资源转化为file流
|
|
|
+ * @param url
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static File urlToFile(URL url) {
|
|
|
+ InputStream is = null;
|
|
|
+ File file = null;
|
|
|
+ FileOutputStream fos = null;
|
|
|
+ try {
|
|
|
+ String tmp = "templates" + File.separator + "tmp.jpg";
|
|
|
+ file = new File( new String(tmp.getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8));
|
|
|
+// file = File.createTempFile("tmp", null);
|
|
|
+ URLConnection urlConn = null;
|
|
|
+ urlConn = url.openConnection();
|
|
|
+ is = urlConn.getInputStream();
|
|
|
+ fos = new FileOutputStream(file);
|
|
|
+ byte[] buffer = new byte[4096];
|
|
|
+ int length;
|
|
|
+ while ((length = is.read(buffer)) > 0) {
|
|
|
+ fos.write(buffer, 0, length);
|
|
|
+ }
|
|
|
+ return file;
|
|
|
+ } catch (IOException e) {
|
|
|
+ return null;
|
|
|
+ } finally {
|
|
|
+ if (is != null) {
|
|
|
+ try {
|
|
|
+ is.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (fos != null) {
|
|
|
+ try {
|
|
|
+ fos.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|