多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
**目录 (Table of Contents)** [TOC] ## 获取JS API ```PHP $wxConfigure = new WechatConfig(); $wxConfigure->setParameter("appid",YourAppID); $wxConfigure->setParameter("appsecret",YourSecret); // 假设您在之前的操作中已经获取过ACCESS_TOKEN,并保存在数据库中 $wxConfigure->setParameter("access_token",ACCESS_TOKEN); $wechatServer = new WechatServerApi($wxConfigure); try { $results = $wechatServer->getWechatJsapiTicket(); $ticket = $results['ticket']; $epxires_in = $results['expires_in']; $wxConfigure->setParameter("jsapi_ticket",$ticket); // 保存 $ticket 到数据库,并设置超时时间 $expires_in $results= $wechatServer->getJsApiSign(); echo $results; // 将签名后的js配置返回给前端页面 } catch(WechatException $e) { echo $e->errorMessage(); } ``` ```HTML5 <html> <header> <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.1.0.js"></script> </header> <body> </body> <script> // 假设前端获取到后端返回来的jsapi 签名对象为 results wx.config({ debug: false, appId:results.appId, timestamp:results.timestamp, nonceStr: 'results.nonceStr, signature:results.signature, jsApiList: [ // 所有要调用的 API 都要加到这个列表中 'checkJsApi', 'openLocation', 'getLocation', 'scanQRCode', 'translateVoice', ] }); </script> ```