2 Commits 58584ff29d ... c3b88479bb

Autor SHA1 Mensagem Data
  hjdhnx c3b88479bb 优化base_request支持传data 2 meses atrás
  hjdhnx d9d6507bb2 修复T4数据可能中文乱码问题 2 meses atrás
2 arquivos alterados com 25 adições e 13 exclusões
  1. 4 2
      app/t4/files/drpy_js/老白故事[听].js
  2. 21 11
      app/utils/vod_tool.py

+ 4 - 2
app/t4/files/drpy_js/老白故事[听].js

@@ -262,7 +262,8 @@ var rule = {
         headers['Content-Type'] = 'application/x-www-form-urlencoded';
         let html = post(appData.api_url, {
             headers: headers,
-            body: post_data,
+            // body: post_data,
+            data: post_obj,
         });
         let content = JSON.parse(html);
         var datas = content.data;
@@ -306,7 +307,8 @@ var rule = {
         headers['Content-Type'] = 'application/x-www-form-urlencoded';
         let html = post(appData.api_url, {
             headers: headers,
-            body: post_data,
+            // body: post_data,
+            data: post_obj,
         });
         let content = JSON.parse(html);
         var datas = content.data;

+ 21 - 11
app/utils/vod_tool.py

@@ -3,6 +3,7 @@
 # File  : vod_tool.py
 # Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------
 # Date  : 2024/2/5
+import re
 
 import ujson
 from time import time
@@ -55,11 +56,19 @@ def base_request(_url, _object, _js_type=0, cloudfare=False):
         timeout = round(timeout / 1000, 2)
     # print(f'timeout:{timeout}')
     body = _object.get('body') or ''
+    encoding = _object.get('encoding') or 'utf-8'
     data = _object.get('data') or {}
-    headers = _object.get('headers') or {}
-    headers = dict(headers)
-    for key, value in headers.items():
-        headers[key] = str(value)
+    _headers = _object.get('headers') or {}
+    _headers = dict(_headers)
+    headers = {}
+    for key, value in _headers.items():
+        headers[str(key).lower()] = str(value)
+
+    if headers.get('content-type') and re.search('charset=(.*)', headers['content-type'], re.I):
+        try:
+            encoding = re.search('charset=(.*)', headers['content-type'], re.I).groups()[0]
+        except:
+            pass
 
     if body and not data:
         if '&' in body:
@@ -74,21 +83,22 @@ def base_request(_url, _object, _js_type=0, cloudfare=False):
 
     elif not body and data and method != 'get':
         content_type_keys = [key for key in headers if key.lower() == 'content-type']
-        content_type = 'application/json'
+        default_type = 'application/json'
+        content_type = default_type
         if content_type_keys:
             content_type_key = content_type_keys[-1]
             old_content_type = headers[content_type_key]
-            if content_type not in old_content_type:
-                headers[content_type_key] = content_type
+            # if content_type not in old_content_type:
+            #     headers[content_type_key] = content_type
+            content_type = old_content_type
         else:
-            headers['Content-Type'] = content_type
+            headers['Content-Type'] = default_type
 
-        if isinstance(data, dict):
+        if isinstance(data, dict) and default_type in content_type:
             data = ujson.dumps(data, ensure_ascii=False)
-    encoding = _object.get('encoding') or 'utf-8'
+
     buffer = _object.get('buffer') or 1
     redirect = False if _object.get('redirect') == 0 or _object.get('redirect') == False else True
-
     withHeaders = bool(_object.get('withHeaders') or False)
     r = None
     r_text = ''