feat: 增加公田移动Rabchaser页面接口调用

dev
huangfeng 11 months ago
parent 7285ede61c
commit c29ceac5e4

@ -3,6 +3,7 @@ package com.shxy.xymanager_common.sms;
import com.shxy.xymanager_common.constant.Constants;
import com.shxy.xymanager_common.sms.dahan.DahanApi;
import com.shxy.xymanager_common.sms.rabchaser.RabchaserApi;
import com.shxy.xymanager_common.sms.rabchaser.RabchaserWeb;
import com.shxy.xymanager_common.util.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@ -19,6 +20,8 @@ public class SmsAdapter {
DahanApi dahanApi;
@Resource
RabchaserApi rabchaserApi;
@Resource
RabchaserWeb rabchaserWeb;
public void sendSms(Integer type, List<String> iccidList, String content) {
if (Constants.NetType_Dahan.equals(type)) {
@ -32,6 +35,8 @@ public class SmsAdapter {
String today = DateUtil.format(new Date(), "yyyy-MM-dd");
if (Constants.NetType_Dahan.equals(type)) {
return dahanApi.smsRecord(iccid, today);
} else if (Constants.NetType_Rabchaser.equals(type)) {
rabchaserWeb.selectMsgReceive(iccid, today);
}
return null;
}

@ -0,0 +1,66 @@
package com.shxy.xymanager_common.sms.rabchaser;
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 javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;
@Service
@Slf4j
public class RabchaserWeb {
private String baseUrl = "http://www.rabchaser.com/api";
public static String authorization = "";
public Object selectMsgReceive(String iccid, String date) {
String url = "/cardquery/selectMsgReceiveByPage";
Map<String, String> headMap = new HashMap<>();
headMap.put("Authorization", authorization);
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("iccid", iccid);
// dataMap.put("receiveTime", date);
dataMap.put("pageNum", 1);
dataMap.put("pageSize", 10);
try {
HashMap<String, Object> result = null;
String json = HttpClient.post(baseUrl + url, dataMap, headMap);
log.info("查询短信记录完成: " + json);
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())) {
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());
}
}
@PostConstruct
private void login() {
String url = "/user/login";
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("loginName", "shxy");
dataMap.put("password", "Admin@123");
dataMap.put("rememberAccount", true);
try {
String json = HttpClient.post(baseUrl + url, dataMap, null);
log.info("login完成: " + json);
HashMap<String, Object> result = JSONUtil.json2Object(json, HashMap.class);
authorization = "Bearer " + result.get("data").toString();
} catch (Exception e) {
log.error("短信登入失败.", e);
}
}
}

@ -52,7 +52,7 @@ public class SmsServiceImpl implements SmsService {
} else if (Constants.NetType_Rabchaser.equals(simcard.getType2())) {
rabchaserList.add(simcard.getIccid2());
} else {
throw new ApiException(termId + "该装置的运营商类型type2暂不支持发短信");
throw new ApiException(termId + "该装置的运营商类型type2=" + simcard.getType2() + "暂不支持发短信");
}
}
@ -79,8 +79,10 @@ public class SmsServiceImpl implements SmsService {
}
if (Constants.NetType_Dahan.equals(simcard.getType2())) {
return smsAdapter.listSms(Constants.NetType_Dahan, simcard.getIccid2());
} else if (Constants.NetType_Rabchaser.equals(simcard.getType2())) {
return smsAdapter.listSms(Constants.NetType_Rabchaser, simcard.getIccid2());
} else {
throw new ApiException(termId + "该装置的运营商类型type2暂不支持查询短信");
throw new ApiException(termId + "该装置的运营商类型type2=" + simcard.getType2() + "暂不支持查询短信");
}
}
}

Loading…
Cancel
Save