新增:webParams 的 [receive_time] 标签支持自定义时间格式 #327

This commit is contained in:
pppscn 2023-07-29 23:02:18 +08:00
parent 74c461f917
commit 2575363c38
2 changed files with 23 additions and 0 deletions

View File

@ -131,6 +131,9 @@ data class MsgInfo(
//替换{{APP名称}}标签
private fun replaceAppName(content: String, packageName: String): String {
if (TextUtils.isEmpty(content)) return content
if (content.indexOf(getString(R.string.tag_app_name)) == -1) return content
var appName = ""
if (SettingUtils.enableLoadUserAppList && App.UserAppList.isNotEmpty()) {
for (appInfo in App.UserAppList) {

View File

@ -101,6 +101,10 @@ class WebhookUtils {
.replace("[title]", URLEncoder.encode(simInfo, "UTF-8"))
.replace("[card_slot]", URLEncoder.encode(simInfo, "UTF-8"))
.replace("[receive_time]", URLEncoder.encode(receiveTime, "UTF-8"))
.replace(Regex("\\[receive_time:(.*?)\\]")) {
val format = it.groups[1]?.value ?: ""
formatDateTime(format)
}
.replace("\n", "%0A")
if (!TextUtils.isEmpty(setting.secret)) {
webParams = webParams.replace("[timestamp]", timestamp.toString())
@ -123,6 +127,10 @@ class WebhookUtils {
.replace("[title]", escapeJson(simInfo))
.replace("[card_slot]", escapeJson(simInfo))
.replace("[receive_time]", receiveTime)
.replace(Regex("\\[receive_time:(.*?)\\]")) {
val format = it.groups[1]?.value ?: ""
formatDateTime(format)
}
.replace("[timestamp]", timestamp.toString())
.replace("[sign]", sign)
Log.d(TAG, "method = ${setting.method}, Url = $requestUrl, bodyMsg = $bodyMsg")
@ -155,6 +163,10 @@ class WebhookUtils {
.replace("[title]", simInfo)
.replace("[card_slot]", simInfo)
.replace("[receive_time]", receiveTime)
.replace(Regex("\\[receive_time:(.*?)\\]")) {
val format = it.groups[1]?.value ?: ""
formatDateTime(format)
}
.replace("[timestamp]", timestamp.toString())
.replace("[sign]", sign)
)
@ -206,5 +218,13 @@ class WebhookUtils {
return if (jsonStr.length >= 2) jsonStr.substring(1, jsonStr.length - 1) else jsonStr
}
@SuppressLint("SimpleDateFormat")
fun formatDateTime(format: String): String {
val currentTime = Date()
val dateFormat = SimpleDateFormat(format)
dateFormat.timeZone = TimeZone.getTimeZone("UTC") // Optional: Set the desired timezone here
return dateFormat.format(currentTime)
}
}
}