Compare commits
2 Commits
cb5fdf5676
...
50d7f0a07f
Author | SHA1 | Date |
---|---|---|
吴顺杰 | 50d7f0a07f | 2 months ago |
吴顺杰 | 3a38a3eb9b | 2 months ago |
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.yingji</groupId>
|
||||
<artifactId>yingjiAlgorithms</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>utils</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
|
||||
</project>
|
@ -0,0 +1,64 @@
|
||||
package com.utils;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 短信通知工具类
|
||||
*
|
||||
* @author wu
|
||||
* @since 2024/9/24 10:18
|
||||
*/
|
||||
public class SmsUtil {
|
||||
|
||||
/**
|
||||
* 获取短信接口token
|
||||
*
|
||||
* @return token
|
||||
*/
|
||||
public static String getSmsToken() {
|
||||
Map<String, Object> bodyMap = new HashMap<>();
|
||||
bodyMap.put("uid", "yjglj_yjjyszzh");
|
||||
bodyMap.put("pwd", "f604d2d6de51573b5cef5c95c11ffabe");
|
||||
String bodyJson = JSONUtil.toJsonStr(bodyMap);
|
||||
String responseStr = HttpRequest.post("http://2.46.42.43:80/admin-api/sms/token")
|
||||
.body(bodyJson)
|
||||
.execute()
|
||||
.body();
|
||||
JSONObject responseJson = JSONUtil.parseObj(responseStr);
|
||||
return (String) responseJson.get("data");
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送短信
|
||||
*
|
||||
* @param content 短信内容
|
||||
* @param tel 手机号多个使用,拼接
|
||||
* @return 响应类
|
||||
*/
|
||||
public static Object sendSms(String content, String tel) {
|
||||
String token = getSmsToken();
|
||||
Map<String, Object> bodyMap = new HashMap<>();
|
||||
bodyMap.put("uid", "yjglj_yjjyszzh");
|
||||
bodyMap.put("pwd", "f604d2d6de51573b5cef5c95c11ffabe");
|
||||
bodyMap.put("extensionNo", "2559");
|
||||
if (StrUtil.isNotEmpty(tel)) {
|
||||
bodyMap.put("tel", tel);
|
||||
} else {
|
||||
bodyMap.put("tel", "18870257135,18261462112,15850922852,18112760590");
|
||||
}
|
||||
bodyMap.put("content", "市应急局提醒: " + content);
|
||||
String bodyJson = JSONUtil.toJsonStr(bodyMap);
|
||||
String responseStr = HttpRequest.post("http://2.46.42.43:80/admin-api/sms/send")
|
||||
.header("Authorization", token)
|
||||
.body(bodyJson)
|
||||
.execute()
|
||||
.body();
|
||||
return JSONUtil.parseObj(responseStr);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue