使用wxpy库
目前微信小号,手机不登陆,wxpy只能保持20小时在线
照着官方手册抄下来的最简单的代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# pip install pillow wxpy # coding: utf-8 from __future__ import unicode_literals from wxpy import * import time dstart=0 def caltime(): global dstart if dstart==0: dstart=int(time.time()) dnow=int(time.time()) ddiff=dnow-dstart dday=ddiff//86400 dhour=ddiff%86400//3600 dminute=ddiff%3600//60 dsecond=ddiff%60 return (dday,dhour,dminute,dsecond) bot = Bot('bot.pkl',console_qr=True) caltime() # my_friend = bot.friends().search("xx")[0] # my_friend.send('Hello WeChat!') @bot.register(Friend) def reply_test(msg): msg.reply('在线时间 %s 天 %s 小时 %s 分钟 %s 秒'%caltime()) msg.reply(msg.text+' .. got it!') bot.join() |