python wxpy模塊


API接口
參考


python微信接口使用

from wxpy import *

bot = Bot()

bot.file_helper.send('hello world!')

print("ending")


  """
bot中的參數
:param cache_path:
    * 設置當前會話的緩存路徑,並開啟緩存功能;為 `None` (默認) 則不開啟緩存功能。
    * 開啟緩存后可在短時間內避免重復掃碼,緩存失效時會重新要求登陸。
    * 設為 `True` 時,使用默認的緩存路徑 'wxpy.pkl'。
:param console_qr:
    * 在終端中顯示登陸二維碼,需要安裝 pillow 模塊 (`pip3 install pillow`)。
    * 可為整數(int),表示二維碼單元格的寬度,通常為 2 (當被設為 `True` 時,也將在內部當作 2)。
    * 也可為負數,表示以反色顯示二維碼,適用於淺底深字的命令行界面。
    * 例如: 在大部分 Linux 系統中可設為 `True` 或 2,而在 macOS Terminal 的默認白底配色中,應設為 -2。
:param qr_path: 保存二維碼的路徑
:param qr_callback: 獲得二維碼后的回調,可以用來定義二維碼的處理方式,接收參數: uuid, status, qrcode
:param login_callback: 登陸成功后的回調,若不指定,將進行清屏操作,並刪除二維碼文件
:param logout_callback: 登出時的回調
"""
from wxpy import *

bot = Bot()

# 獲取所有好友
friends = bot.friends()

# 遍歷輸出好友名稱
for friend in friends:
    print(friend)

# 找到好友
friend = bot.friends.search('被單')[0]
print(friend)
friend.send("hello world!")

# 獲取所有聊天群
groups = bot.groups()

for group in groups:
    print(group)

# 找到目標群
group = groups.search("409")[0]

group.send("hello world!")
from wxpy import *

bot = Bot()
# 獲取好友
my_friend = bot.friends().search('被單')[0]

# 搜索信息
messages = bot.messages.search(keywords='測試', sender=bot.self)

for message in messages:
    print(message)

# 發送文本
my_friend.send('Hello, WeChat!')
# 發送圖片
my_friend.send_image('my_picture.png')
# 發送視頻
my_friend.send_video('my_video.mov')
# 發送文件
my_friend.send_file('my_file.zip')
# 以動態的方式發送圖片
my_friend.send('@img@my_picture.png')

# 發送公眾號
my_friend.send_raw_msg(
    # 名片的原始消息類型
    raw_type=42,
    # 注意 `username` 在這里應為微信 ID,且被發送的名片必須為自己的好友
    raw_content='<msg username="wxpy_bot" nickname="wxpy 機器人"/>'
)


# 消息接收監聽器
@bot.register()
def print_others(msg):
    # 輸出監聽到的消息
    print(msg)
    # 回復消息
    msg.reply("hello world")


embed()


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM