注意:企业微信第三方应用打开企业微信添加好友功能,只能在移动端使用,PC端目前不支持!!
以第三方应用在企业微信里面打开添加好友的操作为例
在这之前,去企业微信里面配置相关的权限,具体看文档,下面是代码:
npm install wecomjsdk --save //安装jssdk
import wecomjsdk from "wecomjsdk" //引入jssdk
import { postWecomGetJsSdk } from '@/api/index.js' //后台签名算法等一堆参数
async created(){
this.initJssdk()
}
methods:{
async initJssdk(type) {
let that = this
let params = {
jsApiList: ["navigateToAddCustomer"],
url: window.location.href
}
let res = await postWecomGetJsSdk(params)
if (res.code != 200) return;
let wxx = wx ? wx : wecomjsdk;
if (wxx) {
window.wx = wxx
} else {
return;
}
wxx.config({
debug: res.data.wecomJsSdk.debug,
beta: res.data.wecomJsSdk.beta,
appId: res.data.wecomJsSdk.appId,
nonceStr: res.data.wecomJsSdk.nonceStr,
signature: res.data.wecomJsSdk.signature,
timestamp: res.data.wecomJsSdk.timestamp,
jsApiList: ['navigateToAddCustomer'],
});
wxx.ready(function() {
wxx.agentConfig({
corpid: res.data.agentJsSdk.corpid,
agentid: res.data.agentJsSdk.agentid,
timestamp: res.data.agentJsSdk.timestamp,
nonceStr: res.data.agentJsSdk.nonceStr,
signature: res.data.agentJsSdk.signature,
jsApiList: ['navigateToAddCustomer'], //必填,传入需要使用的接口名称
success: function(res) {
console.log(res)
},
fail: function(res) {
console.log(res)
if (res.errMsg.indexOf('function not exist') > -1) {
uni.showToast({
icon: "none",
title: '版本过低,请升级'
})
}
}
})
})
},
handleClick(){
wx.invoke('navigateToAddCustomer', {}, function(res) {
if (res.err_msg != "navigateToAddCustomer:ok") {}
});
}
}