**目錄 (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>
```
- 1、序言
- 1.1、更新說明
- 1.2、更新計劃
- 2、開始使用 Endor
- 3、目錄結構
- 4、類說明
- 4.1、WechatConfig
- 4.2、WechatValid
- 4.3、WechatCommon
- 4.4、WechatException
- 4.5、基礎接口
- 4.5.1、ShortUrl
- 4.5.2、WechatServerApi
- 4.6、菜單接口
- 4.6.1、菜單類設計
- 4.6.2、Menu
- 4.6.3、ClickMenu
- 4.6.4、ViewMenu
- 4.6.5、MiniProgramMenu
- 4.6.6、MenuApi
- 4.7、消息接口
- 4.7.1、Receiver
- 4.7.2、Message
- 4.7.3、EventMessage
- 4.7.4、TextMessage
- 4.7.5、ClickEventMessage
- 4.7.6、SubscribeEventMessage
- 4.7.7、UnSubscribeEventMessage
- 4.7.8、LocationEventMessage
- 4.7.9、ImageMessage
- 4.7.10、LinkMessage
- 4.7.11、NewsMessage
- 4.7.12、NewsContext
- 4.8、OAuth2.0權限驗證
- 4.8.1、WechatUser
- 4.8.2、OAuthApi
- 4.9、微信支付接口
- 4.9.1、微信支付類設計
- 4.9.2、PayApi
- 4.9.3、RequestPay
- 4.9.4、ResponsePay
- 4.9.5、UnifiedOrder
- 4.9.6、JsPay
- 4.9.7、Refund
- 4.9.8、Query
- 4.9.9、Bill
- 4.9.10、NotifyData
- 4.9.11、Notify
- 4.10、模板消息接口
- 4.10.1、TemplateContext
- 4.10.2、TemplateMessageApi
- 5、使用場景
- 5.1、微信接入服務器驗證
- 5.2、獲取微信API令牌(access_token)
- 5.3、獲取JS API
- 5.4、OAuth2.0靜默登錄
- 5.5、微信菜單
- 5.6、微信消息
- 5.7、微信支付
- 5.7.1、微信公眾號內JsApi支付
- 5.7.2、Native 模式二 掃碼支付
- 5.8、模板消息發送