微信config:invalid signature
config:invalid signature是微信的签名错误
官网关于签名生成的规则:参与签名的字段包括noncestr(随机字符串), 有效的jsapi_ticket, timestamp(时间戳), url(当前网页的URL,不包含#及其后面部分) 。对所有待签名参数按照字段名的ASCII 码从小到大排序(字典序)后,使用URL键值对的格式(即key1=value1&key2=value2…)拼接成字符串string1。这里需要注意的是所有参数名均为小写字符。对string1作sha1加密,字段名和字段值都采用原始值,不进行URL 转义。
1、noncestr(随机字符串)
随机字符串这个基本不会错误,只需要注意确认config中nonceStr(js中驼峰标准大写S), timestamp与用以签名中的对应noncestr, timestamp一致。
2、有效的jsapi_ticket
这个需要特别注意:
(1)、有效的时间是7200s,也就是两个小时,所以官方文档建议进行本地存储;
(2)、由于jsapi_ticket的请求参数access_token也存在有效时间7200s,也需要做本地存储;
(3)、请求access_token的参数appId和secret这两个参数不要混淆,基本不会出错;
(4)、确认 config 中的 appid 与用来获取 jsapi_ticket 的 appid 一致;
(5)、确保一定缓存access_token和jsapi_ticket。
3、timestamp(时间戳)
生成一个时间戳的字符串,基本不会错误。
4、url(当前网页的URL,不包含#及其后面部分)
(1)、确认url是页面完整的url;
(2)、当前网页的URL;
(3)、不包含#及其后面部分
注意:
确保你获取用来签名的url是动态获取的。如果是html的静态页面在前端通过ajax将url传到后台签名,前端需要用js获取当前页面除去'#'hash部分的链接(可用window.location.href.split('#')[0]获取,而且需要encodeURIComponent),因为页面一旦分享,微信客户端会在你的链接末尾加入其它参数,如果不是动态获取当前链接,将导致分享后的页面签名失败。
重要的事情说三遍:
URL、动态获取的URL和当前URL(除‘#’及以后的参数)必须一致。
URL、动态获取的URL和当前URL(除‘#’及以后的参数)必须一致。
URL、动态获取的URL和当前URL(除‘#’及以后的参数)必须一致。
5、签名参数按照字段名的ASCII 码从小到大排序
6、使用URL键值对的格式(即key1=value1&key2=value2…)拼接成字符串string(注意的是所有参数名均为小写字符)
7、对string作sha1加密
这样基本避免了可能犯错的地方,config:invalid signature错误也基本都可以解决了。
其他
[我的博客,欢迎交流!](http://rattenking.gitee.io/stone/index.html)
[我的CSDN博客,欢迎交流!](https://blog.csdn.net/m0_38082783)
[微信小程序专栏](https://blog.csdn.net/column/details/18335.html)
[前端笔记专栏](https://blog.csdn.net/column/details/18321.html)
[微信小程序实现部分高德地图功能的DEMO下载](http://download.csdn.net/download/m0_38082783/10244082)
[微信小程序实现MUI的部分效果的DEMO下载](http://download.csdn.net/download/m0_38082783/10196944)
[微信小程序实现MUI的GIT项目地址](https://github.com/Rattenking/WXTUI-DEMO)
[微信小程序实例列表](http://blog.csdn.net/m0_38082783/article/details/78853722)
[前端笔记列表](http://blog.csdn.net/m0_38082783/article/details/79208205)
[游戏列表](http://blog.csdn.net/m0_38082783/article/details/79035621)
相关文章
- UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xd3 in position 5: invalid continuation byte
- IDEA Android 打包APK报错:“Invalid keystore format”解决方法
- 二则 ORA-01722: invalid number错误的处理,substr to_char之间的区别。连接符号错误 + ||
- 微信小程序 - [警告] Setting data field “xxxx“ to undefined is invalid. 解决方案
- MySQL Invalid default value for datetime
- uwsgi 服务 invalid request block size: 4161 (max 4096)...skip问题的解决
- {"errcode":40097,"errmsg":"invalid args hint: [vjNe7xxxxxx8vr19]"}——记录一次微信错误处理
- dubbo-admin-2.5.3 运行报错: Bean property 'URIType' is not writable or has an invalid 解决方法
- 微信上传图文消息invalid media_id hint,thumb_media_id怎么获取
- 转 pip离线复制python开发环境 以及报错invalid syntax 和 cx_oracle 处理clob
- Tomcat 8 Invalid character found in the request target. The valid characters are defined in RFC 3986
- Gson本地和服务器环境不同遇到的Date转换问题 Failed to parse date []: Invalid time zone indicator
- Invalid command 'WSGIScriptAlias', perhaps misspelled or defined by a module not included in the ser
- odoo15 UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xcb in position 8: invalid continuation
- [未解决]报错:UnicodeDecodeError: 'utf-8' codec can't decode byte 0x87 in position 0: invalid start byte
- EF:Invalid column name 'Discriminator'.