如何利用微信JSSDK調(diào)用微信掃一掃功能?具體內(nèi)容如下
為和縣等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計制作服務(wù),及和縣網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為成都網(wǎng)站設(shè)計、成都做網(wǎng)站、外貿(mào)網(wǎng)站建設(shè)、和縣網(wǎng)站設(shè)計,以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會得到認(rèn)可,從而選擇與我們長期合作。這樣,我們也可以走得更遠(yuǎn)!
1. 確保有 調(diào)起微信掃一掃接口 權(quán)限,測試號可能不行;
2. 導(dǎo)入相關(guān)JS
<script type="text/javascript" http://test.com/zepto_touch.js"></script> <script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
3. 頁面觸發(fā)掃碼元素
<img src="../../../images/right.jpg" onclick="scanCode()" class="img">
4. 相關(guān)JS代碼
<script type="text/javascript"> var _appId = "wxz88dbd30e5580e59"; var _data = { appId : _appId, url : location.href, t : Math.random() }; var _getWechatSignUrl = 'http://test.com/getWechatSign.do'; // 獲取微信簽名 $.ajax({ url : _getWechatSignUrl, data : _data, success : function(o) { console.log(o); if (o.returnCode == "00") { wxConfig(o.detail[0].timestamp, o.detail[0].nonceStr, o.detail[0].signature); } } }); function wxConfig(_timestamp, _nonceStr, _signature) { //alert('獲取數(shù)據(jù):'+_timestamp+'\n'+_nonceStr+'\n'+_signature); console.log('獲取數(shù)據(jù):' + _timestamp + '\n' + _nonceStr + '\n' + _signature); wx.config({ debug : true, // 開啟調(diào)試模式,調(diào)用的所有api的返回值會在客戶端alert出來,若要查看傳入的參數(shù),可以在pc端打開,參數(shù)信息會通過log打出,僅在pc端時才會打印。 appId : _appId, // 必填,公眾號的唯一標(biāo)識 timestamp : _timestamp, // 必填,生成簽名的時間戳 nonceStr : _nonceStr, // 必填,生成簽名的隨機(jī)串 signature : _signature,// 必填,簽名,見附錄1 jsApiList : [ 'onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareWeibo', 'scanQRCode' ] // 必填,需要使用的JS接口列表,所有JS接口列表見附錄2 }); } function scanCode() { wx.scanQRCode({ needResult : 1, scanType : [ "qrCode", "barCode" ], success : function(res) { console.log(res) alert(JSON.stringify(res)); var result = res.resultStr; }, fail : function(res) { console.log(res) alert(JSON.stringify(res)); } }); } </script>
5. 獲取簽名接口getWechatSign.do各值生成方式
timestamp
Long timestamp = System.currentTimeMillis() / 1000;
nonceStr
String nonceStr = RandomStringUtils.randomAlphanumeric(16);
signature
public static String getSign(String jsapi_ticket, String noncestr, Long timestamp, String url) throws NoSuchAlgorithmException { String shaStr = "jsapi_ticket=" + jsapi_ticket + "&noncestr=" + noncestr + "×tamp=" + timestamp + "&url=" + url; MessageDigest mDigest = MessageDigest.getInstance("SHA1"); byte[] result = mDigest.digest(shaStr.getBytes()); StringBuffer signature = new StringBuffer(); for (int i = 0; i < result.length; i++) { signature.append(Integer.toString((result[i] & 0xff) + 0x100, 16).substring(1)); } return signature.toString(); }
6. 微信參考文檔
獲取access_token https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140183
獲取jsapi_ticket https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。
分享標(biāo)題:微信JSSDK調(diào)用微信掃一掃功能的方法
URL鏈接:http://aaarwkj.com/article26/pdphcg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)、外貿(mào)建站、定制開發(fā)、做網(wǎng)站、虛擬主機(jī)、搜索引擎優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)