Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 隐藏手机号中间 4 位 #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions process.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import requests
import hashlib
import logging

from shadow import shadow
AES_KEY = 'qbhajinldepmucsonaaaccgypwuvcjaa'
AES_IV = '2018534749963515'
SALT = '2af72f100c356273d46284f6fd1dfc08'
Expand Down Expand Up @@ -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)

# 如果是成功,推送消息简化;失败消息则全量推送
Expand Down Expand Up @@ -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}')
9 changes: 9 additions & 0 deletions shadow.py
Original file line number Diff line number Diff line change
@@ -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:]
12 changes: 12 additions & 0 deletions tests/test_shadow.py
Original file line number Diff line number Diff line change
@@ -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()