<?php require_once('wxjssdk.class.php'); $weixin = new class_weixin(); $signPackage = $weixin->GetSignPackage(); $news = array("Title" =>"方倍", "Description"=>"方倍測試", "PicUrl" =>'http://demo.open.weixin.qq.com/jssdk/images/p2166127561.jpg', "Url" =>'http://www.baidu.com/'); // session_start(); // var_dump($_SESSION); ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=2.0, minimum-scale=1.0, user-scalable=no" /> <meta name="format-detection" content="telephone=no" /> <title></title> <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0"> <link rel="stylesheet" href="http://demo.open.weixin.qq.com/jssdk/css/style.css"> <script type="text/javascript" src="jquery-1.8.3.min.js"></script> </head> <body ontouchstart=""> <!-- --> <h3 id="menu-scan">微信左頁掃描</h3> <button class="btn btn_primary" id="scanQRCode1">scanQRCode(直接返回結果)</button> </body> <script src="https://res.wx.qq.com/open/js/jweixin-1.1.0.js"></script> <script> wx.config({ debug: false, appId: '<?php echo $signPackage["appId"];?>', timestamp: <?php echo $signPackage["timestamp"];?>, nonceStr: '<?php echo $signPackage["nonceStr"];?>', signature: '<?php echo $signPackage["signature"];?>', // url:'<?php echo $signPackage["url"];?>', jsApiList: [ // 全部要調用的 API 都要加到這個列表中 'checkJsApi', 'onMenuShareTimeline', 'onMenuShareAppMessage', 'scanQRCode' ] }); </script> <script> wx.ready(function () { //自動執行的 wx.checkJsApi({ jsApiList: [ 'onMenuShareTimeline', 'onMenuShareAppMessage' ], success: function (res) { // alert(JSON.stringify(res)); // alert(JSON.stringify(res.checkResult.getLocation)); // if (res.checkResult.getLocation == false) { // alert('你的微信版本過低,不支持微信JS接口,請升級到最新的微信版本!'); // return; // } } }); // wx.hideOptionMenu(); wx.onMenuShareAppMessage({ title: '<?php echo $news['Title'];?>', desc: '<?php echo $news['Description'];?>', link: '<?php echo $news['Url'];?>', imgUrl: '<?php echo $news['PicUrl'];?>', trigger: function (res) { // 不要嘗試在trigger中使用ajax異步請求修改本次分享的內容,由於客戶端分享操做是一個同步操做,這時候使用ajax的回包會尚未返回 // alert('用戶點擊發送給朋友'); }, success: function (res) { // alert('已分享'); }, cancel: function (res) { // alert('已取消'); }, fail: function (res) { alert(JSON.stringify(res)); } }); wx.onMenuShareTimeline({ title: '<?php echo $news['Title'];?>', link: '<?php echo $news['Url'];?>', imgUrl: '<?php echo $news['PicUrl'];?>', trigger: function (res) { // 不要嘗試在trigger中使用ajax異步請求修改本次分享的內容,由於客戶端分享操做是一個同步操做,這時候使用ajax的回包會尚未返回 // alert('用戶點擊分享到朋友圈'); }, success: function (res) { // alert('已分享'); }, cancel: function (res) { // alert('已取消'); }, fail: function (res) { alert(JSON.stringify(res)); } }); // 9.1.2 掃描二維碼並返回結果 document.querySelector('#scanQRCode1').onclick = function () { wx.scanQRCode({ needResult: 1, // 默認爲0,掃描結果由微信處理,1則直接返回掃描結果, scanType: ["qrCode","barCode"], // 能夠指定掃二維碼仍是一維碼,默認兩者都有 success: function (res) { alert(JSON.stringify(res)); var left = res.resultStr; // 當needResult 爲 1 時,掃碼返回的結果 $.ajax({ url: 'soap.php', type: 'POST', data: {left:left}, dataType: 'JSON', beforeSend:function(){ }, success: function (data) { alert(JSON.stringify(data)); window.location.href="right.php"; }, complete:function(){ }, error:function(res){ alert("第三方查詢接口異常,請重試"); // alert(JSON.stringify(res)); } }); } }); }; }); wx.error(function (res) { alert(res.errMsg); }); </script> </html>