• 微信公众号开发-遇到的坑


    博文图片挂了临时解决办法

    在配置后端服务器时,报错 "系统发生错误,请稍后重试"

    情景:配置如下截图:

    按照要求使用http标准80端口,但是提交就报错。在服务端抓包,根本没收到请求。那这个报错就是微信公众平台没有发送过来呀。
    折腾了半个小时!
    我去,发现不能在url中指定80端口,就可以成功,如下图:

    这样不指定端口才正确。微信说明还是不是很明确

    在handle模块,实例代码是py2代码,py3中要进行编码转换

    • 微信开发文档的代码,在py3中执行会一直报token验证错误。
    # -*- coding: utf-8 -*-
    # filename: handle.py
    
    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 = "xxxx" #请按照公众平台官网基本配置中信息填写
    
                list = [token, timestamp, nonce]
                list.sort()
                sha1 = hashlib.sha1()
                map(sha1.update, list)  # 这里list中的字符串在py2中是符合sha1.update要求的
                hashcode = sha1.hexdigest()
                print "handle/GET func: hashcode, signature: ", hashcode, signature
                if hashcode == signature:
                    return echostr
                else:
                    return ""
            except Exception, Argument:
                return Argument
    
    • py3修改后的
    """
    handle.py
    """
    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 = "****"   # 自己定义的tokent
    
                list = [token, timestamp, nonce]
                list.sort()
                sha1 = hashlib.sha1()
                sha1.update(''.join(list).encode('utf-8'))  # 将py3中的字符串编码为bytes类型
                hashcode = sha1.hexdigest()
                print("handle/GET func: hashcode, signature:", hashcode, signature)
                if hashcode == signature:
                    return echostr
                else:
                    return ""
            except Exception as e:
                print(e)
    
    
    if __name__ == '__main__':
        pass
    
  • 相关阅读:
    Auto Mapper01
    一个ActionResult中定位到两个视图—<团委项目>
    网站根目录的问题
    数据库基础和断点调试
    linux 环境下jmeter+ant+jenkins
    Postman 下载和使用
    用ExtentReports美化你的测试报告
    extentreports报告插件与testng集成
    SourceTree使用图解
    charles4.2下载与破解方法以及配置https
  • 原文地址:https://www.cnblogs.com/ZJiQi/p/9045413.html
Copyright © 2020-2023  润新知