Skip to content

Commit

Permalink
新增:webParams 的 [receive_time] 标签支持自定义时间格式 #327
Browse files Browse the repository at this point in the history
  • Loading branch information
pppscn committed Jul 29, 2023
1 parent 74c461f commit 2575363
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/src/main/java/com/idormy/sms/forwarder/entity/MsgInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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")
Expand Down Expand Up @@ -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)
)
Expand Down Expand Up @@ -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)
}

}
}

0 comments on commit 2575363

Please sign in to comment.