123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- // import network from '@/network'; // 这个是自己项目里的网络层,用于调用接口
- import Vue from 'vue';
- import {
- allocations
- } from '@/api/configget';
- import Router from '@/router'
- import {withoutCodeLoad} from '@/utils/wxconfiguration.js'
- import moment from 'moment' // 时间库
- export const wxAuth = async (pushindex, next) => {
- const wechatConfigUrl = location.href.split('#')[0]
- // const wechatConfigUrl = location.href.split("?")[1].split("=")[1]
- // console.log('获取url')
- // console.log(location.href)
- // console.log(wechatConfigUrl)
- // console.log(window.wechatConfigUrl)
- // console.log(window.WWOpenData)
- if (window.wechatConfigUrl === wechatConfigUrl && window.WWOpenData) {
- if (next) {
- next()
- }
- return Promise.resolve()
- } else {
- try {
- await wxConfigByCorp(wechatConfigUrl, pushindex, next)
- window.wechatConfigUrl = wechatConfigUrl
- return Promise.resolve()
- } catch (error) {
- return Promise.reject(error)
- }
- }
- }
- async function wxConfigByCorp(body, pushindex, next) {
- var data;
- await allocations(body).then((res) => {
- if (res.data.code == 1) {
- console.log("请求配置成功")
- data = res.data.data
- }else{
- }
- }).catch(()=>{
- // withoutCodeLoad()
- })
- const wxConfigParams = data.config
- const appSignature = data.agentConfig
- // console.log(wxConfigParams)
- // console.log(appSignature)
- // console.log('wxConfig开始')
- // console.log(Vue.prototype.$wx)
- await Vue.prototype.$wx.config({ // 鉴权(企业的身份与权限)
- beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
- debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
- appId: wxConfigParams.appId, // 必填,企业微信的corpID
- timestamp: wxConfigParams.timestamp, // 必填,生成签名的时间戳
- nonceStr: wxConfigParams.nonceStr, // 必填,生成签名的随机串
- signature: wxConfigParams.signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法
- jsApiList: [
- 'shareAppMessage',
- 'previewFile',
- 'selectEnterpriseContact',
- 'onMenuShareAppMessage',
- 'invoke',
- 'hideOptionMenu',
- 'showOptionMenu'
- ] // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
- });
- await Vue.prototype.$wx.ready(function () {
- // console.log('wxConfig成功')
- // console.log('wx.agentConfig开始')
- // console.log('wx.agentConfig:BEGIN');
- const u = navigator.userAgent;
- const isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; // 安卓
- const isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); // ios终端
- if (isAndroid) {
- console.log('安卓手机');
- Vue.prototype.$wx.invoke('agentConfig', {
- corpid: appSignature.appId, // 必填,企业微信的corpid,必须与当前登录的企业一致
- agentid: appSignature.agentid, // 必填,企业微信的应用id (e.g. 1000247)生产环境 写自己环境的agentid
- timestamp: appSignature.timestamp, // 必填,生成签名的时间戳
- nonceStr: appSignature.nonceStr, // 必填,生成签名的随机串
- signature: appSignature.signature, // 必填,签名,见附录-JS-SDK使用权限签名算法
- jsApiList: [
- 'openUserProfile',
- 'previewFile'
- ], // 必填
- }, function (res) {
- console.log('result', res);
- });
- }
- if (isIOS) {
- console.log('苹果手机');
- Vue.prototype.$wx.agentConfig({
- corpid: appSignature.appId, // 必填,企业微信的corpid,必须与当前登录的企业一致
- agentid: appSignature.agentid, // 必填,企业微信的应用id (e.g. 1000247)生产环境
- timestamp: appSignature.timestamp, // 必填,生成签名的时间戳
- nonceStr: appSignature.nonceStr, // 必填,生成签名的随机串
- signature: appSignature.signature, // 必填,签名,见附录-JS-SDK使用权限签名算法
- jsApiList: [
- 'openUserProfile',
- 'previewFile'
- ], // 必填
- success(res) {
- console.log('agentConfig', res);
- },
- fail(res) {
- console.log('err', res);
- if (res.errMsg.indexOf('function not exist') > -1) {
- alert('版本过低请升级');
- }
- }
- });
- }
- if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
- } else {
- console.log('pc端')
- // console.log(appSignature)
- Vue.prototype.$wx.agentConfig({ //鉴权(应用的身份与权限)
- corpid: appSignature.corpid, // 必填,企业微信的corpid,必须与当前登录的企业一致
- agentid: appSignature.agentid, // 必填,企业微信的应用id (e.g. 1000247)
- timestamp: appSignature.timestamp, // 必填,生成签名的时间戳
- nonceStr: appSignature.nonceStr, // 必填,生成签名的随机串
- signature: appSignature.signature, // 必填,签名,见附录-JS-SDK使用权限签名算法
- jsApiList: ['selectExternalContact'], //必填
- success: function (res) { // 回调 // wx.agentConfig成功回调后,WWOpenData 才会注入到 window 对象上面
- console.log('agentConfig成功')
- // console.log('回调')
- // console.log(res)
- console.log('window.WWOpenData')
- console.log(window.WWOpenData)
- if (next) {
- next()
- }
- if (pushindex) {
- console.log('跳转首页')
- Router.push({
- path: '/'
- }) //跳转首页
- }
- },
- fail: function (res) {
- console.log(res)
- if (res.errMsg.indexOf('function not exist') > -1) {
- alert('版本过低请升级')
- }
- }
- });
- }
- });
- }
- // export const wxAuth = async (to,pushindex) => {
- // // const tempUrl = window.location.protocol + '//' + window.location.host + '/nwd-enterprise-wechat' + to.fullPath;
- // // const urlNow = encodeURIComponent(tempUrl);
- // // console.log('当前授权URL:', urlNow);
- // // const noncestr = Math.floor(Math.random() * 100000000000000);
- // // const body = {
- // // url: urlNow,
- // // timestamp: (new Date()) - 0,
- // // nonceStr: noncestr
- // // };
- // console.log('111111')
- // const body = window.location.href.split('#')[0]
- // console.log(body)
- // var data ;
- // await allocations(body).then((res)=>{
- // console.log('1111111111')
- // if(res.data.code == 1){
- // data = res.data.data
- // console.log(res.data.data.agentConfig)
- // return res.data.data.agentConfig
- // }
- // })
- // const wxConfigParams = data.config
- // const appSignature = data.agentConfig
- // console.log(wxConfigParams)
- // console.log(appSignature)
- // // const wxConfigParams = network.common.getWxConfigParams(body); // 通过接口,获取wxConfig的参数
- // // const appSignature = network.common.getAppSignature(body); // 通过接口,获取agentConfig的参数
- // Vue.prototype.$wx.config({
- // beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
- // debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
- // appId: wxConfigParams.appId, // 必填,企业微信的corpID
- // timestamp: wxConfigParams.timestamp, // 必填,生成签名的时间戳
- // nonceStr: wxConfigParams.nonceStr, // 必填,生成签名的随机串
- // signature: wxConfigParams.signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法
- // jsApiList: [
- // 'shareAppMessage',
- // 'previewFile',
- // 'selectEnterpriseContact',
- // 'onMenuShareAppMessage',
- // 'invoke',
- // 'hideOptionMenu',
- // 'showOptionMenu'
- // ] // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
- // });
- // Vue.prototype.$wx.ready(function() {
- // console.log('wx.agentConfig:BEGIN');const u = navigator.userAgent;
- // const isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; // 安卓
- // const isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); // ios终端
- // if (isAndroid) {
- // console.log('安卓手机');
- // Vue.prototype.$wx.invoke('agentConfig', {
- // corpid: appSignature.appId, // 必填,企业微信的corpid,必须与当前登录的企业一致
- // agentid: appSignature.agentid, // 必填,企业微信的应用id (e.g. 1000247)生产环境 写自己环境的agentid
- // timestamp: appSignature.timestamp, // 必填,生成签名的时间戳
- // nonceStr: appSignature.nonceStr, // 必填,生成签名的随机串
- // signature: appSignature.signature, // 必填,签名,见附录-JS-SDK使用权限签名算法
- // jsApiList: [
- // 'openUserProfile',
- // 'previewFile'
- // ], // 必填
- // }, function(res) {
- // console.log('result', res);
- // });
- // }
- // if (isIOS) {
- // console.log('苹果手机');
- // Vue.prototype.$wx.agentConfig({
- // corpid: appSignature.appId, // 必填,企业微信的corpid,必须与当前登录的企业一致
- // agentid: appSignature.agentid, // 必填,企业微信的应用id (e.g. 1000247)生产环境
- // timestamp: appSignature.timestamp, // 必填,生成签名的时间戳
- // nonceStr: appSignature.nonceStr, // 必填,生成签名的随机串
- // signature: appSignature.signature, // 必填,签名,见附录-JS-SDK使用权限签名算法
- // jsApiList: [
- // 'openUserProfile',
- // 'previewFile'
- // ], // 必填
- // success(res) {
- // console.log('agentConfig', res);
- // },
- // fail(res) {
- // console.log('err', res);
- // if (res.errMsg.indexOf('function not exist') > -1) {
- // alert('版本过低请升级');
- // }
- // }
- // });
- // }
- // if(/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
- // }else{
- // console.log('pc端')
- // console.log('wxConfig成功')
- // Vue.prototype.$wx.agentConfig({
- // corpid: appSignature.corpid, // 必填,企业微信的corpid,必须与当前登录的企业一致
- // agentid: appSignature.agentid, // 必填,企业微信的应用id (e.g. 1000247)
- // timestamp: appSignature.timestamp, // 必填,生成签名的时间戳
- // nonceStr: appSignature.nonceStr, // 必填,生成签名的随机串
- // signature: appSignature.signature,// 必填,签名,见附录-JS-SDK使用权限签名算法
- // jsApiList: ['selectExternalContact'], //必填
- // success: function(res) { // 回调
- // console.log('agentConfig成功')
- // console.log(res)
- // //wx.agentConfig成功回调后,WWOpenData 才会注入到 window 对象上面
- // console.log(window.WWOpenData)
- // // if(routpush){
- // // Router.push({path: '/'})//跳转首页
- // // }
- // console.log(to)
- // if(pushindex){
- // Router.push({path: '/'})//跳转首页
- // }else{
- // Router.push({path: to.path})//跳转首页
- // }
- // },
- // fail: function(res) {
- // console.log(res)
- // if(res.errMsg.indexOf('function not exist') > -1){
- // alert('版本过低请升级')
- // }
- // }
- // });
- // }
- // });
- // };
|