-
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.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
70e8ce8
commit 152adfb
Showing
8 changed files
with
245 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,85 @@ | ||
import { RuleObject } from "../../../../utils/RuleObject"; | ||
import { BillType } from "../../../../utils/BillType"; | ||
import { Currency } from "../../../../utils/Currency"; | ||
|
||
// 定义源名称和需要匹配的标题数组 | ||
const SOURCE_NAME_BOC = "中国银行微银行"; | ||
const TITLES_BOC = ["交易成功提醒"]; | ||
|
||
// 正则表达式和处理函数的映射关系 | ||
const regexMapBOC = new Map([ | ||
[/交易时间:(.*?)\n交易类型:(.*支付)(尾号(\d+))\n交易金额:(.*?) ([\d\,]+.\d{2})\n账户余额:.*元\n交易说明:点击查看更多详情/, (match) => ({ | ||
money: parseFloat(match[5].replace(",", "")), | ||
type: BillType.Expend, | ||
time: `${new Date().getFullYear()}年${match[1]}`, | ||
shopItem: match[2], | ||
accountNameFrom: `中国银行(${match[3]})`, | ||
Currency: Currency[match[4]], | ||
channel: '微信[中国银行-消费]' | ||
})], | ||
[/交易时间:(.*?)\n交易类型:(.*退款)(尾号(\d+))\n交易金额:(.*?) ([\d\,]+.\d{2})\n账户余额:.*元\n交易说明:点击查看更多详情/, (match) => ({ | ||
money: parseFloat(match[5].replace(",", "")), | ||
type: BillType.Income, | ||
time: `${new Date().getFullYear()}年${match[1]}`, | ||
shopItem: match[2], | ||
accountNameFrom: `中国银行(${match[3]})`, | ||
Currency: Currency[match[4]], | ||
channel: '微信[中国银行-退款]' | ||
})], | ||
[/交易时间:(.*?)\n交易类型:(.*入账)(尾号(\d+))\n交易金额:(.*?) ([\d\,]+.\d{2})\n账户余额:.*元\n交易说明:点击查看更多详情/, (match) => ({ | ||
money: parseFloat(match[5].replace(",", "")), | ||
type: BillType.Income, | ||
time: `${new Date().getFullYear()}年${match[1]}`, | ||
shopItem: match[2], | ||
accountNameFrom: `中国银行(${match[3]})`, | ||
Currency: Currency[match[4]], | ||
channel: '微信[中国银行-入账]' | ||
})] | ||
]); | ||
|
||
/** | ||
* 解析中国银行文本 | ||
* @param {string} text - 需要解析的文本 | ||
* @returns {Object|null} - 解析结果对象,如果解析失败则返回null | ||
*/ | ||
function parseBOCText(text) { | ||
for (let [regex, handler] of regexMapBOC) { | ||
const match = text.match(regex); | ||
if (match) { | ||
return handler(match); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* 获取中国银行规则对象 | ||
* @param {string} data - JSON格式的数据 | ||
* @returns {RuleObject|null} - 规则对象,如果获取失败则返回null | ||
*/ | ||
export function get(data) { | ||
const mapItem = JSON.parse(data).mMap; | ||
if (mapItem.source !== SOURCE_NAME_BOC || !TITLES_BOC.includes(mapItem.title)) { | ||
return null; | ||
} | ||
|
||
// 解析文本 | ||
const parsedText = parseBOCText(mapItem.description); | ||
if (!parsedText || parsedText.type === null) { | ||
return null; | ||
} | ||
|
||
// 创建并返回RuleObject对象 | ||
return new RuleObject( | ||
parsedText.type, | ||
parsedText.money, | ||
parsedText.shopName, | ||
parsedText.shopItem, | ||
parsedText.accountNameFrom , | ||
parsedText.accountNameTo , | ||
0, | ||
parsedText.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,88 @@ | ||
const { get } = require('./main'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const {testAnkioInit, testAnkio} = require("../../../../tests/TestUtils"); | ||
const {DataType} = require("../../../../utils/DataType"); | ||
|
||
testAnkioInit(get,__dirname,DataType.App,"com.tencent.mm") | ||
|
||
test("中国银行入账", () => testAnkio('中国银行入账',[ | ||
{ | ||
type: 1, | ||
money: 14800.00, | ||
fee: 0, | ||
shopName: '', | ||
shopItem: '银联入账', | ||
accountNameFrom: '中国银行(7575)', | ||
accountNameTo: '', | ||
currency: 'CNY', | ||
time: "2024年04月12日18:12", | ||
channel: '微信[中国银行-入账]' | ||
} | ||
])) | ||
|
||
test("中国银行退款", () => testAnkio('中国银行退款',[ | ||
{ | ||
type: 1, | ||
money: 1000.00, | ||
fee: 0, | ||
shopName: '', | ||
shopItem: '网上快捷退款', | ||
accountNameFrom: '中国银行(7575)', | ||
accountNameTo: '', | ||
currency: 'CNY', | ||
time: "2024年04月13日13:02", | ||
channel: '微信[中国银行-退款]' | ||
} | ||
])) | ||
|
||
test("中国银行消费", () => testAnkio('中国银行消费',[ | ||
{ | ||
type: 0, | ||
money: 1000, | ||
fee: 0, | ||
shopName: '', | ||
shopItem: '网上快捷支付', | ||
accountNameFrom: "中国银行(7575)", | ||
accountNameTo: '', | ||
currency: 'CNY', | ||
time: "2024年04月13日13:02", | ||
channel: '微信[中国银行-消费]' | ||
}, | ||
{ | ||
type: 0, | ||
money: 31.78, | ||
fee: 0, | ||
shopName: '', | ||
shopItem: '网上快捷支付', | ||
accountNameFrom: '中国银行(7575)', | ||
accountNameTo: '', | ||
currency: 'CNY', | ||
time: "2024年04月12日18:28", | ||
channel: '微信[中国银行-消费]' | ||
}, | ||
{ | ||
type: 0, | ||
money: 1000, | ||
fee: 0, | ||
shopName: '', | ||
shopItem: '网上快捷支付', | ||
accountNameFrom: '中国银行(7575)', | ||
accountNameTo: '', | ||
currency: 'CNY', | ||
time: "2024年04月64日64:02", | ||
channel: '微信[中国银行-消费]' | ||
}, | ||
{ | ||
type: 0, | ||
money: 30, | ||
fee: 0, | ||
shopName: '', | ||
shopItem: '网上快捷支付', | ||
accountNameFrom: "中国银行(0464)", | ||
accountNameTo: '', | ||
currency: 'CNY', | ||
time: "2024年04月12日19:04", | ||
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,12 @@ | ||
{ | ||
"mMap": { | ||
"tableName": "AppMessage", | ||
"description": "交易时间:04月12日18:12\n交易类型:银联入账(尾号7575)\n交易金额:人民币 14,800.00\n账户余额:14,800.11元\n交易说明:点击查看更多详情", | ||
"source": "中国银行微银行", | ||
"arg": "msgId", | ||
"type": 5, | ||
"appId": "", | ||
"msgId": 98807, | ||
"title": "交易成功提醒" | ||
} | ||
} |
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": "交易时间:04月13日13:02\n交易类型:网上快捷支付(尾号7575)\n交易金额:人民币 1,000.00\n账户余额:1,023,768.33元\n交易说明:点击查看更多详情", | ||
"source": "中国银行微银行", | ||
"arg": "msgId", | ||
"type": 5, | ||
"appId": "", | ||
"msgId": 98962, | ||
"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": "交易时间:04月12日18:28\n交易类型:网上快捷支付(尾号7575)\n交易金额:人民币 31.78\n账户余额:74,768.33元\n交易说明:点击查看更多详情", | ||
"source": "中国银行微银行", | ||
"arg": "msgId", | ||
"type": 5, | ||
"appId": "", | ||
"msgId": 98837, | ||
"title": "交易成功提醒" | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/rule/app/com.tencent.mm/微信公众号中国银行微银行/tests/中国银行消费3.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": "交易时间:04月64日64:02\n交易类型:网上快捷支付(尾号7575)\n交易金额:人民币 1,000.00\n账户余额:64,768.33元\n交易说明:点击查看更多详情", | ||
"source": "中国银行微银行", | ||
"arg": "msgId", | ||
"type": 5, | ||
"appId": "", | ||
"msgId": 98962, | ||
"title": "交易成功提醒" | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/rule/app/com.tencent.mm/微信公众号中国银行微银行/tests/中国银行消费4.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": "交易时间:04月12日19:04\n交易类型:网上快捷支付(尾号0464)\n交易金额:人民币 30.00\n账户余额:8.93元\n交易说明:点击查看更多详情", | ||
"source": "中国银行微银行", | ||
"arg": "msgId", | ||
"type": 5, | ||
"appId": "", | ||
"msgId": 291485, | ||
"title": "交易成功提醒" | ||
} | ||
} |
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": "交易时间:04月13日13:02\n交易类型:网上快捷退款(尾号7575)\n交易金额:人民币 1,000.00\n账户余额:93,177.48元\n交易说明:点击查看更多详情", | ||
"source": "中国银行微银行", | ||
"arg": "msgId", | ||
"type": 5, | ||
"appId": "", | ||
"msgId": 99092, | ||
"title": "交易成功提醒" | ||
} | ||
} |