feat: 增加公田移动Rabchaser短信发送功能
parent
465e6389d3
commit
0eb041966b
@ -0,0 +1,53 @@
|
||||
package com.shxy.xymanager_common.sms.rabchaser;
|
||||
|
||||
import com.shxy.xymanager_common.exception.ApiException;
|
||||
import com.shxy.xymanager_common.util.DigestUtils;
|
||||
import com.shxy.xymanager_common.util.HttpClient;
|
||||
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 RabchaserApi {
|
||||
|
||||
private String baseUrl = "http://www.rabchaser.com/iotapi/v1";
|
||||
private String appId = "h74tbgvq7YgstDF";
|
||||
private String appKey = "Jx1!9Np*fD95xl5n1S1!oo&15eWl9W";
|
||||
|
||||
|
||||
private Map<String, String> signHead(String url) throws Exception {
|
||||
String nonceStr = "ibuaiVcKdpRxkhJA";
|
||||
Map<String, String> map = new HashMap<>();
|
||||
String timestamp = String.valueOf(System.currentTimeMillis());
|
||||
map.put("appId", appId);
|
||||
map.put("timestamp", timestamp);
|
||||
map.put("nonceStr", nonceStr);
|
||||
String sign = "appId=" + appId + "&nonceStr=" + nonceStr + "×tamp=" + timestamp
|
||||
+ "&key=" + appKey;
|
||||
String md5 = DigestUtils.md5(sign).toUpperCase();
|
||||
map.put("sign", md5);
|
||||
return map;
|
||||
}
|
||||
|
||||
public void sendSms(List<String> iccidList, String content) {
|
||||
String url = "/simCards/sendSms";
|
||||
try {
|
||||
Map<String, String> headMap = this.signHead(url);
|
||||
Map<String, Object> dataMap = new HashMap<>();
|
||||
dataMap.put("iccid", iccidList);
|
||||
dataMap.put("message", content);
|
||||
|
||||
String json = HttpClient.post(baseUrl + url, dataMap, headMap);
|
||||
log.info("发送短信完成:" + json);
|
||||
} catch (ApiException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
log.error("发送短信异常.", e);
|
||||
throw new ApiException("发送短信异常," + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue