Files
smart-wx-demo/dist/wecomp.js
T
2026-01-12 18:01:04 +08:00

54 lines
2.0 KiB
JavaScript

import { WeChatClient } from "./wechat-client.js";
export async function handleWecomp() {
// 检查环境变量
if (process.env.WEIXIN_CORP_ID == null ||
process.env.WEIXIN_CORP_SECRET == null) {
throw new Error('环境变量错误:请设置 WEIXIN_CORP_ID 和 WEIXIN_CORP_SECRET');
}
// 创建企业微信客户端
const client = new WeChatClient({
corpId: process.env.WEIXIN_CORP_ID,
corpSecret: process.env.WEIXIN_CORP_SECRET,
baseUrl: process.env.WEIXIN_CORP_URL || 'https://qyapi.weixin.qq.com',
});
try {
// 示例:获取配置了客户联系功能的成员列表
console.log('\n=== 获取配置了客户联系功能的成员列表 ===');
const followUserList = await client.getFollowUserList();
console.log('\n--- 成员列表 ---');
console.log('成员数量:', followUserList.follow_user?.length || 0);
if (!followUserList.follow_user || followUserList.follow_user.length === 0) {
console.log('没有配置了客户联系功能的成员');
return;
}
console.log('成员ID列表:');
followUserList.follow_user.forEach((id, index) => {
console.log(` ${index + 1}. ${id}`);
});
let userId = 'YeDeLiang';
if (!userId) {
console.log('错误:无法获取有效的成员userid');
return;
}
const res = await client.getContactWay({
config_id: 'd5990127d833c10d9db8ba7f192e7b19'
});
console.log(res);
}
catch (error) {
if (error instanceof Error) {
console.error('发生错误:', error.message);
const err = error;
if (err.errcode !== undefined) {
console.error('错误码:', err.errcode);
}
if (err.errmsg !== undefined) {
console.error('错误信息:', err.errmsg);
}
}
else {
throw error;
}
}
}
//# sourceMappingURL=wecomp.js.map