• uniapp app,小程序,公众号h5调用扫一扫


    (app,小程序)

    uni.scanCode({
    onlyFromCamera: true, //只能通过相机扫码
    success: function (res) {
    if(res.result.indexOf("%")!=-1){
    var str = res.result.substr(50);
    let strs= str.split("-");
    that.account = strs[0];
    that.content = strs[1];
    }
    }
    });

    (公众号H5)

    第一步-> 进入项目目录

    npm install jweixin-module --save

    第二步-> 在需要使用的页面

    import jweixin from 'jweixin-module'

    scancode(){

     var that = this;

    // #ifdef H5
    let url = window.location.href.split('#')[0]; // 很重要
    let urls = url.split('#')[0];
    that.$request({
    url:'wx-gzh-sign',
    methods:'GET'
    },{
    url:url
    }).then(res=>{
    let data = res.data.data;
    jweixin.config({
    debug: false, //测试时候用true 能看见wx.config的状态是否是config:ok
    appId: data.appid, // 必填,公众号的唯一标识(公众号的APPid)
    timestamp: data.timestamp, // 必填,生成签名的时间戳
    nonceStr: data.noncestr, // 必填,生成签名的随机串
    signature: data.sign, // 必填,签名
    jsApiList: ['scanQRCode'], // 必填,需要使用的JS接口列表
    });
    jweixin.ready(function (res) {
    jweixin.checkJsApi({
    jsApiList: ['scanQRCode'], // 需要检测的JS接口列表,所有JS接口列表见附录2,
    success: function(res) {
    jweixin.scanQRCode({
    needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
    scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码,默认二者都有
    success: function (res1) {
    if(res1.resultStr.indexOf("%")!=-1){
    var str = res1.resultStr.substr(50);
    let strs= str.split("-");
    that.account = strs[0];
    that.content = strs[1];
    }
    // window.location.href = res1.resultStr; //安卓机型跳转渲染有问题 所以要加这句
    }
    });
    }
    });
    });
    jweixin.error(function (res1) {
    console.log("接口调取失败:"+res1);
    });
    });
    // #endif

    }

  • 相关阅读:
    windows 查看某个端口号被占用情况
    C# 配置文件ini操作类
    C#:如何解决WebBrowser.DocumentCompleted事件的多次调用
    什么是异或_异或运算及异或运算的作用
    UID卡、CUID卡、FUID卡的区别
    C#获取窗口大小和位置坐标 GetWindowRect用法
    C#中SetWindowPos函数详解
    C#让电脑发声,播放声音
    C#自动缩进排列代码的快捷键 c# 代码重新排版 变整齐
    安卓手机USB无法共享、上网或卡顿的解决方法
  • 原文地址:https://www.cnblogs.com/shoolnight/p/15843014.html
Copyright © 2020-2023  润新知