【企业微信新版sdk】

wecom 的引入使用

一、引入wecom

  • 1、企业微信 WECOM-JSSDK提供了 npm 和 cdn 两种引入途径。

  • 1.1、 npm 引入

    npm install @wecom/jssdk

  • 1.2、安装后引入

    import * as ww from '@wecom/jssdk'

  1. 通过 script 标签引入

    <script src="https://wwcdn.weixin.qq.com/node/open/js/wecom-jssdk-2.0.2.js"></script>

注:详见: 企业微信

二、封装函数

  1. 制作全局工具函数

    import {jssdk} from '../api/approval/approval';
    import * as ww from '@wecom/jssdk'
    /**
    *** 作者: Lenovo-【Lindon】
    *** 文件名称: weChat
    *** 文件创建日期: 2024/4/10 14:11


    */
    const wwChatMixin = {
    data() {
    return {};
    },
    methods: {
    async wwRegister(sysAgentId, url, callback) {
    debugger;
    const res = await jssdk({sysAgentId: sysAgentId, url: url});
    ww.register({
    corpId: res.config.appId,
    jsApiList: ['selectExternalContact'],
    getConfigSignature() {
    console.log('ww.getSignature',ww);
    return ww.getSignature(res.config.signature);
    },
    });

    复制代码
             if (callback && typeof callback === 'function') {
               callback(ww);
             }
         },
     },

    };

    export default wwChatMixin;

2.通过后端接口 api/approval/approval 后去企业微信的相关数据

  1. ww.register 进行注册,获取签名

  2. 暴露出去使用

三、使用测试

复制代码
<template>
    <div>
        <!--    wecom-->
        <van-button @click="getwxAgentConfig">使用</van-button>
    </div>
</template>

<script>
import wwChatMixin from '../../mixin/weChat';

export default {
    /**
     *** 作者: Lenovo-【Lindon】
     *** 文件名称: wecom
     *** 文件创建日期: 2024/4/10 14:21
     ***
     */
    name: 'Wecom',
    components: {},
    mixins: [wwChatMixin],
    props: {},
    data() {
        return {};
    },
    created() {},
    mounted() {},
    methods: {
        // 使用
        // const url = window.location.href.split('#')[0];
        getwxAgentConfig() {
            this.wwRegister(1, window.location.href.split('#')[0], ww => {
              debugger;
                ww.selectExternalContact({
                    success(res) {
                      console.log('666',res);
                      alert(JSON.stringify(res));
                    },
                });
            });
        },
    },
};
</script>

<style scoped></style>
相关推荐
vx-bot55566639 分钟前
企业微信接口在混合云环境下的集成架构与网络互联方案企业微信接口在混合云环境下的集成架构与网络互联方案
网络·架构·企业微信
王者鳜錸1 天前
企业微信自动化发消息-从0到1开发实践
运维·自动化·企业微信
梦想的旅途22 天前
RPA 驱动企微非官方 API:外部群批量推送核心优化
企业微信·rpa
2501_941982052 天前
企微非官方API开发:RPA与协议结合的混合驱动实现
网络·企业微信·rpa
2501_941982052 天前
半手企微 API 开发:RPA 架构下外部群功能落地的关键步骤
架构·企业微信·rpa
fengkaiyz3 天前
企业微信会话存档服务
企业微信
天空属于哈夫克33 天前
企微自动化控制台:跨语言调用与多进程管理的技术架构
架构·自动化·企业微信
2501_941982053 天前
企微中台架构:非官方接口与企业私有化 CRM 的深度集成
架构·企业微信
vx-bot5556664 天前
企业微信接口在微服务协同架构中的事件桥接与状态同步模式
微服务·架构·企业微信
2501_941982054 天前
企业微信外部群精准运营:API 主动推送消息开发指南
大数据·人工智能·企业微信