赞
踩
npm install weixin-jsapi --save
- var jWeixin = require('jweixin-module')
-
- // 配置微信config
- function getSign() {
- let that = this
- let currentRoutes = getCurrentPages(); // 获取当前打开过的页面路由数组
- var paraString = window.location.href;//获取页面完整路径包含路径上的参数
- let currentRoute = currentRoutes[currentRoutes.length - 1].route //获取当前页面路由不包含路径后的参数
- // 获取微信签名
- uni.request({
- url: 'https://xcx7.yxzyhz.com/project/tire_mall/public/api/common/getWxSign',
- method: 'POST',
- data: {
- // url: 'https://xcx7.yxzyhz.com/project/tire_mall/public/h5/#/' + currentRoute
- url: paraString
- },
- success: (wxres) => {
-
- jWeixin.config({
- debug: false, // 开启调试模式,
- appId: wxres.data.data.appId, // 必填,公众号的唯一标识
- timestamp: wxres.data.data.timestamp, // 必填,生成签名的时间戳
- nonceStr: wxres.data.data.nonceStr, // 必填,生成签名的随机串
- signature: wxres.data.data.signature, // 必填,签名
- jsApiList: ["scanQRCode", 'hideAllNonBaseMenuItem',
- 'showAllNonBaseMenuItem'
- ] // 必填,需要使用的JS接口列表
- });
- jWeixin.error(function(res) {
- console.log('微信config配置失败res', res)
- })
- jWeixin.ready(function() {
- // that.toggle()
- console.log('微信config配置成功res')
- })
- }
- })
-
- }
-
- // 微信扫一扫
- function toggle() {
- jWeixin.scanQRCode({
- needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
- scanType: ["qrCode"], // 可以指定扫二维码还是一维码,默认二者都有
- success: function(res) {
- var result = res.resultStr; // 当needResult 为 1 时,扫码返回的结果
- uni.setStorageSync('scancode', result)
- },
- fail: function(err) {
- uni.removeStorageSync('scancode')
- }
- });
- }
-
- // 微信支付
- function payment() {
- let paymentcon = JSON.parse(uni.getStorageSync('payment'))
- jWeixin.chooseWXPay({
- timestamp: paymentcon.timeStamp, // 支付签名时间戳
- nonceStr: paymentcon.nonceStr, // 支付签名随机串,不长于 32 位
- package: paymentcon.package, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=\*\*\*)
- signType: paymentcon.signType, // 微信支付V3的传入RSA,微信支付V2的传入格式与V2统一下单的签名格式保持一致
- paySign: paymentcon.paySign, // 支付签名
- success: function(res) {
- console.log(res,'支付成功')
- // 支付成功后的回调函数
- }
- });
- }
- export {
- getSign,
- toggle,
- payment
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。