Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_check_signature_should_ok(self):
token = 'test'
signature = 'f21891de399b4e33a1a93c9a7b8a8fffb5a443ff'
timestamp = '1410685589'
nonce = 'test'
check_signature(token, signature, timestamp, nonce)
def on_get(self, req, resp):
query_string = req.query_string
query_list = query_string.split('&')
b = {}
for i in query_list:
b[i.split('=')[0]] = i.split('=')[1]
try:
check_signature(token='lengxiao', signature=b['signature'], timestamp=b['timestamp'], nonce=b['nonce'])
resp.body = (b['echostr'])
except InvalidSignatureException:
pass
resp.status = falcon.HTTP_200
def get(self):
"""完成url输入之后,微信验证url有效性"""
signature = self.request.arguments.get('signature', '')
timestamp = self.request.arguments.get('timestamp', '')
nonce = self.request.arguments.get('nonce', '')
echo_str = self.request.arguments.get('echostr', '')
try:
token_check()
check_signature(ACCESS_TOKEN, signature, timestamp, nonce)
except InvalidSignatureException:
self.set_status(403)
self.write(echo_str)
def handle(self, **kwargs):
entry = wx_client.wxenv(request.env)
request.entry = entry
self.crypto = entry.crypto_handle
self.token = entry.wx_token
_logger.info('>>> %s'%request.params)
msg_signature = request.params.get('msg_signature', '')
signature = request.params.get('signature', '')
timestamp = request.params.get('timestamp', '')
nonce = request.params.get('nonce', '')
encrypt_type = request.params.get('encrypt_type', 'raw')
try:
check_signature(
self.token,
signature,
timestamp,
nonce
)
except InvalidSignatureException:
return abort(403)
if request.httprequest.method == 'GET':
return request.params.get('echostr', '')
# POST
msg = None
if encrypt_type == 'raw':
# plaintext mode
def wechat():
signature = request.args.get('signature', '')
timestamp = request.args.get('timestamp', '')
nonce = request.args.get('nonce', '')
echo_str = request.args.get('echostr', '')
try:
check_signature(TOKEN, signature, timestamp, nonce)
except InvalidSignatureException:
abort(403)
if request.method == 'GET':
return echo_str
else:
msg = parse_message(request.data)
if msg.type == 'text':
reply = create_reply(msg.content, msg)
else:
reply = create_reply('Sorry, can not handle this for now', msg)
return reply.render()
def handle(self, **kwargs):
entry = app_client.appenv(request.env)
self.crypto = entry.crypto_handle
self.token = entry.token
_logger.info('>>> %s'%request.params)
msg_signature = request.params.get('msg_signature', '')
timestamp = request.params.get('timestamp', '')
nonce = request.params.get('nonce', '')
encrypt_type = request.params.get('encrypt_type', 'raw')
if request.httprequest.method == 'GET':
try:
echo_str = check_signature(
self.token,
request.params.get('signature', ''),
timestamp,
nonce
)
except InvalidSignatureException:
return abort(403)
return request.params.get('echostr', '')
# POST
if encrypt_type == 'raw':
# plaintext mode
msg = parse_message(request.httprequest.data)
else:
# encryption mode
msg = None
def _wechat_required(method, *args, **kwargs):
from wechatpy.crypto import WeChatCrypto
from wechatpy import parse_message
signature = request.args.get('signature')
timestamp = request.args.get('timestamp')
nonce = request.args.get('nonce')
if not current_app.config.get('WECHAT_TOKEN'):
return abort(500, "Token is None")
token = current_app.config['WECHAT_TOKEN']
try:
check_signature(token, signature, timestamp, nonce)
except InvalidSignatureException:
current_app.logger.warning('check signature failed.')
return abort(403)
if request.method == 'GET':
return request.args.get('echostr', '')
raw_msg = request.data
current_app.logger.debug(raw_msg)
if current_app.config.get('WECHAT_AES_KEY'):
crypto = WeChatCrypto(
current_app.config['WECHAT_TOKEN'],
current_app['WECHAT_AES_KEY'],
current_app.config['WECHAT_APPID']
)
try:
def get(self):
echostr = self.get_argument('echostr', '')
signature = self.get_argument('signature', '')
timestamp = self.get_argument('timestamp', '')
nonce = self.get_argument('nonce', '')
try:
check_signature(options.token, signature, timestamp, nonce)
except InvalidSignatureException:
logging.warning("Signature check failed.")
else:
logging.info("Signature check success.")
self.write(echostr)