We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
话说这问题其实早在2016年末就已经遇到过了,没想到时隔接近一年,这次又重回微信开发,遇到了更坑爹的情况。 下文所有的情况都是基于SPA html5 history所讨论,其他情况不列入在内,比如终结方案就是不用 history 路由。 首先吐槽一下微信文档,我认为微信团队根本没把心思花在这个上面,包括小程序也是一样,不管API还是文档,都写的很烂。
SPA html5 history
说实话配置签名还算是简单,不过官方给的demo质量也也太差了,相信大部分人都是复制粘贴的,下面贴一个质量稍微高一点的php签名算法。 客户端只需要把window.location.href发来即可。
window.location.href
$sParams = [ 'noncestr' => uniqid('wjs_'), 'jsapi_ticket' => $jsapi_ticket, 'timestamp' => time(), 'url' => $url, ]; if (($pos = strpos($sParams['url'], '#')) !== false) { $sParams['url'] = substr($sParams['url'], 0, $pos); } ksort($sParams); $rawData = ''; foreach ($sParams as $k => $v) { $rawData .= '&' . $k . '=' . $v; } $signature = sha1(substr($rawData, 1)); return [ 'appId' => WECHAT_APPID, 'nonceStr' => $sParams['noncestr'], 'timestamp'=> $sParams['timestamp'], 'url' => $url, 'signature' => $signature, // 'rawString' => $rawData, ];
接口都必须在wx.config后的wx.ready执行,首先吐槽官方的SDK,绝对可以让新手写出回调地狱。
wx.config
wx.ready
$.ajax({ success: function({ // ... wx.config() }) }) wx.ready(function(){ //... wx.xxx(function(){ success: function() { // ... } }) })
wx.scanQRCode
pushstate
The text was updated successfully, but these errors were encountered:
No branches or pull requests
话说这问题其实早在2016年末就已经遇到过了,没想到时隔接近一年,这次又重回微信开发,遇到了更坑爹的情况。
下文所有的情况都是基于
SPA html5 history
所讨论,其他情况不列入在内,比如终结方案就是不用 history 路由。首先吐槽一下微信文档,我认为微信团队根本没把心思花在这个上面,包括小程序也是一样,不管API还是文档,都写的很烂。
配置签名步骤
说实话配置签名还算是简单,不过官方给的demo质量也也太差了,相信大部分人都是复制粘贴的,下面贴一个质量稍微高一点的php签名算法。
客户端只需要把
window.location.href
发来即可。调用接口
接口都必须在
wx.config
后的wx.ready
执行,首先吐槽官方的SDK,绝对可以让新手写出回调地狱。对于SPA的注意点
wx.ready
只会执行一次,即无论是否多次调用wx.config
,均只执行一次。wx.scanQRCode
。pushstate
后url。The text was updated successfully, but these errors were encountered: