TNW: TypeScript(The) + Node.js(Next) + WeChat 微信公衆號開發腳手架,支持任何 Node.js 的服務端框架(Express、Nest、egg 等)javascript
公衆號接口權限說明css
微信 JS-SDK 說明文檔html
正式號:登陸微信公衆平臺進入 公衆號設置
的 功能設置
裏填寫 JS接口安全域名
vue
測試號:進入微信公衆賬號測試號申請系統 找到 JS接口安全域名
點擊 修改
java
在須要調用JS接口的頁面引入以下JS文件:res2.wx.qq.com/open/js/jwe… (支持https)node
wx.config({
debug: true,
appId: '{{ appId }}',
timestamp: '{{ timestamp }}',
nonceStr: '{{ nonceStr }}',
signature: '{{ signature }}',
jsApiList: [
'checkJsApi',
'...省略其餘'
]
});
複製代碼
簽名算法見 官方文檔附錄1git
特別注意: url 必須爲頁面完整的URL包括參數web
@Get('jssdk')
@Render('jssdk.hbs')
async jssdk(@Req() request: Request, @Res() response: Response) {
let appId = ApiConfigKit.getApiConfig.getAppId;
let timestamp = new Date().getTime() / 1000;
let nonceStr = uuid.v1();
let url = "http://xxxx/jssdk?....";//填寫完整頁面的URL包括參數
// 生成簽名
let signature = await WeChat.jssdkSignature(nonceStr, timestamp, url);
return {
appId: appId,
timestamp: timestamp,
nonceStr: nonceStr,
signature: signature
};
}
複製代碼
wx.ready(function(){
// config 信息驗證後會執行 ready 方法,全部接口調用都必須在 config 接口得到結果以後,config 是一個客戶端的異步操做,因此若是須要在頁面加載時就調用相關接口,則須把相關接口放在 ready 函數中調用來確保正確執行。對於用戶觸發時才調用的接口,則能夠直接調用,不須要放在 ready 函數中。
});
複製代碼
wx.error(function(res){
// config 信息驗證失敗會執行 error 函數,如簽名過時致使驗證失敗,具體錯誤信息能夠打開 config 的 debug 模式查看,也能夠在返回的 res 參數中查看,對於 SPA 能夠在這裏更新簽名。
});
複製代碼
全部JS接口列表見 官方文檔附錄2算法
特別注意:typescript
link
連接必須 JS 接口安全域名下的連接<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>TNW 微信公衆號開發腳手架</title>
<meta charset="utf-8">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="tnw,nodejs,微信公衆號開發">
<meta http-equiv="description" content="tnw 微信公衆號開發腳手架,可集成到任何 Node.js MVC後端框架中">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="https://www.weixinsxy.com/jssdk/css/style.css">
</head>
<body>
<div class="wxapi_container">
<div class="wxapi_index_container">
<ul class="label_box lbox_close wxapi_index_list">
<li class="label_item wxapi_index_item"><a class="label_inner" href="#menu-basic">基礎接口</a></li>
<li class="label_item wxapi_index_item"><a class="label_inner" href="#menu-share">分享接口</a></li>
<li class="label_item wxapi_index_item"><a class="label_inner" href="#menu-image">圖像接口</a></li>
<li class="label_item wxapi_index_item"><a class="label_inner" href="#menu-voice">音頻接口</a></li>
<li class="label_item wxapi_index_item"><a class="label_inner" href="#menu-smart">智能接口</a></li>
<li class="label_item wxapi_index_item"><a class="label_inner" href="#menu-device">設備信息接口</a></li>
<li class="label_item wxapi_index_item"><a class="label_inner" href="#menu-location">地理位置接口</a></li>
<li class="label_item wxapi_index_item"><a class="label_inner" href="#menu-webview">界面操做接口</a></li>
<li class="label_item wxapi_index_item"><a class="label_inner" href="#menu-scan">微信掃一掃接口</a></li>
<li class="label_item wxapi_index_item"><a class="label_inner" href="#menu-shopping">微信小店接口</a></li>
<li class="label_item wxapi_index_item"><a class="label_inner" href="#menu-card">微信卡券接口</a></li>
<li class="label_item wxapi_index_item"><a class="label_inner" href="#menu-pay">微信支付接口</a></li>
</ul>
</div>
<div class="lbox_close wxapi_form">
<h3 id="menu-basic">基礎接口</h3>
<span class="desc">判斷當前客戶端是否支持指定JS接口</span>
<button class="btn btn_primary" id="checkJsApi">checkJsApi</button>
<h3 id="menu-share">分享接口</h3>
<span class="desc">「分享給朋友」及「分享到QQ」</span>
<button class="btn btn_primary" id="updateAppMessageShareData">updateAppMessageShareData</button>
<span class="desc">「分享到朋友圈」及「分享到QQ空間」</span>
<button class="btn btn_primary" id="updateTimelineShareData">updateTimelineShareData</button>
<span class="desc">分享到騰訊微博</span>
<button class="btn btn_primary" id="onMenuShareWeibo">onMenuShareWeibo</button>
<h3 id="menu-image">圖像接口</h3>
<span class="desc">拍照或從手機相冊中選圖接口</span>
<button class="btn btn_primary" id="chooseImage">chooseImage</button>
<span class="desc">預覽圖片接口</span>
<button class="btn btn_primary" id="previewImage">previewImage</button>
<span class="desc">上傳圖片接口</span>
<button class="btn btn_primary" id="uploadImage">uploadImage</button>
<span class="desc">下載圖片接口</span>
<button class="btn btn_primary" id="downloadImage">downloadImage</button>
<h3 id="menu-voice">音頻接口</h3>
<span class="desc">開始錄音接口</span>
<button class="btn btn_primary" id="startRecord">startRecord</button>
<span class="desc">中止錄音接口</span>
<button class="btn btn_primary" id="stopRecord">stopRecord</button>
<span class="desc">播放語音接口</span>
<button class="btn btn_primary" id="playVoice">playVoice</button>
<span class="desc">暫停播放接口</span>
<button class="btn btn_primary" id="pauseVoice">pauseVoice</button>
<span class="desc">中止播放接口</span>
<button class="btn btn_primary" id="stopVoice">stopVoice</button>
<span class="desc">上傳語音接口</span>
<button class="btn btn_primary" id="uploadVoice">uploadVoice</button>
<span class="desc">下載語音接口</span>
<button class="btn btn_primary" id="downloadVoice">downloadVoice</button>
<h3 id="menu-smart">智能接口</h3>
<span class="desc">識別音頻並返回識別結果接口</span>
<button class="btn btn_primary" id="translateVoice">translateVoice</button>
<h3 id="menu-device">設備信息接口</h3>
<span class="desc">獲取網絡狀態接口</span>
<button class="btn btn_primary" id="getNetworkType">getNetworkType</button>
<h3 id="menu-location">地理位置接口</h3>
<span class="desc">使用微信內置地圖查看位置接口</span>
<button class="btn btn_primary" id="openLocation">openLocation</button>
<span class="desc">獲取地理位置接口</span>
<button class="btn btn_primary" id="getLocation">getLocation</button>
<h3 id="menu-webview">界面操做接口</h3>
<span class="desc">隱藏右上角菜單接口</span>
<button class="btn btn_primary" id="hideOptionMenu">hideOptionMenu</button>
<span class="desc">顯示右上角菜單接口</span>
<button class="btn btn_primary" id="showOptionMenu">showOptionMenu</button>
<span class="desc">關閉當前網頁窗口接口</span>
<button class="btn btn_primary" id="closeWindow">closeWindow</button>
<span class="desc">批量隱藏功能按鈕接口</span>
<button class="btn btn_primary" id="hideMenuItems">hideMenuItems</button>
<span class="desc">批量顯示功能按鈕接口</span>
<button class="btn btn_primary" id="showMenuItems">showMenuItems</button>
<span class="desc">隱藏全部非基礎按鈕接口</span>
<button class="btn btn_primary" id="hideAllNonBaseMenuItem">hideAllNonBaseMenuItem</button>
<span class="desc">顯示全部功能按鈕接口</span>
<button class="btn btn_primary" id="showAllNonBaseMenuItem">showAllNonBaseMenuItem</button>
<h3 id="menu-scan">微信掃一掃</h3>
<span class="desc">調起微信掃一掃接口</span>
<button class="btn btn_primary" id="scanQRCode0">scanQRCode(微信處理結果)</button>
<button class="btn btn_primary" id="scanQRCode1">scanQRCode(直接返回結果)</button>
</div>
</div>
</body>
<script type="text/javascript" src="http://res2.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
<script type="text/javascript"></script>
</html>
複製代碼
TNW
微信公衆號開發腳手架:gitee.com/javen205/TN…IJPay
讓支付觸手可及:gitee.com/javen205/IJ…mica
工具集:gitee.com/596392912/m…Avue
一款基於 vue 可配置化的神奇框架:gitee.com/smallweigit…pig
宇宙最強微服務(架構師必備):gitee.com/log4j/pigSpringBlade
完整的線上解決方案(企業開發必備):gitee.com/smallc/Spri…