python的 itchat微信api文档的 itchat.send如何发信息给指定用户?

itchat.send_msg('Hello world')
<ItchatReturnValue: {u'MsgID': u'', u'LocalID': u'', u'BaseResponse': {u'ErrMsg': u'', u'Ret': 1204, 'RawMsg': u''}}>

不能发给自己信息

itchat.send('hello',toUserName = User)

发给别人也不行( User 是一个微信号

阅读 12k
1 个回答
#想给谁发信息,先查找到这个朋友
users = itchat.search_friends(name=u'通讯录备注名')
#找到UserName
userName = users[0]['UserName']
#然后给他发消息
itchat.send('hello',toUserName = userName)

或者每直接用这个用户发送

user = itchat.search_friends(name=u'通讯录备注名')[0]
user.send(u'机器人say hello')
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题