h5链接企业微信WECOM-JSSDK的使用(2)

声明企业微信方法

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)
  }
  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值