Ver código fonte

组织签名数据使用有序字典

locky 3 anos atrás
pai
commit
2e609f5033
1 arquivos alterados com 11 adições e 9 exclusões
  1. 11 9
      Object/UVerifyObject.py

+ 11 - 9
Object/UVerifyObject.py

@@ -9,6 +9,7 @@ import random
 import string
 import time
 import requests
+from collections import OrderedDict
 from datetime import datetime, timedelta
 
 
@@ -52,15 +53,16 @@ class UVerifyObject:
             value = sign_headers_dict[key]
             sign_headers_str = sign_headers_str + key + ':' + value + '\n'
 
-        sign_dict = {
-            'HTTPMethod': 'POST',
-            'Accept': 'application/json',
-            'Content-MD5': content_md5_str,
-            'Content-Type': 'application/json; charset=UTF-8',
-            'Date': None,
-            'Headers': sign_headers_str,
-            'Url': self.path_url + '?' + 'appkey=' + self.umeng_app_key,
-        }
+        # 需要使用有序字典,否则StringToSign错误
+        sign_dict = OrderedDict(
+            [('HTTPMethod', 'POST'),
+            ('Accept', 'application/json'),
+            ('Content-MD5', content_md5_str),
+            ('Content-Type', 'application/json; charset=UTF-8'),
+            ('Date', None,),
+            ('Headers', sign_headers_str),
+            ('Url', self.path_url + '?' + 'appkey=' + self.umeng_app_key)]
+        )
 
         string_to_sign = ""
         for key in sign_dict.keys():