zoukankan      html  css  js  c++  java
  • 微信公众号开发-遇到的坑

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

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

    情景:配置如下截图:

    按照要求使用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
    
  • 相关阅读:
    html URLRewriter生成静态页不能访问
    sql server 2008 不允许保存更改,您所做的更改要求删除并重新创建以下表
    IIS7.0 伪静态页配置
    hubbledotnet 定时更新索引
    今天开通了这个BLOG。
    ASP.NET公有六种验证控件 功能描叙
    Recommend of the Day:Orkut社区和明星推荐
    每日英语:Why You Need a Dictator in a Marriage
    每日英语:An Unhappy Middle in the Middle Kingdom
    每日英语:Web Browsers Are Reinvented
  • 原文地址:https://www.cnblogs.com/ZJiQi/p/9045413.html
Copyright © 2011-2022 走看看