阅读量:1
声明企业微信方法
import * as ww from '@wecom/jssdk' import Taro, { ENV_TYPE, getCurrentInstance } from '@tarojs/taro' import { BaseApi, HttpUtil, Url } from '../utils/net/index' import { get as getGlobalData } from '../global_data' const getCurExternalContact = (jumpUrl, Callback) => { let currentUrl = Url.curDomain + '/' HttpUtil.post(BaseApi + '/MiniOfficial/WeChat/ZJLS_AgentConfig', { jumpUrl: jumpUrl }, false).then(res => { ww.register({ corpId: res.Data.corpid, // 必填,当前用户企业所属企业ID agentId: res.Data.agentid, // 必填,当前应用的AgentID jsApiList: ['getCurExternalContact'], // 必填,需要使用的JSAPI列表 getConfigSignature, // 必填,根据url生成企业签名的回调函数 getAgentConfigSignature // 必填,根据url生成应用签名的回调函数 }) async function getConfigSignature(url) { // 根据 url 生成企业签名 // 生成方法参考 https://open.work.weixin.qq.com/api/doc/90001/90144/93197 return { timestamp: res.Data.timestamp, nonceStr: res.Data.nonceStr, signature: res.Data.signature_QiYe } } async function getAgentConfigSignature(url) { // 根据 url 生成应用签名,生成方法同上,但需要使用应用的 jsapi_ticket return { timestamp: res.Data.timestamp, nonceStr: res.Data.nonceStr, signature: res.Data.signature_YingYong } } console.log(Callback) try { ww.getCurExternalContact({ success: r => { console.log(r, '成功了') // alert(r.userId) if (r.userId && Callback) { Callback(r.userId) } }, fail: err => { console.log(err) Taro.showToast({ icon: 'none', title: '当前用户无权获取外部联系人信息,请联系管理员', duration: 3000 }) } }) } catch (error) { Taro.showToast({ icon: 'none', title: ' ' }) console.log(error) } }) } export default getCurExternalContact
使用在需要用到的页面里调用
import getCurExternalContact from '@/utils/qyWeChat.js' // 使用方法 getQywxUserid = async () => { const { switchItem } = this.state getCurExternalContact(window.location.href, async externalUserid => { console.log('====================================') console.log(externalUserid) console.log('====================================') // 获取店铺信息列表和用户的userid const shop = await HttpUtil.post(BaseApi + '/MiniOfficial/WeChat/ZJLS_QY_WeChatUserInfo_ZJ_User_Shops', { externalUserid }, false) console.log(shop) if (shop?.Data?.UserId) { this.setState({ userId: shop.Data.UserId, selectshop: shop.Data.Shops[0], shopId: shop.Data.Shops[0].ShopId, shopList: shop.Data.Shops }, () => this.getVipInfo(switchItem.urlName)) } else { Taro.showToast({ icon: 'none', title: '请该客户先登录中酒网小程序,以便系统能更准确地查询相关信息。', duration: 3000 }) } }) // console.log(scanQRCodeH5) }