-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Peter Jones
committed
Apr 14, 2024
1 parent
ae4353a
commit 2e0cbb4
Showing
4 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { RuleObject } from "../../../../utils/RuleObject"; | ||
import { BillType } from "../../../../utils/BillType"; | ||
import { Currency } from "../../../../utils/Currency"; | ||
|
||
const SOURCE_NAME = "招商银行信用卡"; | ||
const TITLES = ["交易成功提醒"]; | ||
|
||
// 定义正则表达式,用于匹配交易时间、交易类型、交易金额、交易商户和可用额度 | ||
const regex = /交易时间:尾号(\d+)信用卡(\d{2}月\d{2}日\d{2}:\d{2})\n交易类型:(.*?)\n交易金额:(\d+\.\d{2})(.*?)\n交易商户:(.*?)\n可用额度:.*/; | ||
|
||
/** | ||
* 解析招商银行信用卡消费文本 | ||
* @param {string} text - 需要解析的文本 | ||
* @returns {Object|null} - 解析结果对象,如果解析失败则返回null | ||
*/ | ||
function parseCMBText(text) { | ||
const match = text.match(regex); | ||
if (!match) return null; | ||
|
||
const [, cardNumber, time, type, money, currency, shopName] = match; | ||
const currentYear = new Date().getFullYear(); // 获取当前年份 | ||
return { | ||
accountNameFrom: `招商银行信用卡(${cardNumber})`, | ||
time: `${currentYear}年${time}`, | ||
type: type === '消费' ? BillType.Expend : null, | ||
money: parseFloat(money), | ||
shopName: shopName, | ||
Currency: Currency[currency], | ||
Channel:`微信[招行信用卡${type}]` | ||
}; | ||
} | ||
|
||
/** | ||
* 获取招商银行信用卡消费规则对象 | ||
* @param {string} data - JSON格式的数据 | ||
* @returns {RuleObject|null} - 规则对象,如果获取失败则返回null | ||
*/ | ||
export function get(data) { | ||
const mapItem = JSON.parse(data).mMap; | ||
if (mapItem.source !== SOURCE_NAME || !TITLES.includes(mapItem.title)) { | ||
return null; | ||
} | ||
|
||
const parsedText = parseCMBText(mapItem.description); | ||
if (!parsedText || parsedText.type === null) return null; | ||
|
||
return new RuleObject( | ||
parsedText.type, | ||
parsedText.money, | ||
parsedText.shopName, | ||
parsedText.shopItem, | ||
parsedText.accountNameFrom, | ||
"", | ||
0, | ||
Currency['人民币'], | ||
parsedText.time, | ||
parsedText.Channel | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const { get } = require('./main'); | ||
const {testAnkioInit, testAnkio} = require("../../../../tests/TestUtils"); | ||
const {DataType} = require("../../../../utils/DataType"); | ||
|
||
testAnkioInit(get,__dirname,DataType.App,"com.tencent.mm") | ||
|
||
test("招商银行信用卡消费", () => testAnkio('招商银行信用卡消费',[ | ||
{ | ||
type: 0, | ||
money: 34.69, | ||
shopName: '美团-牛约堡手(旭辉店)', | ||
shopItem: '', | ||
accountNameFrom: '招商银行信用卡(1356)', | ||
accountNameTo: '', | ||
fee: 0, | ||
currency: 'CNY', | ||
time: "2024年04月11日18:05", | ||
channel: '微信[招行信用卡消费]' | ||
}, | ||
{ | ||
type: 0, | ||
money: 19.68, | ||
shopName: '美团-奉天熏六记熏拌鸡架(马坡店)', | ||
shopItem: '', | ||
accountNameFrom: '招商银行信用卡(1356)', | ||
accountNameTo: '', | ||
fee: 0, | ||
currency: 'CNY', | ||
time: "2024年04月12日10:53", | ||
channel: '微信[招行信用卡消费]' | ||
} | ||
])) |
12 changes: 12 additions & 0 deletions
12
src/rule/app/com.tencent.mm/微信公众号招商银行信用卡/tests/招商银行信用卡消费.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"mMap": { | ||
"tableName": "AppMessage", | ||
"description": "交易时间:尾号1356信用卡04月11日18:05\n交易类型:消费\n交易金额:34.69人民币\n交易商户:美团-牛约堡手(旭辉店)\n可用额度:¥11383815.03", | ||
"source": "招商银行信用卡", | ||
"arg": "msgId", | ||
"type": 5, | ||
"appId": "", | ||
"msgId": 98372, | ||
"title": "交易成功提醒" | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/rule/app/com.tencent.mm/微信公众号招商银行信用卡/tests/招商银行信用卡消费2.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"mMap": { | ||
"tableName": "AppMessage", | ||
"description": "交易时间:尾号1356信用卡04月12日10:53\n交易类型:消费\n交易金额:19.68人民币\n交易商户:美团-奉天熏六记熏拌鸡架(马坡店)\n可用额度:¥24695.35", | ||
"source": "招商银行信用卡", | ||
"arg": "msgId", | ||
"type": 5, | ||
"appId": "", | ||
"msgId": 98505, | ||
"title": "交易成功提醒" | ||
} | ||
} |