zoukankan      html  css  js  c++  java
  • uni-app/Vue 公众号H5调用微信扫码

    npm安装微信JS-SDK

    npm install jweixin-module --save

    通过网址下载:

    https://unpkg.com/browse/jweixin-module@1.6.0/lib/index.js

    需要用到微信JSSDK页面,引入微信JSSDK

    //微信js-sdk引入
    var jweixin = require('jweixin-module')

    调用微信扫码功能:

    html代码:

    <view @click="scan()">扫一扫</view>

    JS代码:

    //调用扫码
    scan(){
         let that=this; //如果要把扫码结果赋值给页面定义变量,要使用that.变量名
         jweixin.scanQRCode({
              needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果, 
                      scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码,默认二者都有
                  success: function (res) {
                     var result = res.resultStr; // 当needResult 为 1 时,扫码返回的结果
                     if(res.resultStr.indexOf(',') > 0){
                                //条形码时返回的格式类似为【code128,123456789】        
                                 var dealserialNumber=res.resultStr.split(',')[1];
                                 dealserialNumber = dealserialNumber.replace(/[^a-zd]/ig, "");//处理条形码扫描的字符
                     alert(dealserialNumber);
                                 //location.href='接收结果页面='+dealserialNumber;//扫描结果传递到的处理页面
                      }
               else{
                            //二维码时
                            alert(res.resultStr);
                            //location.href='接收结果页面='+res.resultStr;//扫描结果传递到的处理页面
                            }
                          }
                        
        });    
    },
  • 相关阅读:
    解决CollectionView TableView reloadData或者reloadSections时的刷新的闪烁问题
    HTTP请求头
    Fastlane 使用笔记
    python-函数式编程
    python-高级特性
    python基础使用
    python基础-函数02
    python基础-函数01
    python基础
    Linux基础
  • 原文地址:https://www.cnblogs.com/Intellectualscholar/p/15365443.html
Copyright © 2011-2022 走看看