当前位置:网站首页>Config:invalid signature solution and troubleshooting details
Config:invalid signature solution and troubleshooting details
2022-07-06 22:28:00 【a_ Jing】
First verify whether the signature is valid
1. obtain access_token, Fill in appid and secret You can get
Wechat public platform interface debugging tool

2. adopt access_token obtain jsapi_ticket , The following link is placed in the browser ,you_access_token Replace with the one you just got access_token You can get jsapi_ticket
3. On wechat JS Interface signature verification tool , Get signature . If you get it here signature And what you got signature Agreement , Just to prove your signature That's right. . Then check the problem of domain name setting , as follows :
WeChat JS Interface signature verification tool
https://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=jsapisign
JSSDK Use steps
Step one : Bind domain name
First log in to wechat public platform “ Setting of public number ” Of “ Feature set ” Fill in “JS Interface security domain name ”.
remarks : Log in to “ Developer center ” View the corresponding interface permissions .
Step two : introduce JS file
Call when needed JS The interface page is introduced as follows JS file ,( Support https):http://res.wx.qq.com/open/js/jweixin-1.6.0.js
To further improve service stability , When the above resources are not accessible , Modifiable access :http://res2.wx.qq.com/open/js/jweixin-1.6.0.js ( Support https).
remarks : Support use AMD/CMD Standard module loading method loading
Step three : adopt config Interface injection authority validation configuration
All required JS-SDK The page must be filled with configuration information first , Otherwise, it will not be called ( The same url Just one call , For changes url Of SPA Of web app But every time url Call when changing , at present Android Wechat client does not support pushState Of H5 New characteristics , So use pushState To achieve web app A page that is not signed will cause the signature to fail , This problem will be solved in Android6.2 Medium repair ).
wx.config({
debug: true, // Turn on debugging mode , Call all api The return value of will be on the client side alert come out , To see the parameters passed in , Can be in pc End open , The parameter information will go through log play , Only in pc Only when the end is printed .
appId: '', // Required , The only sign of official account number
timestamp: , // Required , Generate signature timestamp
nonceStr: '', // Required , Generate a random string of signatures
signature: '',// Required , Signature
jsApiList: [] // Required , Required JS Interface list
});
See the signature algorithm at the end of the text appendix 1, all JS See appendix 2
Be careful : If you are using Applet cloud development static website hosting Domain name web page , You can skip any legal compliance applet directly without authentication , call wx.config when appId You need to fill in the certified applet of the non personal subject , No need to calculate the signature ,timestamp、nonceStr、signature Fill in any non empty value .
Step four : adopt ready Interface processing successfully verified
wx.ready(function(){
// config It will be executed after information verification ready Method , All interface calls must be in the config After the interface gets the result ,config Is an asynchronous operation of a client , So if you need to call the relevant interface when the page is loaded , The relevant interface shall be ready The function is used to ensure proper execution. . Interface called only when triggered by the user , You can call , No need to put ready Function .
});
Step five : adopt error Interface processing failed validation
wx.error(function(res){
// config Information validation failure will be executed error function , If the signature expires and the verification fails , Specific error messages can be opened config Of debug Mode view , You can also go back to res View in parameters , about SPA You can update your signature here .
});
Interface call description
All interfaces through wx object ( You can also use jWeixin object ) To call , Parameter is an object , In addition to the parameters that each interface needs to pass , There are also the following general parameters :
- success: The callback function that is executed when the interface calls successfully .
- fail: The callback function executed when an interface call fails .
- complete: The callback function executed when the interface call completes , It will be carried out regardless of success or failure .
- cancel: Callback function when the user clicks cancel , Only some of them are cancelled by users api Will be used .
- trigger: monitor Menu The method of triggering when the button in , This method only supports Menu Related interfaces in .
remarks : Don't try to be in trigger Use in ajax Asynchronous request to modify the shared content , Because the client sharing operation is a synchronous operation , Use at this time ajax The return package has not been returned .
All of the above functions take a parameter , Type as object , In addition to the data returned by each interface itself , There is also a common attribute errMsg, The value format is as follows :
When the call succeeds :"xxx:ok" , among xxx Is the interface name of the call
When user cancels :"xxx:cancel", among xxx Is the interface name of the call
When the call fails : Its value is the specific error message
Common mistakes and Solutions
call config Pass in parameters when using the interface debug: true Can be opened debug Pattern , Page meeting alert Error message . Here are some common mistakes and solutions :
invalid url domain The domain name of the current page and the appid No binding , Please confirm to fill in the bound domain name correctly , Support only 80(http) and 443(https) Two ports , Therefore, there is no need to fill in the port number ( One appid You can bind three valid domain names , see ] Catalog 1.1.1).
invalid signature Signature error . It is recommended to check in the following order :
Make sure the signature algorithm is correct , You can use WeChat JS Interface signature verification tool Page tools to verify .
confirm config in nonceStr(js Middle hump standard capital S), timestamp Corresponding to in a signature noncestr , timestamp Agreement .
confirm url The page is complete url( Please on the current page alert(location.href.split('#')[0]) confirm ), Include
'http(s)://'part , as well as '?' hinder GET Parameters of the part , But does not include '#'hash Back section .confirm config Medium appid And used to obtain jsapi_ticket Of appid Agreement .
Make sure there's a cache access_token and jsapi_ticket.
Make sure you get the url It's dynamic , Dynamic page can be seen in the example code php How to implement . If it is html Static page in front through ajax take url Send it to the backstage for signature , The front end needs to use js Get the current page '#'hash Partial links ( You can use location.href.split('#')[0] obtain , And they need encodeURIComponent), Because once the page is shared , Wechat client will add other parameters at the end of your link , If it is not dynamic, get the current link , It will cause the page signature after sharing to fail .
the permission value is offline verifying This mistake is because config Not executed correctly , Or called JSAPI There was no introduction config Of jsApiList Parameters in . It is recommended to check in the following order :
confirm config Pass correctly .
If it is called when the page is loaded JSAPI, It must be written in wx.ready In the callback .
confirm config Of jsApiList Parameter contains this JSAPI.
permission denied The official account has no access to this. JSAPI, Or called JSAPI There was no introduction config Of jsApiList Parameters in ( Some interfaces can only be used after authentication ).
function not exist The interface is not supported by the current client version , Please upgrade to the new experience .
Why? 6.0.1 edition config:ok, however 6.0.2 Not after version ok( because 6.0.2 No permission verification before version , therefore config All are ok, But that doesn't mean you config The signature in is OK Of , Please be there. 6.0.2 Verify that the correct signature is generated to ensure config In higher versions, too ok.)
stay iOS and Android Can't share ( Please confirm that the official account has been certified. , The official account number only has the right to share the relevant interfaces. , If it has been certified , Check whether the listening interface is wx.ready Triggered in callback function )
The service cannot be obtained after it is online jsapi_ticket, No problem when testing by yourself .( because access_token and jsapi_ticket You must cache on your own server , Otherwise, the frequency limit will be triggered after online . Please make sure you are right token and ticket Do caching to reduce 2 Secondary server request , Not only can trigger frequency limit be avoided , And speed up your own service . At present, in order to facilitate the test 1w Acquisition of , After exceeding the threshold , The service will no longer be available , Please ensure that the global cache must be before the service goes online access_token and jsapi_ticket, Both are valid for 7200 second , Otherwise, once online, trigger the frequency limit , The service will no longer be available ).
uploadImage How to transmit multiple pictures ( Currently, only one upload is supported at a time , Multiple pictures need to wait until the previous picture is uploaded before calling this interface )
Cannot preview locally selected pictures (chooseImage The interface itself supports preview , No additional support is required )
adopt a link ( For example, first log in through wechat authorization ) Jump to b link ,invalid signature Signature failed ( The link that generates the signature in the background is used jssdk Current link to , That is, after the jump b link , Please do not use the authorization link of wechat login for signature calculation , Signed backstage url It must be using jssdk Full of the current page url remove '#' part )
appear config:fail error ( This is due to incoming config Incomplete parameters lead to , Make sure you pass in the correct appId、timestamp、nonceStr、signature And what you need to use jsApiList)
How to make jsapi The multimedia resources uploaded to wechat are downloaded to their own servers ( See the documentation uploadVoice and uploadImage Remarks of interface )
Android adopt jssdk Upload to wechat server , The third party downloads it from wechat to its own server , There will be noise ( The wechat team has fixed this problem , At present, the background has been optimized and launched )
Bind parent domain name , Is its subdomain also available ( Yes , Legal child domain names are fully supported after binding the parent domain name )
stay iOS WeChat 6.1 In the version , Shared pictures are not displayed outside the chain , It can only display pictures in the official account page or pictures of WeChat server. , Already in 6.2 Medium repair
Do you need to be compatible with the lower version (jssdk Are compatible with lower versions , No additional work needs to be done by a third party , But some interfaces are 6.0.2 Newly introduced , Only the new version can be called )
The official account is invalid. , The transaction cannot be initiated ( Please make sure you use jweixin.js It's the official online version , It can not only reduce user traffic , It's also possible for some bug Make repairs , Copy to a third-party server for use , The authorities will not guarantee any problems , Please refer to the specific payment signature algorithm JSSDK Wechat payment column )
at present Android Wechat client does not support pushState Of H5 New characteristics , So use pushState To achieve web app A page that is not signed will cause the signature to fail , The problem already exists Android6.2 Medium repair
uploadImage stay chooseImage Sometimes in callbacks Android Will not perform ,Android6.2 Will solve this problem , If you need to support lower versions, you can call uploadImage Put it in setTimeout Medium delay 100ms solve
require subscribe The error indicates that you have not subscribed to the test number , This error occurs only for the test number
getLocation The returned coordinates are openLocation There is a deviation , because getLocation The return is gps coordinate ,openLocation The open Tencent map is the coordinates of Mars , A third party needs to make the conversion itself ,6.2 The version has supported direct acquisition of Mars coordinates
Check the official account ( Not added ): "menuItem:addContact" No display , Only links that are transmitted from official account can be displayed. , The source must be the official account.
ICP Filing data synchronization is delayed for one day , So please bind on the second day
边栏推荐
- Self made j-flash burning tool -- QT calls jlinkarm DLL mode
- BarcodeX(ActiveX打印控件) v5.3.0.80 免费版使用
- NPDP certification | how do product managers communicate across functions / teams?
- Leetcode question brushing (XI) -- sequential questions brushing 51 to 55
- Insert sort and Hill sort
- Management background --4, delete classification
- [leetcode daily clock in] 1020 Number of enclaves
- Solve project cross domain problems
- C # réalise la liaison des données du rapport Crystal et l'impression du Code à barres 4
- 变量与“零值”的比较
猜你喜欢

Barcodex (ActiveX print control) v5.3.0.80 free version

HDR image reconstruction from a single exposure using deep CNNs阅读札记

0 basic learning C language - interrupt

Advantages of link local address in IPv6
![[linear algebra] determinant of order 1.3 n](/img/6e/54f3a994fc4c2c10c1036bee6715e8.gif)
[linear algebra] determinant of order 1.3 n

软考高级(信息系统项目管理师)高频考点:项目质量管理

C#实现水晶报表绑定数据并实现打印4-条形码

2022-07-04 mysql的高性能数据库引擎stonedb在centos7.9编译及运行

第3章:类的加载过程(类的生命周期)详解

云原生技术--- 容器知识点
随机推荐
3DMAX assign face map
NetXpert XG2帮您解决“布线安装与维护”难题
LeetCode刷题(十一)——顺序刷题51至55
Management background --1 Create classification
第4章:再谈类的加载器
数据处理技巧(7):MATLAB 读取数字字符串混杂的文本文件txt中的数据
Web APIs DOM time object
Aardio - 不声明直接传float数值的方法
OpenCV VideoCapture. Get() parameter details
CCNA-思科网络 EIGRP协议
ZABBIX proxy server and ZABBIX SNMP monitoring
C#实现水晶报表绑定数据并实现打印4-条形码
UE4蓝图学习篇(四)--流程控制ForLoop和WhileLoop
i. Mx6ull build boa server details and some of the problems encountered
Oracle control file and log file management
qt quick项目offscreen模式下崩溃的问题处理
Memorabilia of domestic database in June 2022 - ink Sky Wheel
Management background --5, sub classification
(十八)LCD1602实验
【LeetCode】19、 删除链表的倒数第 N 个结点
https://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=jsapisign