itchat 微信接口不能直接发消息给指定用户

很久没有用itchat,最近有需求需要用到,所以把以前用的代码进行复用。

    itchat.auto_login(hotReload=True)
    
    itchat.send(content,toUserName='filehelper')
    account=itchat.get_friends('user1')
    print account
    itchat.send(content, toUserName='user1')


结果是用户user1没有收到消息。而filehelper却可以收到用户消息


折腾了一番,去最新的官方更新了看了下,现在只能支持用user1的数字序列进行发送消息。


比如 上面的account中,里面有一个Username @ 一串数字的


<User: {u'UserName': u'@c49f3dd811957bd5ed998410d74560716cc0511e6a861c048adf387aa5c8577c', u'City': u'\u6df1\u5733', u'DisplayName': u'', u'UniFriend': 0, 'MemberList': <ContactList: []>, u'PYQuanPin': u'junge', u'RemarkPYInitial': u'', u'Uin': 0, u'AppAccountFlag': 0, u'VerifyFlag': 0, u'Province': u'\u5e7f\u4e1c', u'KeyWord': u'', u'RemarkName': u'', u'PYInitial': u'JG', u'ChatRoomId': 0, u'IsOwner': 0, u'HideInputBarFlag': 0, u'EncryChatRoomId': u'', u'AttrStatus': 236325, u'SnsFlag': 1, u'MemberCount': 0, u'OwnerUin': 0, u'Alias': u'', u'Signature': u'\u5988\u5988\uff0c\u6211\u6c38\u8fdc\u6000\u5ff5\u60a8\uff0c\u6c38\u8fdc\u6d3b\u5728\u6211\u5fc3\u4e2d\uff0c\u795d\u60a8\u5728\u5929\u5802\u5b89\u597d', u'ContactFlag': 3, u'NickName': u'\u541b\u54e5', u'RemarkPYQuanPin': u'', u'HeadImgUrl': u'/cgi-bin/mmwebwx-bin/webwxgeticon?seq=641471480&username=@c49f3dd811957bd5ed998410d74560716cc0511e6a861c048adf387aa5c8577c&skey=@crypt_7801355c_17bd503bf8c1b2f92998687691a9c156', u'Sex': 1, u'StarFriend': 0, u'Statues': 0}>,


那么上面的数字就是用户的数字序列,你只要把

itchat.send(content, toUserName='user1')

中的user1改为@c49f3dd811957bd5ed998410d74560716cc0511e6a861c048adf387aa5c8577c 就可以了。

记得@不能漏。



  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值