增加ts客户端sdk

- 增加ts客户端sdk
- 优化python代码
This commit is contained in:
LuChao committed 2024-03-21 18:58:09 +08:00
1 parent ffa3ea49d9
commit 89a7fc8196
12 files changed
+1249 -85

No files matched your search

+59
View File
@@ -0,0 +1,59 @@
import * as wxhelper from '../src/index'
import net from 'net'
import {
writeMsgStore,
readMsgStore
} from '../src/utils/messageStore'
// 启动一个TCP服务,接收hook消息
const server = net.createServer((socket: any) => {
console.log('New client connected')
let messageStore = readMsgStore()
let data = Buffer.from('')
socket.on('data', (data: any, chunk: any) => {
console.log(`Received data: ${data}`)
const dataJson = JSON.parse(data)
messageStore = writeMsgStore(messageStore, dataJson)
// data = Buffer.concat([data, chunk])
// console.log(`Received data: ${data}`)
})
socket.on('end', () => {
const decodedData = data.toString('utf8')
console.log(`Received data: ${decodedData}`)
})
socket.on('close', () => {
console.log('Client disconnected')
})
})
const wsPort = 19099
const main = async () => {
// server.listen(wsPort, () => {
// console.log(`Server listening on port ${wsPort}`)
// })
const checkLoginRes = await wxhelper.checkLogin()
console.log('登录状态:', checkLoginRes.data)
if (checkLoginRes.data.msg !== 'success') {
console.log('请先登录')
return
} else {
const port = String(wsPort)
const ip = '127.0.0.1'
const url = ''
const timeout = '3000'
const enableHttp = '0'
const hookSyncMsgRes = await wxhelper.hookSyncMsg(port, ip, url, timeout, enableHttp)
console.log('开启hook:', hookSyncMsgRes.data)
}
const userInfoRes = await wxhelper.userInfo()
console.log('当前账号信息:', userInfoRes.data)
const sendTextMsgRes = await wxhelper.sendTextMsg('filehelper', new Date().toLocaleString() + ':你好,我是机器人')
console.log('发送文本消息:', sendTextMsgRes.data)
}
void main()