Skip to content

Commit

Permalink
Merge pull request #80 from taigongzhaihua/master
Browse files Browse the repository at this point in the history
✨新增适配中国银行微银行消费、退款、入账 #75 #68 #64 #62 #63 #58
  • Loading branch information
taigongzhaihua authored Apr 14, 2024
2 parents db0d42e + 152adfb commit d2be7e1
Show file tree
Hide file tree
Showing 8 changed files with 245 additions and 0 deletions.
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
);
}
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: '微信[中国银行-消费]'
}
]))
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": "交易成功提醒"
}
}
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": "交易成功提醒"
}
}
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": "交易成功提醒"
}
}
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": "交易成功提醒"
}
}
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": "交易成功提醒"
}
}
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": "交易成功提醒"
}
}

0 comments on commit d2be7e1

Please sign in to comment.