123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- import {getWorkConfig,getWorkAgentConfig} from "@/api/work.js"
- export function initWxConfig() {
- return getTicket;
- }
- export function initAgentConfig() {
- return agentConfig;
- };
-
- const getTicket = new Promise((resolve, reject) => {
- getWorkConfig(window.location.href.split('#')[0]).then(res=>{
- if (/(iPhone|iPad|iPod|iOS|macintosh|mac os x)/i.test(navigator.userAgent)) {
- jWeixin.config({
- beta: true,
- debug: false,
- appId: res.data.appId,
- timestamp:res.data.timestamp ,
- nonceStr: res.data.nonceStr,
- signature: res.data.signature,
-
- jsApiList: ["getCurExternalContact", "getCurExternalChat", "getContext", "chooseImage","sendChatMessage","shareAppMessage"]
- });
- jWeixin.ready(function() {
-
- setTimeout(()=>{
- getWorkAgentConfig(window.location.href.split('#')[0]).then(response=>{
- let jWeixi = wx;
- jWeixi.agentConfig({
- corpid: response.data.corpid,
- agentid: response.data.agentid,
- timestamp: response.data.timestamp,
- nonceStr: response.data.nonceStr,
- signature: response.data.signature,
-
- jsApiList: ["getCurExternalContact", "getCurExternalChat", "getContext", "chooseImage","sendChatMessage","shareAppMessage"],
- success: function(data) {
- resolve(data);
- },
- fail: function(err) {
- if(err.errMsg.indexOf('function not exist') > -1){
- reject('版本过低请升级');
- }
- }
- });
- })
- },1000)
- })
- }else{
-
- jWeixin.config({
- beta: true,
- debug: false,
- appId: res.data.appId,
- timestamp:res.data.timestamp ,
- nonceStr: res.data.nonceStr,
- signature: res.data.signature,
- jsApiList: ["getCurExternalContact", "getCurExternalChat", "getContext", "chooseImage","sendChatMessage","shareAppMessage"]
- });
- jWeixin.ready(function() {
-
- getWorkAgentConfig(location.href).then(response=>{
- jWeixin.agentConfig({
- corpid: response.data.corpid,
- agentid: response.data.agentid,
- timestamp: response.data.timestamp,
- nonceStr: response.data.nonceStr,
- signature: response.data.signature,
-
- jsApiList: ["getCurExternalContact", "getCurExternalChat", "getContext", "chooseImage","sendChatMessage","shareAppMessage"],
- success: function(data) {
- resolve(data);
- },
- fail: function(err) {
- if(err.errMsg.indexOf('function not exist') > -1){
- reject('版本过低请升级');
- }
- }
- });
- })
- })
- }
-
- }).catch(err=>{
- reject(err);
- })
- })
- const agentConfig = new Promise((resolve, reject)=>{
- getWorkAgentConfig(location.href).then(res=>{
- wx.agentConfig({
- corpid: res.data.corpid,
- agentid: res.data.agentid,
- timestamp: res.data.timestamp,
- nonceStr: res.data.nonceStr,
- signature: res.data.signature,
- jsApiList: ["getCurExternalContact", "getCurExternalChat", "getContext", "chooseImage","sendChatMessage","shareAppMessage"]
- ,
- success: function(res) {
- resolve(res);
- },
- fail: function(res) {
- if(res.errMsg.indexOf('function not exist') > -1){
- reject('版本过低请升级');
- }
- }
- });
- })
- })
-
|