• 微信JSSDK 扫描二维码


    <?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>
    

      

  • 相关阅读:
    kakfa 入门
    Spring Boot maven构建——阿里云Maven仓库地址
    MongoDB入门一
    MongoDB入门
    mybatis 一对一、一对多、多对一、多对多
    springboot集成druid数据源并且监控
    java 过滤表情符号
    Mybatis框架
    表单(一)
    HTML标签(二)
  • 原文地址:https://www.cnblogs.com/txw1958/p/11189281.html
Copyright © 2020-2023  润新知