实际上,在开发微信应用的过程当中,转发给朋友和分享到朋友圈,常常发生签名验证失败的问题。php
签名验证失败,大部分是url不符合形成的。
好比 http://www.hisn.cn/index.php?d-12=&from=tamp
这样的连接。
在后台的时候,用 $url =’http://’. $_SERVER[‘HTTP_POST’].$_SERVER[‘REQUEST_URI’];
通常都是上面的那样的连接。前端
可是由于微信取值,用的是 location.href.split('#')[0] 这样的。
而window.location.href 这样取值,有时会带有 index.php 而有时又不带有 index.php,这就致使在作微信签名的时候,先后连接不统一的问题,致使签名验证失败。微信
因此要在前台调用微信jssdk以前对location.href进行处理,我是这样作的:url
var locationUrl = window.location.href; if(locationUrl.indexOf('index.php')==-1){ window.location.href = 'http://www.hisn.cn/index.php'+window.location.search; }
这样,假如前端js获取连接的时候不带有index.php的时候,就自动调转到带有的连接上,就OK了。 code
就保证,分享二次转发等,顺利转发!!开发