diff --git a/china_unicom.py b/china_unicom.py index 3863aca..cbe2162 100644 --- a/china_unicom.py +++ b/china_unicom.py @@ -5,7 +5,7 @@ # @Time : 2022/8/10 13:23 # ------------------------------- """ -联通app抽奖 入口:app首页下拉 话费派送中 +联通app抽奖 入口:联通app 搜索 阅读专区 进入话费派送中 1. 脚本仅供学习交流使用, 请在下载后24h内删除 2. 需要第三方库 pycryptodome 支持 命令行安装 pip3 install pycryptodome或者根据自己环境自行安装 3. 环境变量说明 PHONE_NUM(必需) UNICOM_LOTTER(选填) 自行新建环境变量添加 diff --git a/tools/rsa_encrypt.py b/tools/rsa_encrypt.py index 4edc2bc..b215943 100644 --- a/tools/rsa_encrypt.py +++ b/tools/rsa_encrypt.py @@ -4,21 +4,29 @@ # @Author : github@limoruirui https://github.com/limoruirui # @Time : 2022/8/23 13:05 # ------------------------------- -from Crypto.PublicKey.RSA import importKey +from Crypto.PublicKey.RSA import importKey, construct from Crypto.Cipher import PKCS1_v1_5 from base64 import b64encode + class RSA_Encrypt: def __init__(self, key): if isinstance(key, str): # 若提供的rsa公钥不为pem格式 则先将hex转化为pem格式 - self.key = bytes.fromhex(key) if "PUBLIC KEY" not in key else key.encode() + # self.key = bytes.fromhex(key) if "PUBLIC KEY" not in key else key.encode() + self.key = self.public_key(key) if "PUBLIC KEY" not in key else key.encode() else: print("提供的公钥格式不正确") - def Encrypt(self, data, b64=False): + + def public_key(self, rsaExponent, rsaModulus=10001): + e = int(rsaExponent, 16) + n = int(rsaModulus, 16) # snipped for brevity + pubkey = construct((n, e)).export_key() + return pubkey + + def encrypt(self, data, b64=False): pub_key = importKey(self.key) cipher = PKCS1_v1_5.new(pub_key) rsa_text = cipher.encrypt(data.encode("utf8")) rsa_text = b64encode(rsa_text).decode() if b64 else rsa_text.hex() return rsa_text -# print(b64encode(bytes.fromhex("00A828DB9D028A4B9FC017821C119DFFB8537ECEF7F91D4BC06DB06CC8B4E6B2D0A949B66A86782D23AA5AA847312D91BE07DC1430C1A6F6DE01A3D98474FE4511AAB7E4E709045B61F17D0DC4E34FB4BE0FF32A04E442EEE6B326D97E11AE8F23BF09926BF05AAF65DE34BB90DEBDCEE475D0832B79586B4B02DEED2FC3EA10B3".lower())).decode()) \ No newline at end of file diff --git a/tools/send_msg.py b/tools/send_msg.py index 52d6099..2c16c48 100644 --- a/tools/send_msg.py +++ b/tools/send_msg.py @@ -6,12 +6,14 @@ # ------------------------------- from requests import post from json import dumps +from sys import path +path.append("./tools") from tool import get_environ -tg_userId = get_environ("TG_USER_ID") -tgbot_token = get_environ("TG_BOT_TOKEN") -tg_push_api = get_environ("TG_API_HOST") -pushplus_token = get_environ("PUSH_PLUS_TOKEN") +tg_userId = get_environ("TG_USER_ID", "", False) +tgbot_token = get_environ("TG_BOT_TOKEN", "", False) +tg_push_api = get_environ("TG_API_HOST", "", False) +pushplus_token = get_environ("PUSH_PLUS_TOKEN", "", False) def tgpush(title, content): url = f"https://api.telegram.org/bot{tgbot_token}/sendMessage" @@ -37,8 +39,8 @@ def pushplus(title, content): post(url, headers=headers, data=dumps(data)) except: print('推送失败') -def push(self, title, content): +def push(title, content): if pushplus_token != "": - self.pushplus(title, content) + pushplus(title, content) if tgbot_token != "" and tg_userId != "": - self.tgpush(title, content) \ No newline at end of file + tgpush(title, content) \ No newline at end of file diff --git a/tools/tool.py b/tools/tool.py index 7641dd8..aaf00e1 100644 --- a/tools/tool.py +++ b/tools/tool.py @@ -73,5 +73,9 @@ def hmac_sha1(data, key): # 封装读取环境变量的方法 -def get_environ(key, default=""): - return environ.get(key) if environ.get(key) else default +def get_environ(key, default="", output=True): + def no_read(): + if output: + print_now(f"未填写环境变量 {key} 请添加") + return default + return environ.get(key) if environ.get(key) else no_read()