From 88cf855268a05a68bb4570c6d45841bbe23fe5ec Mon Sep 17 00:00:00 2001
From: cloudroam <cloudroam>
Date: 星期五, 25 四月 2025 13:44:26 +0800
Subject: [PATCH] 短信
---
app/src/main/java/com/example/firstapp/MainActivity.kt | 271 +++++++++++------------------------------------------
1 files changed, 59 insertions(+), 212 deletions(-)
diff --git a/app/src/main/java/com/example/firstapp/MainActivity.kt b/app/src/main/java/com/example/firstapp/MainActivity.kt
index 585212b..5dced23 100644
--- a/app/src/main/java/com/example/firstapp/MainActivity.kt
+++ b/app/src/main/java/com/example/firstapp/MainActivity.kt
@@ -33,6 +33,7 @@
import java.util.Date
import java.util.Locale
import android.app.AlertDialog
+import com.example.firstapp.utils.CodeUtils
class MainActivity : AppCompatActivity() {
// 安全防护关键词数组
@@ -286,12 +287,6 @@
val msg = Msg(0, "1111", "111111", messageBody, 1, "111", 1, 1)
val msgId = Core.msg.insert(msg)
- // 禁用关键词拦截
-// if (securityKeywordsList.any { it in messageBody }) {
-// android.util.Log.d("MainActivity", "历史短信含有禁用关键词,跳过处理")
-// continue
-// }
-
// 使用协程处理API调用和数据库操作
CoroutineScope(Dispatchers.IO).launch {
try {
@@ -302,224 +297,76 @@
if (response.status == "success") {
when (response.data.category) {
"快递" -> {
- val pickupCode = response.data.details.pickupCode ?: ""
- if (pickupCode.isNotEmpty()) {
- val existingCode =
- Core.code.queryByTypeAndCodeAndDate(
- response.data.category,
- pickupCode,
- dateString
- )
-
- if (existingCode == null) {
- val code = Code(
- id = 0,
- category = response.data.category,
- categoryId = 1,
- typeId = 1,
- ruleId = 1,
- msgId = msgId,
- createTime = dateString,
- oneLevel = response.data.details.post ?: "",
- secondLevel = response.data.details.company
- ?: "未知",
- code = pickupCode,
- pickup = 0,
- pickupTime = "",
- overTime = "",
- address = response.data.details.address
- ?: "",
- remarks = response.data.details.time ?: "",
- )
-// if(code.oneLevel.isNotEmpty() && code.secondLevel.isNotEmpty() && code.code.isNotEmpty()) {
- if (code.oneLevel.isNotEmpty() && code.code.isNotEmpty()) {
- Core.code.insert(code)
- android.util.Log.d(
- "MainActivity",
- "历史快递短信已保存: $pickupCode"
- )
- }
- } else {
- android.util.Log.d(
- "MainActivity",
- "发现重复快递短信,跳过保存: $pickupCode"
- )
- }
- }
+ val code = CodeUtils.createExpressCode(
+ msgId = msgId,
+ createTime = dateString,
+ post = response.data.details.post,
+ company = response.data.details.company,
+ pickupCode = response.data.details.pickupCode,
+ address = response.data.details.address,
+ time = response.data.details.time,
+ smsTimestamp = datetime // 添加短信时间戳
+ )
+ CodeUtils.saveCode(code)
}
"还款" -> {
- val amount = response.data.details.amount ?: ""
- if (amount.isNotEmpty()) {
- val existingCode =
- Core.code.queryByTypeAndCodeAndDate(
- response.data.category, amount, dateString
- )
-
- if (existingCode == null) {
- val code = Code(
- id = 0,
- category = response.data.category,
- categoryId = 2,
- typeId = 1,
- ruleId = 2,
- msgId = msgId,
- createTime = dateString,
- oneLevel = response.data.details.type ?: "",
- secondLevel = response.data.details.bank
- ?: "未知",
- code = amount,
- pickup = 0,
- pickupTime = "",
- overTime = response.data.details.date ?: "",
- address = response.data.details.address
- ?: "",
- remarks = "最小还款金额${response.data.details.min_amount}还款卡号${response.data.details.number}"
- )
- if (code.oneLevel.isNotEmpty() && code.secondLevel.isNotEmpty() && code.code.isNotEmpty()) {
- Core.code.insert(code)
- android.util.Log.d(
- "MainActivity",
- "历史还款短信已保存: $amount"
- )
- }
- } else {
- android.util.Log.d(
- "MainActivity",
- "发现重复还款短信,跳过保存: $amount"
- )
- }
- }
+ val code = CodeUtils.createRepaymentCode(
+ msgId = msgId,
+ createTime = dateString,
+ type = response.data.details.type,
+ bank = response.data.details.bank,
+ amount = response.data.details.amount,
+ date = response.data.details.date,
+ address = response.data.details.address,
+ minAmount = response.data.details.min_amount,
+ number = response.data.details.number,
+ smsTimestamp = datetime // 添加短信时间戳
+ )
+ CodeUtils.saveCode(code)
}
"收入" -> {
- val amount = response.data.details.amount ?: ""
- if (amount.isNotEmpty()) {
- val existingCode =
- Core.code.queryByTypeAndCodeAndDate(
- response.data.category, amount, dateString
- )
-
- if (existingCode == null) {
- val code = Code(
- id = 0,
- category = response.data.category,
- categoryId = 3, // 3-收入类型
- typeId = 1, //暂时没有根据type分类
- ruleId = 2, //1-还款类型
- msgId = msgId,
- createTime = dateString,
- oneLevel = response.data.details.bank ?: "",
- secondLevel = response.data.details.bank
- ?: "未知",
- code = amount,
- pickup = 0, // 0-未取件,1-已取件
- pickupTime = "", // 取件时间为空
- overTime = response.data.details.datetime
- ?: "", // 超时时间为空,暂时没有这块处理逻辑
- address = response.data.details.address
- ?: "",
- remarks = "余额" + response.data.details.balance
- ?: "",
- )
- if (code.oneLevel.isNotEmpty() && code.secondLevel.isNotEmpty() && code.code.isNotEmpty()) {
- Core.code.insert(code)
- android.util.Log.d(
- "MainActivity",
- "历史还款短信已保存: $amount"
- )
- }
- } else {
- android.util.Log.d(
- "MainActivity",
- "发现重复还款短信,跳过保存: $amount"
- )
- }
- }
+ val code = CodeUtils.createIncomeCode(
+ msgId = msgId,
+ createTime = dateString,
+ bank = response.data.details.bank,
+ amount = response.data.details.amount,
+ datetime = response.data.details.datetime,
+ address = response.data.details.address,
+ balance = response.data.details.balance,
+ smsTimestamp = datetime // 添加短信时间戳
+ )
+ CodeUtils.saveCode(code)
}
"航班" -> {
- val flight = response.data.details.flight ?: ""
- if (flight.isNotEmpty()) {
- val existingCode =
- Core.code.queryByTypeAndCodeAndDate(
- response.data.category, flight, dateString
- )
-
- if (existingCode == null) {
- val code = Code(
- id = 0,
- category = response.data.category,
- categoryId = 4, // 4-航班类型
- typeId = 1, //暂时没有根据type分类
- ruleId = 2, //1-还款类型
- msgId = msgId,
- createTime = dateString,
- oneLevel = response.data.details.company
- ?: "未知",
- secondLevel = response.data.details.start + response.data.details.end
- ?: "",
- code = flight,
- pickup = 0, // 0-未取件,1-已取件
- pickupTime = "", // 取件时间为空
- overTime = response.data.details.time
- ?: "", // 超时时间为空,暂时没有这块处理逻辑
- address = response.data.details.address
- ?: "",
- remarks = response.data.details.seat ?: "",
- )
- if (code.oneLevel != "" && code.secondLevel != "" && code.code != "") {
- Core.code.insert(code)
- }
- } else {
- android.util.Log.d(
- "MainActivity",
- "发现重复还款短信,跳过保存: $flight"
- )
- }
- }
+ val code = CodeUtils.createFlightCode(
+ msgId = msgId,
+ createTime = dateString,
+ company = response.data.details.company,
+ start = response.data.details.start,
+ end = response.data.details.end,
+ seat = response.data.details.seat,
+ time = response.data.details.time,
+ address = response.data.details.address,
+ smsTimestamp = datetime // 添加短信时间戳
+ )
+ CodeUtils.saveCode(code)
}
"火车票" -> {
- val seat = response.data.details.seat ?: ""
- if (seat.isNotEmpty()) {
- val existingCode =
- Core.code.queryByTypeAndCodeAndDate(
- response.data.category, seat, dateString
- )
-
- if (existingCode == null) {
- val code = Code(
- id = 0,
- category = response.data.category,
- categoryId = 5, // 5-火车票类型
- typeId = 1, //暂时没有根据type分类
- ruleId = 2, //1-还款类型
- msgId = msgId,
- createTime = dateString,
- oneLevel = response.data.details.company
- ?: "",
- secondLevel = response.data.details.company
- ?: "未知",
- code = seat,
- pickup = 0, // 0-未取件,1-已取件
- pickupTime = "", // 取件时间为空
- overTime = response.data.details.time
- ?: "", // 超时时间为空,暂时没有这块处理逻辑
- address = response.data.details.address
- ?: "",
- remarks = response.data.details.trips ?: "",
- )
- if (code.oneLevel != "" && code.secondLevel != "" && code.code != "") {
- Core.code.insert(code)
- }
- } else {
- android.util.Log.d(
- "MainActivity",
- "发现重复还款短信,跳过保存: $seat"
- )
- }
- }
+ val code = CodeUtils.createTrainTicketCode(
+ msgId = msgId,
+ createTime = dateString,
+ company = response.data.details.company,
+ seat = response.data.details.seat,
+ time = response.data.details.time,
+ address = response.data.details.address,
+ trips = response.data.details.trips,
+ smsTimestamp = datetime // 添加短信时间戳
+ )
+ CodeUtils.saveCode(code)
}
}
--
Gitblit v1.9.3