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 就可以了。

記得@不能漏。



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章