From 006bc9dac3fb0752fafd871ee37b4f2903877477 Mon Sep 17 00:00:00 2001 From: LuChao Date: Thu, 21 Mar 2024 20:33:05 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85demo=E8=B0=83=E7=94=A8?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nodejs_client_ts/example/ding-dong-bot.ts | 82 ++++++++++++++++++++++- nodejs_client_ts/src/index.ts | 40 ++++++++++- 2 files changed, 117 insertions(+), 5 deletions(-) diff --git a/nodejs_client_ts/example/ding-dong-bot.ts b/nodejs_client_ts/example/ding-dong-bot.ts index 46ed0ff..4d3416c 100644 --- a/nodejs_client_ts/example/ding-dong-bot.ts +++ b/nodejs_client_ts/example/ding-dong-bot.ts @@ -36,6 +36,11 @@ const main = async () => { // server.listen(wsPort, () => { // console.log(`Server listening on port ${wsPort}`) // }) + const testContact0 = 'filehelper' + const testContact1 = 'ledongmao' + const testRoom = '1234@chatroom' + const testRoom1 = '5678@chatroom' + const checkLoginRes = await wxhelper.checkLogin() console.log('登录状态:', checkLoginRes.data) if (checkLoginRes.data.msg !== 'success') { @@ -52,8 +57,81 @@ const main = async () => { } const userInfoRes = await wxhelper.userInfo() console.log('当前账号信息:', userInfoRes.data) - const sendTextMsgRes = await wxhelper.sendTextMsg('filehelper', new Date().toLocaleString() + ':你好,我是机器人') - console.log('发送文本消息:', sendTextMsgRes.data) + const selfWxid = userInfoRes.data.data.wxid + console.log('当前账号wxid:', selfWxid) + // const sendTextMsgRes = await wxhelper.sendTextMsg('filehelper', new Date().toLocaleString() + ':你好,我是机器人') + // console.log('发送文本消息:', sendTextMsgRes.data) + + // const getContactListRes = await wxhelper.getContactList() + // console.log('获取联系人列表:', getContactListRes.data.data.length) + + // const getDBInfo = await wxhelper.getDBInfo() + // console.log('获取数据库信息:', getDBInfo.data) + + // const sqliteDB = await wxhelper.execSql(2737761293968, 'select * from MSG where localId =301;') + // console.log('查询数据库:', sqliteDB.data) + + // const roomInfoRes = await wxhelper.getChatRoomDetailInfo(testRoom1) + // console.log('获取群聊详情:', roomInfoRes.data) + + // const addMemberToChatRoomRes = await wxhelper.addMemberToChatRoom(testRoom, testContact1) + // console.log('添加群成员:', addMemberToChatRoomRes.data) + + // const modifyChatRoomNameRes = await wxhelper.modifyNickname(testRoom, selfWxid, '大师') + // console.log('修改自己的群名片:', modifyChatRoomNameRes.data) + + // const delMemberFromChatRoomRes = await wxhelper.delMemberFromChatRoom(testRoom, testContact1) + // console.log('删除群成员:', delMemberFromChatRoomRes.data) + + // const getChatRoomMembersRes = await wxhelper.getMemberFromChatRoom(testRoom) + // console.log('获取群成员:', getChatRoomMembersRes.data) + + // const quitChatRoomRes = await wxhelper.quitChatRoom(testRoom1) + // console.log('退出群聊:', quitChatRoomRes.data) + + // const getSNSFirstPage = await wxhelper.getSNSFirstPage() + // console.log('获取朋友圈:', getSNSFirstPage.data) + + // const getSNSNextPage = await wxhelper.getSNSNextPage() + // console.log('获取朋友圈下一页:', getSNSNextPage.data) + + // const sendAtTextMsgRes = await wxhelper.sendAtText(testContact1, testRoom, '你好,我是机器人') + // console.log('发送@消息:', sendAtTextMsgRes.data) + + // const getContactProfileRes = await wxhelper.getContactProfile(testContact1) + // console.log('获取联系人详情:', getContactProfileRes.data) + + // const param = { + // appName: '123', + // userName: '超哥', + // title: '测试转发公众号消息', + // url: 'https://mp.weixin.qq.com/s?__biz=MzIwMzYwMTk1NA==&mid=2247483663&idx=1&sn=', + // thumbUrl: 'https://mmbiz.qpic.cn/mmbiz_jpg/3ic3Zz3', + // digest: '测试', + // wxid: testContact1, + // } + + // const forwardPublicMsgRes = await wxhelper.forwardPublicMsg(param) + // console.log('转发公众号消息:', forwardPublicMsgRes.data) + + // const payload = { + // "wxid": testContact1, + // "waidConcat": "wxaf35009675aa0b2a_118", + // "waid": "wxaf35009675aa0b2a", + // "appletWxid": "gh_7a5c4141778f@app", + // "jsonParam": "{\"current_path\":\"home/pages/index.html\",\"current_title\":\"\",\"image_url\":\"https://ut-static.udache.com/webx/mini-pics/U7mDFxU2yh-2-r1BJ-J0X.png\",\"scene\":1001,\"scene_note\":\"\",\"sessionId\":\"SessionId@1672284921_1#1692848476899\"}", + // "headImgUrl": "http://mmbiz.qpic.cn/sz_mmbiz_png/9n47wQlh4dH8afD9dQ9uQicibRm5mYz3lawXCLMjmnzFicribH51qsFYxjzPEcTGHGmgX4lkAkQ3jznia8UDEtqsX1w/640?wx_fmt=png&wxfrom=200", + // "mainImg": "C:\\wxid_123123\\Applet\\wxaf35009675aa0b2a\\temp\\2.png", + // "indexPage": "pages/index/index.html" + // } + // const sendAppMsgRes = await wxhelper.sendApplet(payload) + // console.log('发送小程序消息:', sendAppMsgRes.data) + + // const sendPatMsgRes = await wxhelper.sendPatMsg(testRoom1, testContact1) + // console.log('拍一拍:', sendPatMsgRes.data) + + // const ocrRes = await wxhelper.ocr('https://ut-static.udache.com/webx/mini-pics/U7mDFxU2yh-2-r1BJ-J0X.png') + // console.log('OCR识别:', ocrRes.data) } void main() \ No newline at end of file diff --git a/nodejs_client_ts/src/index.ts b/nodejs_client_ts/src/index.ts index 88d630d..50d552e 100644 --- a/nodejs_client_ts/src/index.ts +++ b/nodejs_client_ts/src/index.ts @@ -415,7 +415,7 @@ export const getSNSNextPage = (snsId: string) => { export const addFavFromMsg = (msgId: string) => { return post('/api/addFavFromMsg', { msgId }) } - + // def addFavFromImage(): // print("modify wxid imagePath ") // raise RuntimeError("modify wxid imagePath then deleted me") @@ -497,8 +497,16 @@ export const sendAtText = (wxids: string, chatRoomId: string, msg: string) => { // response = requests.request("POST", url, headers=headers, data=payload) // print(response.text) -export const forwardPublicMsg = (appName: string, userName: string, title: string, url: string, thumbUrl: string, digest: string, wxid: string) => { - return post('/api/forwardPublicMsg', { appName, userName, title, url, thumbUrl, digest, wxid }) +export const forwardPublicMsg = (param: { + appName: string; + userName: string; + title: string; + url: string; + thumbUrl: string; + digest: string; + wxid: string +}) => { + return post('/api/forwardPublicMsg', param) } // def forwardPublicMsgByMsgId(): @@ -581,3 +589,29 @@ export const decodeImage = (filePath: string, storeDir: string) => { export const getVoiceByMsgId = (msgId: number, storeDir: string) => { return post('/api/getVoiceByMsgId', { msgId, storeDir }) } + +// /api/sendApplet +export const sendApplet = (param: { + wxid: string + waidConcat: string + appletWxid: string + jsonParam: string + headImgUrl: string + mainImg: string + indexPage: string +}) => { + return post('/api/sendApplet', param) +} + +// /api/sendPatMsg +export const sendPatMsg = (receiver: string, + wxid: string) => { + return post('/api/sendPatMsg', { wxid, receiver }) +} + +// /api/ocr +export const ocr = ( + imagePath: string +) => { + return post('/api/ocr', { imagePath }) +}