|
@@ -0,0 +1,110 @@
|
|
|
+package com.ygj.yuemum.service.modoo;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import org.apache.http.HttpStatus;
|
|
|
+import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
+import org.apache.http.client.methods.HttpPost;
|
|
|
+import org.apache.http.entity.ContentType;
|
|
|
+import org.apache.http.entity.StringEntity;
|
|
|
+import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
+import org.apache.http.impl.client.HttpClients;
|
|
|
+import org.apache.http.util.EntityUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class ModooApiService {
|
|
|
+
|
|
|
+ public int equipmentActive(String ei_code) {
|
|
|
+ try {
|
|
|
+ String result = "";
|
|
|
+ String ticket = getTicket();
|
|
|
+ // 创建httpclient对象
|
|
|
+ CloseableHttpClient httpClient = HttpClients.createDefault();
|
|
|
+ // 创建post方式请求对象
|
|
|
+ HttpPost httpPost = new HttpPost("https://yulu.meng-dong.com/access");
|
|
|
+ String para = "{\"cmd\":2019,\"userId\":\"471699856\",\"WebReqHeader\":{\"uuid\":\"1528104729646\",\"ua\":\"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0\",\"ticket\":\"" + ticket + "\",\"seq\":13},\"request\":{\"psnStr\":\"" + ei_code + "\"}}";
|
|
|
+ StringEntity stringEntity = new StringEntity(para, ContentType.APPLICATION_JSON);
|
|
|
+ stringEntity.setContentEncoding("utf-8");
|
|
|
+ httpPost.setEntity(stringEntity);
|
|
|
+ CloseableHttpResponse response = httpClient.execute(httpPost);
|
|
|
+ if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
|
|
|
+ result = EntityUtils.toString(response.getEntity(), "utf-8");
|
|
|
+ } else {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ Map map1 = JSON.parseObject(result);
|
|
|
+ Map map2 = JSON.parseObject(String.valueOf(map1.get("response")));
|
|
|
+ Map map3 = JSON.parseObject(String.valueOf(map2.get("ret")));
|
|
|
+ String code = String.valueOf(map3.get("code"));
|
|
|
+ response.close();
|
|
|
+ if (code != "0") {
|
|
|
+ return 1;
|
|
|
+ } else {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ } catch (Exception ex) {
|
|
|
+ ex.printStackTrace();
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public int equipmentSettle(String ei_code) {
|
|
|
+ try {
|
|
|
+ String result = "";
|
|
|
+ String ticket = getTicket();
|
|
|
+ // 创建httpclient对象
|
|
|
+ CloseableHttpClient httpClient = HttpClients.createDefault();
|
|
|
+ // 创建post方式请求对象
|
|
|
+ HttpPost httpPost = new HttpPost("https://yulu.meng-dong.com/access");
|
|
|
+ StringEntity stringEntity = new StringEntity("{\"cmd\":2021,\"userId\":\"471699856\",\"WebReqHeader\":{\"uuid\":\"1528104729646\",\"ua\":\"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0\",\"ticket\":\""+ticket+"\",\"seq\":18},\"request\":{\"psnHex\":\""+ei_code+"\",\"newStatusCode\":6}}", ContentType.APPLICATION_JSON);
|
|
|
+ stringEntity.setContentEncoding("utf-8");
|
|
|
+ httpPost.setEntity(stringEntity);
|
|
|
+ CloseableHttpResponse response = httpClient.execute(httpPost);
|
|
|
+ if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
|
|
|
+ result = EntityUtils.toString(response.getEntity(), "utf-8");
|
|
|
+ } else {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ Map map1 = JSON.parseObject(result);
|
|
|
+ Map map2 = JSON.parseObject(String.valueOf(map1.get("response")));
|
|
|
+ String code = String.valueOf(map2.get("code"));
|
|
|
+ response.close();
|
|
|
+ if (code != "0") {
|
|
|
+ return 1;
|
|
|
+ } else {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ } catch (Exception ex) {
|
|
|
+ ex.printStackTrace();
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getTicket() {
|
|
|
+ try {
|
|
|
+ String result = "";
|
|
|
+ // 创建httpclient对象
|
|
|
+ CloseableHttpClient httpClient = HttpClients.createDefault();
|
|
|
+ // 创建post方式请求对象
|
|
|
+ HttpPost httpPost = new HttpPost("https://yulu.meng-dong.com/access");
|
|
|
+ StringEntity stringEntity = new StringEntity("{\"cmd\":104,\"WebReqHeader\":{\"uuid\":\"1528104729646\",\"ua\":\"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0\",\"seq\":7},\"request\":{\"scene\":1,\"mobile\":\"15011358583\",\"password\":\"abcd1234\",\"role\":2}}", ContentType.APPLICATION_JSON);
|
|
|
+ stringEntity.setContentEncoding("utf-8");
|
|
|
+ httpPost.setEntity(stringEntity);
|
|
|
+ CloseableHttpResponse response = httpClient.execute(httpPost);
|
|
|
+ if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
|
|
|
+ result = EntityUtils.toString(response.getEntity(), "utf-8");
|
|
|
+ }
|
|
|
+ Map map1 = JSON.parseObject(result);
|
|
|
+ Map map2 = JSON.parseObject(String.valueOf(map1.get("response")));
|
|
|
+ Map map3 = JSON.parseObject(String.valueOf(map2.get("webUserTicket")));
|
|
|
+ String ticket = String.valueOf(map3.get("ticket"));
|
|
|
+ response.close();
|
|
|
+ return ticket;
|
|
|
+ } catch (Exception ex) {
|
|
|
+ ex.printStackTrace();
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|