Home >WeChat Applet >WeChat Development >Detailed explanation of WeChat JS-SDK development scan interface function implementation code

Detailed explanation of WeChat JS-SDK development scan interface function implementation code

高洛峰
高洛峰Original
2017-03-22 16:30:474869browse

This article explains in detail the implementation code of the scan interface function developed by WeChat JS-SDK

<?php
    require_once "jssdk.php";
    $appID = "输入你的id";
     $appsecret = "输入你的secret";
 
    $jssdk = new JSSDK($appID, $appsecret);
    $signPackage = $jssdk->GetSignPackage();
var_dump($jssdk);
   
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title></title>
</head>
<body>
  <input type="text" value="<?php echo $signPackage["appId"]; ?>" id="id1" />
  <input type="text" value="<?php echo $signPackage["timestamp"]; ?>"id="id2" />
  <input type="text" value="<?php echo $signPackage["nonceStr"]; ?>" id="id3" />
  <input type="text" value="<?php echo $signPackage["signature"]; ?>" id="id4" />
</body>
<script src="./jweixin-1.0.0.js"></script>
<script src="./jquery-1.8.3.min.js"></script>
<script>
  // 注意:所有的JS接口只能在公众号绑定的域名下调用,公众号开发者需要先登录微信公众平台进入“公众号设置”的“功能设置”里填写“JS接口安全域名”。 
  // 如果发现在 Android 不能分享自定义内容,请到官网下载最新的包覆盖安装,Android 自定义分享接口需升级至 6.0.2.58 版本及以上。
  // 完整 JS-SDK 文档地址:http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html
  var appId=$(&#39;#id1&#39;).val();
  var timestamp=$(&#39;#id2&#39;).val();
  var nonceStr=$(&#39;#id3&#39;).val();
  var signature=$(&#39;#id4&#39;).val();
  wx.config({
    debug: true,
    appId: appId,
    timestamp: timestamp,
    nonceStr: nonceStr,
    signature: signature,
    jsApiList: 
       // 所有要调用的 API 都要加到这个列表中
       [&#39;scanQRCode&#39;]
     
  });
   wx.ready(function () {
     // 在这里调用 API
     alert(1);
wx.checkJsApi({
    jsApiList: [&#39;chooseImage&#39;], // 需要检测的JS接口列表,所有JS接口列表见附录2,
    success: function(res) {
     alert(res.errMsg);
        // 以键值对的形式返回,可用的api值true,不可用为false
       // {"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
    }
});
       wx.scanQRCode({  
     needResult: 0, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
      scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码,默认二者都有
      success: function (res) {
       
          var result = res.resultStr; // 当needResult 为 1 时,扫码返回的结果
      }
      
    })
   });
</script>
</html>
代码放到服务器上后用火狐浏览器打开链接,在火狐浏览器地址栏后面有个二维码的图标,点击后出现二维码图片
用微信扫码二维码,微信中弹出的网页会有返回值。(用微信的浏览器打开)

The above is the detailed content of Detailed explanation of WeChat JS-SDK development scan interface function implementation code. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn