forked from anduinnn/HiFiNi-Auto-CheckIn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request anduinnn#41 from anduinnn/refactor/tg_bot-wechat-m…
…ethods Refactor/tg bot wechat methods
- Loading branch information
Showing
4 changed files
with
105 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package cloud.ohiyou.utils; | ||
|
||
import okhttp3.OkHttpClient; | ||
import okhttp3.Request; | ||
|
||
import java.net.URLEncoder; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class TelegramUtils { | ||
|
||
private static final OkHttpClient client = new OkHttpClient.Builder() | ||
.connectTimeout(30, TimeUnit.SECONDS) | ||
.readTimeout(30, TimeUnit.SECONDS) | ||
.writeTimeout(30, TimeUnit.SECONDS) | ||
.build(); | ||
|
||
|
||
/** | ||
* 微信公众号Service酱推送的key | ||
* @Author LisonFan | ||
* @Date&Time 2024/4/28 | ||
* @Migrate 银垚@mtouyao | ||
* @MigrateDate&Time 2024/6/5 | ||
* @param telegramChatId Telegram Chat ID | ||
* @param telegramBotToken Telegram Bot Token | ||
* @param messageText 签到信息 | ||
*/ | ||
public static void publishTelegramBot(String telegramChatId, String telegramBotToken, String messageText) { | ||
if (telegramChatId == null || telegramChatId.isEmpty() || telegramBotToken == null || telegramBotToken.isEmpty()) { | ||
System.out.println("TG_CHAT_ID 或 TG_BOT_TOKEN 环境变量未设置"); | ||
return; | ||
} | ||
|
||
try { | ||
String url = "https://api.telegram.org/bot" + telegramBotToken + "/sendMessage?chat_id=" + telegramChatId + "&text=" + URLEncoder.encode(messageText, "UTF-8"); | ||
Request request = new Request.Builder() | ||
.url(url) | ||
.build(); | ||
client.newCall(request).execute(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters