http://localhost:4200/wxwork/cDL6R1hgSi/chat-activation/wrgKCxBwAALwOgUC9jMwdHiVTFmyXs_A
打开浏览器控制台(F12),运行以下脚本:
(async () => {
try {
const cid = 'cDL6R1hgSi';
const wxworkChatId = 'wrgKCxBwAALwOgUC9jMwdHiVTFmyXs_A'; // 你的企微群聊ID
const userid = 'woAs2qCQAAGQckyg7AQBxhMEoSwnlTvg';
// 配置localStorage
localStorage.setItem('company', cid);
localStorage.setItem(`${cid}/USERINFO`, JSON.stringify({
userid: userid,
errcode: 0,
errmsg: 'ok',
cid: cid
}));
console.log('✅ localStorage配置成功');
// 导入Parse
const { FmodeParse } = await import('fmode-ng/parse');
const Parse = FmodeParse.with('nova');
console.log('🔍 查询群聊记录...');
// 1. 先查询Parse数据库中是否已有记录
const query = new Parse.Query('GroupChat');
query.equalTo('chat_id', wxworkChatId);
query.equalTo('company', { __type: 'Pointer', className: 'Company', objectId: cid });
query.include('project');
let groupChat = await query.first();
if (groupChat) {
console.log('✅ 找到现有群聊记录:', {
objectId: groupChat.id,
chat_id: groupChat.get('chat_id'),
name: groupChat.get('name'),
memberCount: (groupChat.get('member_list') || []).length
});
const url = `http://localhost:4200/wxwork/${cid}/chat-activation/${groupChat.id}`;
await navigator.clipboard.writeText(url);
alert(`✅ 找到群聊记录!地址已复制\n\n群聊名称: ${groupChat.get('name')}\n\n${url}\n\n点击确定后自动打开...`);
setTimeout(() => window.open(url, '_blank'), 500);
} else {
console.log('⚠️ Parse数据库中未找到记录,正在创建...');
// 2. 创建新的群聊记录
const GroupChat = Parse.Object.extend('GroupChat');
const newGroupChat = new GroupChat();
newGroupChat.set('chat_id', wxworkChatId);
newGroupChat.set('name', '企微群聊 - ' + new Date().toLocaleString('zh-CN'));
newGroupChat.set('company', { __type: 'Pointer', className: 'Company', objectId: cid });
newGroupChat.set('member_list', []); // 企微API会同步
newGroupChat.set('data', {
createdFrom: 'test-script',
createdAt: new Date(),
wxworkChatId: wxworkChatId
});
groupChat = await newGroupChat.save();
console.log('✅ 群聊记录已创建:', {
objectId: groupChat.id,
chat_id: groupChat.get('chat_id')
});
const url = `http://localhost:4200/wxwork/${cid}/chat-activation/${groupChat.id}`;
await navigator.clipboard.writeText(url);
alert(`✅ 群聊记录已创建!地址已复制\n\n${url}\n\n页面会自动从企微API同步群聊信息\n\n点击确定后自动打开...`);
setTimeout(() => window.open(url, '_blank'), 500);
}
} catch (e) {
console.error('❌ 错误:', e);
alert('❌ 发生错误: ' + e.message + '\n\n请确保:\n1. 项目已启动\n2. Parse Server已连接');
}
})();
我已经更新了 chat-activation.component.ts,现在支持:
// 方式1:通过Parse objectId查询
gcQuery.equalTo('objectId', this.chatId);
// 方式2:通过企微chat_id查询
gcQuery.equalTo('chat_id', this.chatId);
gcQuery.equalTo('company', { __type: 'Pointer', className: 'Company', objectId: this.cid });
async syncFromWxwork() {
// 调用企微API获取最新信息
const chatInfo = await this.wecorp.externalContact.groupChat.get(chatIdValue);
// 更新群聊名称、成员列表等
this.groupChat.set('name', chatInfo.group_chat.name);
this.groupChat.set('member_list', chatInfo.group_chat.member_list);
// 保存到Parse数据库
await this.groupChat.save();
}
async createFromWxwork() {
// 如果Parse中没有记录,从企微API获取并创建
const chatInfo = await this.wecorp.externalContact.groupChat.get(this.chatId);
// 创建新的GroupChat记录
const newGroupChat = new GroupChat();
newGroupChat.set('chat_id', this.chatId);
newGroupChat.set('name', chatInfo.group_chat.name);
// ... 保存到Parse
}
cd yss-project
npm start
http://localhost:4200
脚本会:
需要配置应用权限
API调用限制
数据访问范围
页面会:
打开控制台可以看到详细的日志:
📥 开始加载数据...
📋 参数: { cid: 'cDL6R1hgSi', chatId: 'wrgKCxBwAALwOgUC9jMwdHiVTFmyXs_A' }
🔍 查询群聊...
✅ 找到群聊: XXX群聊
📊 群聊信息: { objectId: 'xxx', chat_id: 'wrgKCxBwAALwOgUC9jMwdHiVTFmyXs_A', ... }
🔄 从企微API同步群聊信息, chat_id: wrgKCxBwAALwOgUC9jMwdHiVTFmyXs_A
✅ 企微API返回数据: { name: 'xxx', member_list: [...] }
如果Parse中已有记录,可以直接访问:
http://localhost:4200/wxwork/cDL6R1hgSi/chat-activation/wrgKCxBwAALwOgUC9jMwdHiVTFmyXs_A
页面会:
objectId 查询chat_id 查询现在运行上面的脚本开始测试吧! 🚀