mirror of
https://github.com/pppscn/SmsForwarder
synced 2024-11-04 06:00:11 +00:00
修复:短信内容包含“<"字符时,用tg转发失败 #205
This commit is contained in:
parent
313bcd8bca
commit
a8feb97190
@ -52,7 +52,7 @@ class TelegramUtils private constructor() {
|
||||
} else {
|
||||
val bodyMap: MutableMap<String, Any> = mutableMapOf()
|
||||
bodyMap["chat_id"] = setting.chatId
|
||||
bodyMap["text"] = content
|
||||
bodyMap["text"] = htmlEncode(content)
|
||||
bodyMap["parse_mode"] = "HTML"
|
||||
bodyMap["disable_web_page_preview"] = "true"
|
||||
val requestMsg: String = Gson().toJson(bodyMap)
|
||||
@ -132,5 +132,23 @@ class TelegramUtils private constructor() {
|
||||
fun sendMsg(setting: TelegramSetting, msgInfo: MsgInfo) {
|
||||
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…
Reference in New Issue
Block a user