From 045290b53b6251b59f5954e34735e20be44f0ef0 Mon Sep 17 00:00:00 2001 From: Jaxx4Fun <309329794@qq.com> Date: Fri, 23 Feb 2024 21:03:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=9A=90=E8=97=8F=E6=89=8B=E6=9C=BA?= =?UTF-8?q?=E5=8F=B7=E4=B8=AD=E9=97=B4=204=20=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Github Actions Job 的日志中会显示明文手机号,建议还是隐藏部分字段 --- process.py | 8 ++++---- shadow.py | 9 +++++++++ tests/test_shadow.py | 12 ++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 shadow.py create mode 100644 tests/test_shadow.py diff --git a/process.py b/process.py index 8657ae1e..fee1716f 100644 --- a/process.py +++ b/process.py @@ -10,7 +10,7 @@ import requests import hashlib import logging - +from shadow import shadow AES_KEY = 'qbhajinldepmucsonaaaccgypwuvcjaa' AES_IV = '2018534749963515' SALT = '2af72f100c356273d46284f6fd1dfc08' @@ -261,8 +261,8 @@ def reservation(params: dict, mobile: str): # if responses.status_code == 401: # send_msg('!!失败!!茅台预约', f'[{mobile}],登录token失效,需要重新登录') # raise RuntimeError - - msg = f'预约:{mobile};Code:{responses.status_code};Body:{responses.text};' + shadow_mobile = shadow(mobile) + msg = f'预约:{shadow_mobile};Code:{responses.status_code};Body:{responses.text};' logging.info(msg) # 如果是成功,推送消息简化;失败消息则全量推送 @@ -335,4 +335,4 @@ def getUserEnergyAward(mobile: str): headers=headers, json={}) # response.json().get('message') if '无法领取奖励' in response.text else "领取奖励成功" logging.info( - f'领取耐力 : mobile:{mobile} : response code : {response.status_code}, response body : {response.text}') + f'领取耐力 : mobile:{shadow(mobile)} : response code : {response.status_code}, response body : {response.text}') diff --git a/shadow.py b/shadow.py new file mode 100644 index 00000000..67fa1c3e --- /dev/null +++ b/shadow.py @@ -0,0 +1,9 @@ +""" Personal information protection """ + +def shadow(mobile: str): + length = len(mobile) + hidden_length = (length+1)//3 + first_length = (length - hidden_length)//2 + last_length = length - first_length - hidden_length + + return mobile[:first_length]+'*'*hidden_length+mobile[-last_length:] \ No newline at end of file diff --git a/tests/test_shadow.py b/tests/test_shadow.py new file mode 100644 index 00000000..72ba7dce --- /dev/null +++ b/tests/test_shadow.py @@ -0,0 +1,12 @@ +import unittest +from shadow import shadow +class TestShadow(unittest.TestCase): + def test_shadow(self): + self.assertEqual(shadow("12345678901"), "123****8901") + self.assertEqual(shadow("98765403210"), "987****3210") + self.assertEqual(shadow("11111111111"), "111****1111") + self.assertEqual(shadow("123456789"), "123***789") + self.assertEqual(shadow("987654321"), "987***321") + +if __name__ == '__main__': + unittest.main()