微信公众号 ——开发者基本配置(Python3)

https://developers.weixin.qq.com/doc/offiaccount/Getting_Started/Getting_Started_Guide.html

这是微信开启公众号开发的新手指引,不过他使用的是python2,有些地方不对,尤其是哈希加密那部分,导致验证一直不通过,参考了https://blog.csdn.net/qq_39866513/article/details/83218731这位博主,终于改好通过了!!!

以下是代码部分,首先是main.py

import web
from handle import Handle

urls = (
	'/wx' , 'Handle',
	)



if __name__ == '__main__':
	app = web.application(urls,globals())
	app.run()

接着是处理部分

import hashlib
import web

class Handle(object):
    def GET(self):
        try:
            data = web.input()
            if len(data) == 0:
                return "hello, this is handle view"
            signature = data.signature
            timestamp = data.timestamp
            nonce = data.nonce
            echostr = data.echostr
            token = "balaba" #
            print(signature,token,timestamp,nonce,echostr)

            list = [token, timestamp, nonce]
            list.sort()
            sha1 = hashlib.sha1()
            sha1.update(list[0].encode("utf-8"))
            sha1.update(list[1].encode("utf-8"))
            sha1.update(list[2].encode("utf-8"))
            hashcode = sha1.hexdigest()
            print( "handle/GET func: hashcode, signature: ", hashcode, signature)
            if hashcode == signature:
                return echostr
            else:
                return ""
        except (Exception) as Argument:
            return Argument

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值