日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

uniapp 封装微信支付宝web端扫一扫

發(fā)布時間:2023/12/29 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 uniapp 封装微信支付宝web端扫一扫 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

uniapp 封裝? 微信? 支付寶 與app端? 的掃一掃

const scan_btn = function(that) { // #ifdef H5let ua = window.navigator.userAgent.toLowerCase();if (ua.match(/MicroMessenger/i) == 'micromessenger') {//微信console.log("微信")that.$commonjs.wechat_scan(that)}if (ua.match(/AlipayClient/i) == 'alipayclient') {//支付寶console.log("支付寶")var AlipayJSBridge=window.AlipayJSBridgeAlipayJSBridge.call('scan', {type: 'qr'}, function(result) {if(result.error){that.$commonjs.tipshow(that, result.error, 'error')}else{that.$commonjs.getjiexidevice(that,result.codeContent);}});}if (ua.match(/AlipayClient/i) != 'alipayclient' && ua.match(/MicroMessenger/i) != 'micromessenger') {that.$commonjs.tipshow(that, "請在微信 支付寶 app中使用掃一掃", 'error')}// #endif// #ifndef H5uni.scanCode({success: function(res) {console.log(res.result)that.$commonjs.getjiexidevice(that,res.result)},fail:function(res) {console.log('scanCode_fail',res)},});// #endif }, const wechat_scan=function(that){ var jweixin=require('@/components/jweixin-module/lib/index.js')let ua = window.navigator.userAgent.toLowerCase();if (ua.match(/MicroMessenger/i) == 'micromessenger') {let url = location.href.split('#')[0] // 測試要到線上測試!后臺域名要配置!不然會報簽名錯誤。that.$apiconfig.getWechatConfig({data: {signurl: url}}).then(res => {if (res.statusCode != 200) {that.$commonjs.tipshow(that, '網(wǎng)絡(luò)請求錯誤' + res.statusCode, 'error')}if (res.statusCode == 200) {if (res.data.code == "0") {that.$commonjs.tipshow(that, res.data.msg, 'error')}if (res.data.code == "1") {let wx_co = res.data.data// 通過config接口注入權(quán)限設(shè)置,config信息由后端提供jweixin.config({debug: false, // 是否開啟調(diào)試模式appId: wx_co.appId, // 必填,公眾號的唯一標識timestamp: wx_co.timestamp, // 必填,生成簽名的時間戳nonceStr: wx_co.nonceStr, // 必填,生成簽名的隨機串signature: wx_co.signature, // 必填,簽名,見附錄1jsApiList: ['scanQRCode'] // 必填,需要使用的JS接口列表,所有JS接口列表見附錄2});// config 信息嚴重失敗會執(zhí)行該函數(shù)jweixin.error(function (err) {alert("錯誤信息:" + JSON.stringify(err));}); jweixin.scanQRCode({needResult: 1, // 默認為0,掃描結(jié)果由微信處理,1則直接返回掃描結(jié)果,desc: 'scanQRCode desc',success: function(res) {console.info('點擊掃描按鈕res...',res)var result = res.resultStr; // 當needResult 為 1 時,掃碼返回的結(jié)果that.$commonjs.getjiexidevice(that,result)},fail(err){console.info('點擊掃描按鈕err...',err)}});}}})}}module.exports = {scan_btn,wechat_scan }

添加到common.js中

在main.js中引入

import commonjs from '@/js_sdk/common.js' Vue.prototype.$commonjs = commonjs;

調(diào)用

this.$commonjs.scan_btn(this)

其他:微信掃一掃需要去后端獲取配置,需按照自己實際情況修改

?

jweixin.config({debug: false, // 是否開啟調(diào)試模式appId: wx_co.appId, // 必填,公眾號的唯一標識timestamp: wx_co.timestamp, // 必填,生成簽名的時間戳nonceStr: wx_co.nonceStr, // 必填,生成簽名的隨機串signature: wx_co.signature, // 必填,簽名,見附錄1jsApiList: ['scanQRCode'] // 必填,需要使用的JS接口列表,所有JS接口列表見附錄2});

總結(jié)

以上是生活随笔為你收集整理的uniapp 封装微信支付宝web端扫一扫的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。