验证微信消息真实性 :param signature: 微信加密签名 :param timestamp: 时间戳 :param nonce: 随机数 :return: 通过验证返回 True, 未通过验证返回 False
(self, signature, timestamp, nonce)
| 90 | self.__request = request |
| 91 | |
| 92 | def check_signature(self, signature, timestamp, nonce): |
| 93 | """ |
| 94 | 验证微信消息真实性 |
| 95 | :param signature: 微信加密签名 |
| 96 | :param timestamp: 时间戳 |
| 97 | :param nonce: 随机数 |
| 98 | :return: 通过验证返回 True, 未通过验证返回 False |
| 99 | """ |
| 100 | if not signature or not timestamp or not nonce: |
| 101 | return False |
| 102 | |
| 103 | tmp_list = [self.conf.token, timestamp, nonce] |
| 104 | tmp_list.sort() |
| 105 | tmp_str = ''.join(tmp_list) |
| 106 | if signature != hashlib.sha1(tmp_str.encode('utf-8')).hexdigest(): |
| 107 | return False |
| 108 | |
| 109 | return True |
| 110 | |
| 111 | def generate_jsapi_signature(self, timestamp, noncestr, url, jsapi_ticket=None): |
| 112 | """ |