Skip to content

Commit

Permalink
python 0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenZhongPu committed Jun 4, 2022
1 parent 966d60e commit 71f60a5
Show file tree
Hide file tree
Showing 8 changed files with 238 additions and 0 deletions.
78 changes: 78 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST


# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/


# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
.python-version

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/


# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/

.DS_Store
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Zhongpu

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# CheckReg
It can check whether a given email or phone number has been registered in websites.

## Install

```shell
pip install checkreg-zhongpu
```

## Supported Websites

### [dangdang](http://www.dangdang.com/)

```python
from checkreg import dangdang
x = dangdang.check_phone('138xxxxxxxx')
```

The result `x` is a dictionary. For example,

```python
{'statusCode': '0', 'errorCode': '0', 'errorMsg': None, 'if_exist': True, 'cust_id': '744073637'}
```

## License
MIT.
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools>=42"]
build-backend = "setuptools.build_meta"
27 changes: 27 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[metadata]
name = checkreg-zhongpu
version = 0.0.2
author = Zhongpu Chen
author_email = [email protected]
description = A package to check whether it has been registered
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/ChenZhongPu/checkReg
project_urls =
Bug Tracker = https://github.com/ChenZhongPu/checkReg/issues
classifiers =
Programming Language :: Python :: 3
License :: OSI Approved :: MIT License
Operating System :: OS Independent

[options]
package_dir =
= src
packages = find:
python_requires = >=3.6
install_requires =
pycryptodome
requests

[options.packages.find]
where = src
Empty file added src/checkreg/__init__.py
Empty file.
31 changes: 31 additions & 0 deletions src/checkreg/aes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from Crypto.Cipher import AES
import base64
UTF8 = 'UTF-8'


class AESTool:
def __init__(self, key, iv):
self.key = key.encode(UTF8)
self.iv = iv.encode(UTF8)

def pkcs7padding(self, text):
bs = 16
length = len(text)
bytes_length = len(text.encode(UTF8))
padding_size = length if (bytes_length == length) else bytes_length
padding = bs - padding_size % bs
padding_text = chr(padding) * padding
return text + padding_text

def aes_encrypt(self, content):
cipher = AES.new(self.key, AES.MODE_CBC, self.iv)
content_padding = self.pkcs7padding(content)
encrypt_bytes = cipher.encrypt(content_padding.encode(UTF8))
result = str(base64.b64encode(encrypt_bytes), encoding=UTF8)
return result

def aes_decrypt(self, content):
cipher = AES.new(self.key, AES.MODE_CBC, self.iv)
content = base64.b64decode(content)
text = cipher.decrypt(content).decode(UTF8)
return self.pkcs7padding(text)
52 changes: 52 additions & 0 deletions src/checkreg/dangdang.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import datetime
import time
import requests
import hashlib
from urllib.parse import urlencode
from .aes import AESTool

BASE_URL = "https://login.dangdang.com"
P_PERMANENT_ID = 'permanent_id'
P_T = 't'
P_CT = 'ct'
P_STATUS_CODE = 'statusCode'
P_REQUEST_ID = 'requestId'
P_RANKEY = 'rankey'
P_SIGN = 'sign'
UTF8 = 'UTF-8'
AES_IV = '0102030405060708'


def permanent_id():
now = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
return f'{now}00000000000'


def request_key(permanent):
data = {P_PERMANENT_ID: permanent, P_T: int(time.time() * 1000)}
ran_key_url = '/api/customer/loginapi/getRankey'
x = requests.post(f'{BASE_URL}{ran_key_url}', data=data).json()
assert x[P_STATUS_CODE] == '0', 'Error when getting random key!'
return x[P_REQUEST_ID], x[P_RANKEY]


def check_phone(phone_number):
permanent = permanent_id()
request_id, random_key = request_key(permanent)

data = {P_CT: "pc", "mobile_phone": phone_number,
P_PERMANENT_ID: permanent,
P_REQUEST_ID: request_id,
P_T: int(time.time() * 1000)}
data = {k: data[k] for k in sorted(data)}
param = urlencode(data)
md5 = hashlib.md5()
md5.update(param.encode(UTF8))
data_md5 = md5.hexdigest()
aes_tool = AESTool(random_key, AES_IV)
sign = aes_tool.aes_encrypt(data_md5)
data[P_SIGN] = sign
verify_phone = '/api/customer/loginapi/verifyMobilePhone'
x = requests.post(f'{BASE_URL}{verify_phone}', data=data).json()
assert x[P_STATUS_CODE] == '0', 'Error when verifying'
return x

0 comments on commit 71f60a5

Please sign in to comment.