test.py 3.1 KB
Newer Older
L
ljc545w 已提交
1 2 3 4
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 16 14:06:24 2022

L
ljc545w 已提交
5
@author: ljc545w
L
ljc545w 已提交
6 7
"""
import time
L
ljc545w 已提交
8
import os
L
ljc545w 已提交
9
import wxRobot
L
ljc545w 已提交
10
from wxRobot import WeChatRobot
L
ljc545w 已提交
11 12 13


def test_send_text(instance):
L
ljc545w 已提交
14 15
    path = os.path.split(os.path.realpath(__file__))[0]
    # image full path
L
ljc545w 已提交
16
    img_path = os.path.join(path, 'test\\测试图片.png')
L
ljc545w 已提交
17
    # file full path
L
ljc545w 已提交
18 19 20 21 22 23
    filepath = os.path.join(path, 'test\\测试文件')
    self_info = instance.GetSelfInfo()
    chat_with = instance.GetFriendByWxNickName("文件传输助手")
    session = instance.GetChatSession(chat_with.get('wxid'))
    filehelper = instance.GetWxUserInfo(chat_with.get('wxid'))
    session.SendText('个人信息:{}'.format(str(self_info.get('wxNickName'))))
L
ljc545w 已提交
24
    session.SendText('好友信息:{}'.format(str(filehelper.get('wxNickName'))))
L
ljc545w 已提交
25 26 27 28 29 30 31 32 33 34 35 36 37 38
    if os.path.exists(img_path):
        session.SendImage(img_path)
    if os.path.exists(filepath):
        session.SendFile(filepath)
    session.SendArticle("天气预报", "点击查看", "http://www.baidu.com")
    shared = instance.GetFriendByWxNickName("码农翻身")
    if shared:
        session.SendCard(shared.get('wxid'), shared.get('wxNickName'))


def test_friend_status(instance):
    f = open('friend_status.txt', 'wt', encoding='utf-8')
    friend_list = instance.GetFriendList()
    index = "\t".join(['微信号', '昵称', '备注', '状态', '\n'])
L
ljc545w 已提交
39
    f.writelines(index)
L
ljc545w 已提交
40
    for Friend in friend_list:
L
ljc545w 已提交
41
        result = '\t'.join(
L
ljc545w 已提交
42 43
            [Friend.get('wxNumber'), Friend.get('wxNickName'), Friend.get('wxRemark'),
             instance.CheckFriendStatus(Friend.get('wxid'))])
L
ljc545w 已提交
44 45 46 47 48 49
        print(result)
        result += '\n'
        f.writelines(result)
        time.sleep(1)
        break
    f.close()
L
ljc545w 已提交
50 51 52


def test_execute_sql(instance):
L
ljc545w 已提交
53
    try:
L
ljc545w 已提交
54
        dbs = instance.GetDbHandles()
L
ljc545w 已提交
55 56 57
        dbname = 'MicroMsg.db'
        handle = dbs.get(dbname).get('Handle')
        sql = 'select a.UserName as `wxID`,a.Alias as `微信号`,a.EncryptUserName as `V3数据`,\
L
ljc545w 已提交
58 59
               a.Type as `联系人类型`,a.VerifyFlag as `添加方式`,a.Remark as `备注`,a.NickName as `昵称`,b.bigHeadImgUrl as `头像`,\
               a.ExtraBuf as `扩展数据` \
L
ljc545w 已提交
60
               from Contact a inner join ContactHeadImgUrl b where a.UserName=b.usrName and a.Type=3 limit 10'
L
ljc545w 已提交
61
        result = instance.ExecuteSQL(handle, sql)
L
ljc545w 已提交
62
        print(result)
L
ljc545w 已提交
63 64
    except Exception as e:
        print(e)
L
ljc545w 已提交
65 66 67


def test_BackupDb(instance):
L
ljc545w 已提交
68
    try:
L
ljc545w 已提交
69
        dbs = instance.GetDbHandles()
L
ljc545w 已提交
70 71
        dbname = 'MicroMsg.db'
        handle = dbs.get(dbname).get('Handle')
L
ljc545w 已提交
72
        rc = instance.BackupSQLiteDB(handle, 'D:\\WeChatBackup\\{}'.format(dbname))
L
ljc545w 已提交
73
        print(rc)
L
ljc545w 已提交
74 75 76
    except Exception as e:
        print(e)

L
ljc545w 已提交
77

L
ljc545w 已提交
78
def show_interfaces():
L
ljc545w 已提交
79
    robot = wxRobot.WeChatRobot(0).robot
L
ljc545w 已提交
80 81
    print(robot.CGetWeChatVer())
    interfaces = [i for i in dir(robot) if '_' not in i and i[0] == 'C']
L
ljc545w 已提交
82 83
    for interface in interfaces:
        print(interface)
L
ljc545w 已提交
84

L
ljc545w 已提交
85

L
ljc545w 已提交
86
if __name__ == '__main__':
L
ljc545w 已提交
87 88 89 90
    pid_list = wxRobot.get_wechat_pid_list()
    wx = WeChatRobot(pid_list[0])
    wx.StartService()
    wx.StartReceiveMessage()
91
    wxRobot.register_msg_event(wx.pid)
L
ljc545w 已提交
92
    wx.StopService()