先給大家介紹下python微信自動回復功能
1.當收到好友消息時,自動回復
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
|
import random import itchat import requests import time def get_tuling_response(_info): print (_info) # 圖靈機器人的網址 api_url = "http://www.tuling123.com/openapi/api" data = { 'key' : '5ea0f11b5b6146239c52a47849387484' , 'info' : _info, 'userid' : 'wechat-robot' } # 發送數據到指定網址,獲取網址返回的數據(字典數據類型) res = requests.post(api_url, data).json() # print(res, type(res)) # 給用戶返回的內容 print (res[ 'text' ]) return res[ 'text' ] # 時刻監控好友發送的文本消息, 并且給予一個回復, # isGroupChat=True接收群聊消息中的文本信息, 并讓圖靈機器人自動回復; # isMapChat=True接收群聊消息中的文本信息, 并讓圖靈機器人自動回復; @itchat .msg_register(itchat.content.TEXT, isFriendChat = True ) def text_reply(msg): # 需求: 只對固定的群聊消息, 實現機器人聊天. # 獲取好友發送消息的內容 |
ps:下面介紹下python 批量生成微信添加好友截圖
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# -*- coding: utf-8 -*- import time,random,os import PIL.Image as Image import PIL.ImageColor as ImageColor import PIL.ImageDraw as ImageDraw import PIL.ImageFont as ImageFont # from PIL import Image, ImageDraw """ author@:xiaohe QQ496631085 python3.7 """ def circle_corner(img, radii): """ 圓角處理 :param img: 源圖象。 :param radii: 半徑,如:30。 :return: 返回一個圓角處理后的圖象。 """ # 畫圓(用于分離4個角) circle = Image.new( 'L' , (radii * 2 , radii * 2 ), 0 ) # 創建一個黑色背景的畫布 draw = ImageDraw.Draw(circle) draw.ellipse(( 0 , 0 , radii * 2 , radii * 2 ), fill = 255 ) # 畫白色圓形 # 原圖 img = img.convert( "RGBA" ) w, h = img.size # 畫4個角(將整圓分離為4個部分) alpha = Image.new( 'L' , img.size, 255 ) alpha.paste(circle.crop(( 0 , 0 , radii, radii)), ( 0 , 0 )) # 左上角 alpha.paste(circle.crop((radii, 0 , radii * 2 , radii)), (w - radii, 0 )) # 右上角 alpha.paste(circle.crop((radii, radii, radii * 2 , radii * 2 )), (w - radii, h - radii)) # 右下角 alpha.paste(circle.crop(( 0 , radii, radii, radii * 2 )), ( 0 , h - radii)) # 左下角 # alpha.show() img.putalpha(alpha) # 白色區域透明可見,黑色區域不可見 return img #對象,位置 字體 字體大小 字體顏色 添加內容 def imgAddFont(im1,gps,font,fontSize,fontColor,data): # 在圖片上添加文字 1 draw = ImageDraw.Draw(im1) #設置字體 time_font = ImageFont.truetype(font, fontSize) # (0,0):坐標 "內容":添加的字體 (0,0,255):字體顏色 font:字體大小 draw.text(gps,data,fontColor,font = time_font) draw = ImageDraw.Draw(im1) def copy(h,m,z,n,v): #手機當前時間 系統時間 systime = str (h) + ":" + str (m) #小時隨便減去多少 add_h = random.randint( 2 , 5 ) #分鐘隨便減去多少 add_m = random.randint( 2 , 7 ) #添加好友的時間 addtime = str (h - add_h) + ":" + str (m - add_m) #標題名稱 # qun_name = "電銷 " + n qun_name = n #電池電量 diannum = str (v) #打開圖片 im1 = Image. open ( "new.png" ) #系統時間 (寬 高) imgAddFont(im1,( 17 , 20 ), 'C:\Windows\Fonts\msyh.ttc' , 38 ,( 50 , 50 , 50 ),systime) #電池電量 imgAddFont(im1,( 1012 , 21 ), 'C:\Windows\Fonts\simhei.ttf' , 29 ,( 50 , 50 , 50 ),diannum) #群姓名 imgAddFont(im1,( 120 , 108 ), 'C:\Windows\Fonts\msyh.ttc' , 49 ,( 50 , 50 , 50 ),qun_name) #添加時間 imgAddFont(im1,( 490 , 260 ), 'C:\Windows\Fonts\msyh.ttc' , 38 ,( 170 , 170 , 170 ),addtime) # #發消息時間 # imgAddFont(im1,(490,260),'C:\Windows\Fonts\msyh.ttc',38,(170,170,170),addtime) # 保存位置 22 370 # img=im1 # 已經添加好完整的文字了,下面添加圖片 打開 縮略 圓角 合并 # 打開頭像原圖檢測是否存在不存在就換個后綴 jpg_path = '.\\img\\' + ( str (z)) if os.path.exists(jpg_path + ".jpg" ): img = Image. open (jpg_path + ".jpg" ) else : img = Image. open (jpg_path + ".png" ) img = circle_corner(img, radii = 20 ) #縮放等比例的尺寸 w, h = img.size img.thumbnail(( 118 , 118 )) # 尺寸等比縮放 # 打開底圖 layer = Image.new( 'RGBA' , im1.size, ( 0 , 0 , 0 , 0 )) layer.paste(img, ( 20 , 370 )) out = Image.composite(layer,im1,layer) # out.save("target.png") save_time = time.strftime( '%Y_%m_%d_%M_%H' ,time.localtime(time.time())) out.save(save_time + str (z) + ".png" ) # out.save("target.png") h = int ( input ( "請輸入手機幾點" )) m = int ( input ( "請輸入現在幾分" )) v = int ( input ( "請輸入現在電量" )) z = int ( input ( "請輸入需要生成多少張圖片" )) for x in range ( 1 ,z + 1 ): n = input ( "請輸入標題昵稱 例如好友" ) copy(h,m,x,n,v) |
總結
以上所述是小編給大家介紹的python實現微信自動回復及批量添加好友功能 ,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對服務器之家網站的支持!
如果你覺得本文對你有幫助,歡迎轉載,煩請注明出處,謝謝!
原文鏈接:https://blog.csdn.net/forever_wen/article/details/81946630