123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- //引入微信jssdk
- const wx = require('@/js_sdk/jweixin-1.4.0.js')
- import { config } from './config/config';
- //配置注册url
- const url = config.apiBaseurl + 'wechat/sign';
- //http方法
- import Request from '@/js_sdk/luch-request/luch-request/index.js';
- const $http = new Request();
- //系统域名url
- const href = location.href.split('#')[0];
- // const href = location.href.split("?")[0]
- $http.get(url, {params: {url: href, list: 'scanQRCode',dataType: 'json'}}).then(res => {
- let str = JSON.parse( res.data.config)
- console.log( 'res.data.config',str )
- wx.config({
- // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
- debug: true,
- // 必填,公众号的唯一标识
- appId: str.appId,
- // 必填,生成签名的时间戳
- timestamp: "" + str.timestamp,
- // 必填,生成签名的随机串
- nonceStr: str.nonceStr,
- // 必填,签名
- signature: str.signature,
- // 必填,需要使用的JS接口列表,所有JS接口列表
- jsApiList: ['checkJsApi', 'scanQRCode']
- });
- }).catch(err => {
- console.log(err)
- })
- //系统域名url
- export default {
- ...wx,
- isOk: true,
- async config() {
- wx.config({
- debug: true,
- jsApiList: [
- "scanQRCode",
- ],
- ...(await JSON.parse( $http.get(url, {params: {url: href, list: 'scanQRCode',dataType: 'json'}}).data.config)),
- });
- wx.ready(e => {
- this.isOk = true;
- alert('wxapi');
-
- wx.checkJsApi({
- jsApiList: ['scanQRCode'],
- success: function (res) {
- alert('checkJsApi'+res)
-
- }
- });
- // this.hideMenu();
- });
- wx.error(e => {
- console.log("失败")
- alert("出错了:" + res.errMsg);
- this.isOk = false;
- });
- },
- hideMenu() {
- wx.hideAllNonBaseMenuItem();
- },
- showMenu() {
- wx.showMenuItems({
- menuList: [
- "menuItem:share:appMessage",
- "menuItem:profile",
- "menuItem:addContact",
- "menuItem:dayMode",
- "menuItem:nightMode",
- "menuItem:share:timeline",
- "menuItem:favorite"
- ] // 要显示的菜单项,所有menu项见附录3
- });
- },
-
- //
- JSAPI() {
- console.log('1111');
- let result;
- return new Promise(r => {
- wx.scanQRCode({
- needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
- scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码,默认二者都有
- success: function (res) {
- alert('333'+res);
- result = res.resultStr; // 当needResult 为 1 时,扫码返回的结果
- // return result;
- },
- fail:function(err){
- alert(err)
- }
- });
- });
- alert('444'+result);
- return result;
- },
- }
|