feat: 增加安徽物联和公田软件页面接口调用

dev
huangfeng 11 months ago
parent c29ceac5e4
commit 926c9122cf

@ -210,5 +210,7 @@ public class Constants {
*/
public static final Integer NetType_Dahan = 1;
public static final Integer NetType_Rabchaser = 2;
public static final Integer NetType_M2M10086 = 3;
public static final Integer NetType_LWWLKJ = 4;
}

@ -0,0 +1,72 @@
package com.shxy.xymanager_common.sms.lwwlkj;
import com.shxy.xymanager_common.exception.ApiException;
import com.shxy.xymanager_common.util.HttpClient;
import com.shxy.xymanager_common.util.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
@Slf4j
public class LwwlkjWeb {
private String baseUrl = "https://www.lwwlkj.com/wulw";
public static String cookie = "";
private Map<String, String> buildHead() {
Map<String, String> map = new HashMap<>();
map.put("Cookie", cookie);
return map;
}
public Object listSms(String msisdn, String date) {
String url = "/message/history";
Map<String, String> dataMap = new HashMap<>();
dataMap.put("simNo", msisdn);
dataMap.put("pageNo", "1");
dataMap.put("pageSize", "10");
try {
HashMap<String, Object> result = null;
String json = HttpClient.postUrlEncoded(baseUrl + url, dataMap, this.buildHead());
log.info("查询短信记录完成: " + json);
return json;
} catch (Exception e) {
log.error("查询短信异常.", e);
throw new ApiException("查询短信异常," + e.getMessage());
}
}
public void sendSms(List<String> msisdnList, String content) {
String url = "/message/send";
try {
String msisdns = msisdnList.stream().collect(Collectors.joining(","));
Map<String, String> dataMap = new HashMap<>();
dataMap.put("layerSimNo", msisdns);
dataMap.put("messageContent", content);
String json = HttpClient.postUrlEncoded(baseUrl + url, dataMap, this.buildHead());
log.info("发送短信完成:" + json);
HashMap<String, Object> result = null;
try {
result = JSONUtil.json2Object(json, HashMap.class);
} catch (Exception e) {
throw new ApiException(json);
}
if (result.get("code") != null && "success".equalsIgnoreCase(result.get("code").toString())) {
} else {
throw new ApiException(json);
}
} catch (ApiException e) {
throw e;
} catch (Exception e) {
log.error("发送短信异常.", e);
throw new ApiException("发送短信异常," + e.getMessage());
}
}
}

@ -0,0 +1,90 @@
package com.shxy.xymanager_common.sms.m2m;
import com.shxy.xymanager_common.exception.ApiException;
import com.shxy.xymanager_common.util.HttpClient;
import com.shxy.xymanager_common.util.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
@Slf4j
public class M2m10086Web {
private String baseUrl = "https://www.m2m10086.cn/scmp";
public static String cookie = "";
private Map<String, String> buildHead() {
Map<String, String> map = new HashMap<>();
map.put("Cookie", cookie);
return map;
}
public Object listSms(String iccid, String date) {
String url = "/sms/smsRecord/getSmsRecordList";
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("codeType", "iccid");
dataMap.put("startCode", iccid);
dataMap.put("endCode", iccid);
// dataMap.put("submitTimeStart", date);
// dataMap.put("submitTimeEnd", date);
dataMap.put("page", 1);
dataMap.put("limit", 10);
try {
HashMap<String, Object> result = null;
String json = HttpClient.post(baseUrl + url, dataMap, this.buildHead());
log.info("查询短信记录完成: " + json);
try {
result = JSONUtil.json2Object(json, HashMap.class);
} catch (Exception e) {
throw new ApiException(json);
}
if (result.get("code") != null && "0".equalsIgnoreCase(result.get("code").toString())) {
return result.get("data");
} else {
String error = String.valueOf(result.get("message"));
throw new ApiException(error);
}
} catch (Exception e) {
log.error("查询短信异常.", e);
throw new ApiException("查询短信异常," + e.getMessage());
}
}
public void sendSms(List<String> iccidList, String content) {
String url = "/sms/smsRecord/saveSmsRecord";
try {
for (String iccid : iccidList) {
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("codeType", "iccid");
dataMap.put("key", iccid);
dataMap.put("smsContent", content);
dataMap.put("smsFmt", "-1");
String json = HttpClient.post(baseUrl + url, dataMap, this.buildHead());
log.info("发送短信完成:" + json);
HashMap<String, Object> result = null;
try {
result = JSONUtil.json2Object(json, HashMap.class);
} catch (Exception e) {
throw new ApiException(json);
}
if (result.get("code") != null && "0".equalsIgnoreCase(result.get("code").toString())) {
} else {
String error = String.valueOf(result.get("message"));
throw new ApiException(error);
}
}
} catch (ApiException e) {
throw e;
} catch (Exception e) {
log.error("发送短信异常.", e);
throw new ApiException("发送短信异常," + e.getMessage());
}
}
}

@ -186,7 +186,7 @@ public class HttpClient {
}
}
public static String postUrlEncoded(String url, Map<String, String> map) throws Exception {
public static String postUrlEncoded(String url, Map<String, String> map, Map<String, String> headMap) throws Exception {
try (CloseableHttpClient client = createAcceptSelfSignedCertificateClient()) {
// build HttpClient
@ -197,6 +197,11 @@ public class HttpClient {
.setSocketTimeout(50000).build();
request.setConfig(requestConfig);
request.setHeader("Content-type", "application/x-www-form-urlencoded");
if (headMap != null) {
for (Map.Entry<String, String> entry : headMap.entrySet()) {
request.setHeader(entry.getKey(), entry.getValue());
}
}
// 内容
List<NameValuePair> params = new ArrayList<>();

Loading…
Cancel
Save