mirror of
https://github.com/pppscn/SmsForwarder
synced 2025-08-03 01:17:41 +08:00
修复:短信内容包含“<"字符时,用tg转发失败 #205
This commit is contained in:
parent
313bcd8bca
commit
a8feb97190
@ -52,7 +52,7 @@ class TelegramUtils private constructor() {
|
|||||||
} else {
|
} else {
|
||||||
val bodyMap: MutableMap<String, Any> = mutableMapOf()
|
val bodyMap: MutableMap<String, Any> = mutableMapOf()
|
||||||
bodyMap["chat_id"] = setting.chatId
|
bodyMap["chat_id"] = setting.chatId
|
||||||
bodyMap["text"] = content
|
bodyMap["text"] = htmlEncode(content)
|
||||||
bodyMap["parse_mode"] = "HTML"
|
bodyMap["parse_mode"] = "HTML"
|
||||||
bodyMap["disable_web_page_preview"] = "true"
|
bodyMap["disable_web_page_preview"] = "true"
|
||||||
val requestMsg: String = Gson().toJson(bodyMap)
|
val requestMsg: String = Gson().toJson(bodyMap)
|
||||||
@ -132,5 +132,23 @@ class TelegramUtils private constructor() {
|
|||||||
fun sendMsg(setting: TelegramSetting, msgInfo: MsgInfo) {
|
fun sendMsg(setting: TelegramSetting, msgInfo: MsgInfo) {
|
||||||
sendMsg(setting, msgInfo, null, null)
|
sendMsg(setting, msgInfo, null, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun htmlEncode(source: String?): String {
|
||||||
|
if (source == null) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
val buffer = StringBuffer()
|
||||||
|
for (element in source) {
|
||||||
|
when (element) {
|
||||||
|
'<' -> buffer.append("<")
|
||||||
|
'>' -> buffer.append(">")
|
||||||
|
'&' -> buffer.append("&")
|
||||||
|
'"' -> buffer.append(""")
|
||||||
|
//10, 13 -> buffer.append("\n")
|
||||||
|
else -> buffer.append(element)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return buffer.toString()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user