时间:2023-02-20 17:06:01 | 来源:建站知识
时间:2023-02-20 17:06:01 来源:建站知识
EasyWeChat JSSDK 之获取当前 url 深坑:我的用的3.x 版本,在获取 jssdk 的签名时总是出错,这个坑有点深啊...Route::get('test',function (){ $app = new Application(config('wechat')); $js = $app->js; $configArr = $js->getConfigArray([ 'onMenuShareTimeline', 'onMenuShareAppMessage', 'hideAllNonBaseMenuItem', 'showMenuItems', "chooseWXPay" //微信支付 ],false); return $s;});
在 微信开发者工具 中测试时一直会抛 签名验证失败的错误.我们看一下 easywechat 给我们生成的 JSSDK 配置数据:Route::get('test',function (){ $app = new Application(config('wechat')); $js = $app->js; // 通过正则表达式将 http 替换成 https $url = $js->getUrl(); $url = preg_replace("/http(.*)://///","https://",$url); $js->setUrl($url); $configArr = $js->getConfigArray([ 'onMenuShareTimeline', 'onMenuShareAppMessage', 'hideAllNonBaseMenuItem', 'showMenuItems', "chooseWXPay" //微信支付 ],false); return $configArr;});
继续看结果,这时 JSSDK 的配置信息便正确了.关键词:获取