Skip to content

Commit

Permalink
✨ (rule): 新增支付宝花呗支付规则及测试用例 #615
Browse files Browse the repository at this point in the history
新增支付宝花呗支付规则,包括解析交易提醒的JSON数据并生成账单对象。同时添加了相应的测试用例,确保规则解析的正确性。
  • Loading branch information
AnkioTomas committed Dec 28, 2024
1 parent 5041831 commit 2a570e4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { BillType, RuleObject, toFloat } from 'common/index.js';

export function get (data) {
let json = JSON.parse(data);
// 你有一笔43.73元的支出,点击领取4个支付宝积分。使用花呗支付,请及时还款。
let regex = /你有一笔([\d,]+.\d{2})元的支出,点击领取\d+个支付宝积分。使用花呗支付,请及时还款。/;
const match = json.text.match(regex);
if (!match) {
return null;
}
let [, money] = match;
let obj = new RuleObject();

obj.money = toFloat(money);
obj.channel = `支付宝花呗[支出]`;
obj.shopName = '支付宝';
obj.shopItem = json.text;
obj.time = json.t;

obj.type = BillType.Expend;

obj.accountNameFrom = `支付宝花呗`;
return obj;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { get } = require('./main');
const { testAnkio, testAnkioInit } = require('../../../../tests/TestUtils');
const { formatDate } = require('common/Time.js');

testAnkioInit(get, __dirname, 'com.eg.android.AlipayGphone');
test('支付宝花呗支付', () =>
testAnkio('支付宝花呗支付', [
{
'type': 'Expend',
'money': 43.73,
'fee': 0,
'shopName': '支付宝',
'shopItem': '你有一笔43.73元的支出,点击领取4个支付宝积分。使用花呗支付,请及时还款。',
'accountNameFrom': '支付宝花呗',
'accountNameTo': '',
'currency': 'CNY',
'time': 1734576048462,
'channel': '支付宝花呗[支出]'
}
]));
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"title":"交易提醒","text":"你有一笔43.73元的支出,点击领取4个支付宝积分。使用花呗支付,请及时还款。","t":1734576048462}

0 comments on commit 2a570e4

Please sign in to comment.