“蒋伟” 2 mesiacov pred
rodič
commit
79a6474a02
3 zmenil súbory, kde vykonal 74 pridanie a 21 odobranie
  1. 28 0
      common/encrypt.py
  2. 42 21
      conftest.py
  3. 4 0
      random1111.py

+ 28 - 0
common/encrypt.py

@@ -0,0 +1,28 @@
+import base64
+import json
+import time
+import uuid
+from Crypto.Cipher import AES
+
+
+def encrypt_padding(string: str, block_size: int) -> str:
+    length = len(string.encode('utf-8'))
+    add_length = block_size - (length % block_size)
+    return string + (chr(add_length) * add_length)
+
+
+def aes_encrypt(string: str, aes_key: str) -> str:
+    cipher = AES.new(aes_key.encode('utf-8'), AES.MODE_ECB)
+    cipher_text = cipher.encrypt(encrypt_padding(string, AES.block_size).encode('utf-8'))
+    cipher_text = base64.b64encode(cipher_text)
+    return cipher_text.decode()
+
+
+def genRat(url: str,emp:int) -> str:
+    mi = {
+        't': int(time.time() * 1000),
+        'w': str(uuid.uuid4()),
+        'r': url,
+        'u': emp
+    }
+    return aes_encrypt(json.dumps(mi), '253140fdc9c44b0cb903c387b3e85d64')

+ 42 - 21
conftest.py

@@ -11,38 +11,59 @@ path = Path(__file__).parent.glob("**/test_001_登录接口.yaml")
 for yaml_path1 in path:
     yaml_path = yaml_path1
 
-# path = Path(__file__).parent.glob("**/test_001_登录接口验证码.yaml")
-# for yaml_path1 in path:
-#     yzm_path = yaml_path1
+path = Path(__file__).parent.glob("**/test_001_登录获取key.yaml")
+for yaml_path1 in path:
+    yzm_path = yaml_path1
 
 
 @pytest.fixture(scope="session", autouse=True)
 def clear_yam():
     clear_yaml()
     clear_out_yaml()
-    login_system(yaml_path)
-
-
-def login_system(yaml_path: Path):
-    global i
-    data = read_testcase(yaml_path)
-    for i in data:
-        method = i['request'].pop("method")
-        url = read_config_yaml("base", "base_qccq_sc") + i['request'].pop("url")
-        # 发送请求
-        res = requests.request(method, url, **i['request'])
-        token = res.json()['data']["token"]
-        write_yaml({"token": token})
+    login_new()
+    # key_login(yzm_path)
+    # login_system(yaml_path)
 
 
-# def  yzm_login(yzm_path):
+#
+# def login_system(yaml_path: Path):
+#     global i
+#     data = read_testcase(yaml_path)
+#     for i in data:
+#         method = i['request'].pop("method")
+#         url = read_config_yaml("base", "base_qccq_sc") + i['request'].pop("url")
+#         # 发送请求
+#         res = requests.request(method, url, **i['request'])
+#         token = res.json()['data']["token"]
+#         write_yaml({"token": token})
+#
+#
+# def key_login(yzm_path):
 #     global i
 #     data = read_testcase(yzm_path)
 #     for i in data:
 #         method = i['request'].pop('method')
 #         url = read_config_yaml("base", "base_qccq_sc") + i['request'].pop("url")
-#         res = requests.request(method, url, **i['request'])
-#         print(111111111111111111,res)
-
-
+#         res = requests.request(method, url)
+#         write_yaml({"captchaKey": res.json()["data"]["captchaKey"]})
+#         write_yaml({"captcha": res.json()["data"]["length"]})
+def login_new():
+    url = "https://app.youth.cq.cqyl.org.cn/api/service-sysmgr/LoginController/getCaptchaLength?accountId=18983394419"
+    method = "get"
+    res = requests.request(method, url)
+    data = res.json()["data"]
 
+    url1 = "https://app.youth.cq.cqyl.org.cn/api/service-sysmgr/LoginController/login"
+    method1 = "post"
+    request_data = {
+        "captchaKey": data["captchaKey"],
+        "captcha": data["length"],
+        "mobile": "18983394419",
+        'password': "4E797559645371504E71767A563733444C2F7250785176504C79696231427977737073446347774A4C4A5631486A5231554B7455744B692B56423446673473562B4755504E737064767665674753445672334A6A4836434B447A336B6F63346F6C554654786D5467516768684D7661564A4D6B49327A75377A72535A6745746A4E546A535058344B39312B794A6C57634B4E45334E4F723043704E505031653145686C337033767330354D3D",
+        "scope": "PHONE",
+        "username": '18983394419'
+    }
+    print(request_data)
+    response = requests.request(url=url1, method=method1, json=request_data)
+    token = response.json()["data"]["token"]
+    write_yaml({"token": token})

+ 4 - 0
random1111.py

@@ -7,6 +7,7 @@ import time
 # import rsa as rsa
 import yaml
 
+from common.encrypt import genRat
 from common.request_util import *
 from common.yaml_util import read_yaml
 
@@ -96,3 +97,6 @@ class DubugTalk:
         from common.request_util import RequestUtil
         # last_data = RequestUtil(self).replace_value(last_data)
         print(last_data)
+
+    def genRat(self, url: str, emp: int):
+        return genRat(url, emp)