feat: 增加大汉移动页面接口调用
parent
926c9122cf
commit
a7cbfcea70
@ -0,0 +1,85 @@
|
||||
package com.shxy.xymanager_common.sms.dahan;
|
||||
|
||||
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 DahanWeb {
|
||||
private String baseUrl = "http://iot.dahancloud.com/mySms";
|
||||
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 = "/smsPage";
|
||||
Map<String, String> dataMap = new HashMap<>();
|
||||
dataMap.put("filter", msisdn);
|
||||
dataMap.put("smsType", "0");
|
||||
dataMap.put("page", "340");
|
||||
dataMap.put("rows", "10");
|
||||
try {
|
||||
HashMap<String, Object> result = null;
|
||||
String json = HttpClient.get(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("rows") != null) {
|
||||
return result.get("rows");
|
||||
} 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 = "/cardSendMt";
|
||||
try {
|
||||
for (String iccid : iccidList) {
|
||||
Map<String, String> dataMap = new HashMap<>();
|
||||
dataMap.put("iccid", iccid);
|
||||
dataMap.put("content", content);
|
||||
|
||||
String json = HttpClient.get(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 && "200".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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue