@Name : __sign @Desc:signs a given request URL when the apiKey and secretKey are known @Input: payload: dictionary of params be signed @Output: the signature of the payload
(self, payload)
| 130 | return self.__lastError |
| 131 | |
| 132 | def __sign(self, payload): |
| 133 | """ |
| 134 | @Name : __sign |
| 135 | @Desc:signs a given request URL when the apiKey and |
| 136 | secretKey are known |
| 137 | @Input: payload: dictionary of params be signed |
| 138 | @Output: the signature of the payload |
| 139 | """ |
| 140 | params = list(zip(list(payload.keys()), list(payload.values()))) |
| 141 | params.sort(key=lambda k: str.lower(k[0])) |
| 142 | hash_str = "&".join( |
| 143 | ["=".join( |
| 144 | [str.lower(r[0]), |
| 145 | str.lower( |
| 146 | urllib.parse.quote_plus(str(r[1]), safe="*") |
| 147 | ).replace("+", "%20")] |
| 148 | ) for r in params] |
| 149 | ) |
| 150 | signature = base64.encodebytes( |
| 151 | hmac.new(self.securityKey.encode('utf-8'), |
| 152 | hash_str.encode('utf-8'), |
| 153 | hashlib.sha1).digest()).strip() |
| 154 | return signature |
| 155 | |
| 156 | def __sendPostReqToCS(self, url, payload): |
| 157 | ''' |