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

2022/1/25 17:06:08

本文主要是介绍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

}

 



这篇关于uniapp app,小程序,公众号h5调用扫一扫的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程