如何将h5网页改成微信网页
1、如何將h5網(wǎng)頁改成微信網(wǎng)頁
1、設置安全域名
? ? ? ? ? 先登錄微信公眾平臺進入“公眾號設置”的“功能設置”里填寫“JS接口安全域名”。
? ? ? ? ?備注:登錄后可在“開發(fā)者中心”查看對應的接口權限。
2、引用一個js文件 在微信開發(fā)者里面 js sdk里面
? ? ? <script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>先登錄微信公眾平臺進入“公眾號設置”的“功能設置”里填寫“JS接口安全域名”。
備注:登錄后可在“開發(fā)者中心”查看對應的接口權限。
3、要去寫一個配置
? ? ? wx.config({
? ? ? ? ? ??debug: true, // 開啟調(diào)試模式,調(diào)用的所有api的返回值會在客戶端alert出來,若要查看傳入的參數(shù),可以在pc端打開,參數(shù)信息會通過log打出,僅在pc端時才會打印。
? ? ??? ? ??appId: '', // 必填,公眾號的唯一標識 公眾號開發(fā)者id
? ? ??? ? ??timestamp: (new Date().getTime())/1000), // 必填,生成簽名的時間戳 秒 js中是毫秒 需要除以1000取前面的整數(shù)
? ? ??? ? ??nonceStr: '', // 必填,生成簽名的隨機串 asgdf
? ? ??? ? ??signature: '',// 必填,簽名
? ? ??? ? ??jsApiList: ["onMenuShareTimeline",
? ? ??? ? ??"onMenuShareAppMessage",
? ? ??? ? ??"onMenuShareQQ",
? ? ??? ? ??"onMenuShareWeibo",
? ? ??? ? ??"onMenuShareQZone","getLocation"......
? ? ??? ? ??openCard] // 必填,需要使用的JS接口列表
? ? ??});
備注 如何獲取 signature
? ? ??1、在http://mp.weixin.qq.com/debug里面的調(diào)試工具可以用appid和secret 換取accesstoken
get請求
? ? ??請求地址 https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=xxxxxxxx&secret=xxxxx
2、用accesstoken 換取signature
? ? ??http://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=你的token&type=jsapi
? ? ??拿到signature
4、調(diào)用
<div id="info">選擇一張圖片</div>
<div onClick="getImg()">選擇一張圖片</div>
<script>
? ? ??function getImg(){
? ? ??? ? ??wx.ready(function(){
? ? ??? ? ??wx.chooseImage({
? ? ??? ? ??count: 1, // 默認9
? ? ?? ? ???sizeType: ['original', 'compressed'], // 可以指定是原圖還是壓縮圖,默認二者都有
? ? ??? ? ??sourceType: ['album', 'camera'], // 可以指定來源是相冊還是相機,默認二者都有
? ? ??? ? ??success: function (res) {
? ? ??? ? ??? ? ??var localIds = res.localIds; // 返回選定照片的本地ID列表,localId可以作為img標簽的src屬性顯示圖片
? ? ??? ? ?? ? ???//調(diào)試這樣,因為手機沒有console 只能這樣顯示然后調(diào)試錯誤
? ? ?? ? ??? ? ???var t=document.getElementById("Info");
? ? ?? ? ???? ? ??t.innerHTML=res.localIds
? ? ??? ? ???}
? ? ??? ? ??});
? ? ??? ? ??});
? ? ??}
</script>
微信sdk幫助文檔
http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html
?
?
微信config? 和釘釘接入不盡相同,都是需要獲取accesstoken然后拿到后臺去鑒權,然后認證通過進入
更多專業(yè)前端知識,請上 【猿2048】www.mk2048.com 創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎
總結
以上是生活随笔為你收集整理的如何将h5网页改成微信网页的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于html以及js相关格式验证的记录
- 下一篇: 蘑菇街一电话面试1