登陆注册
11310

微信怎么群发消息给所有人(企业微信怎么群发给所有人)

大财经2023-03-23 14:05:330

filename = os.path.basename(filepath)

def QYWXSendGroupFile(filepath, url):

群发图片

webHookKey = params[&39;key&39;][0]

md5Content = md.hexdigest()

发送请求

headers = {

if json_res.get(&39;media_id&39;):

&39;media&39;: (filename, open(filepath, &39;rb&39;), &39;application/octet-stream&39;)},

&34;&34;&34;

with open(imgPath,&34;rb&34;) as f:

9

md.update(fd)

发送微信群组机器人文件

&34;mentioned_list&34;:mentioned_list,

&34;&34;&34;

print(&34;企业微信机器人发送文件失败,详细信息:&34; + str(e))

}} 发送文本消息27

msg = {&34;msgtype&34;: &34;text&34;,

:param webHookUrl: 群组机器人WebHook

headers[&39;Content-Type&39;] = multipart.content_type

发送文件需要先上传文件获取media_id

&34;file&34;: {&34;media_id&34;: media_id}}

from urllib import parse

return json_res.get(&39;media_id&39;)

13

url = url

:return: media_id

def SendGroupMsg(textContent, webHookUrl, mentioned_list=[],mentioned_mobile_list=[]):

print(&34;Requset Failed:&34;, e)

headers = {

except Exception as e:

requests.post(url, headers=headers, json=msg)

result =requests.post(url, headers=headers, json=msg)

}

if __name__==&39;__main__&39;:

url = &39;http://qyapi.weixin.qq.com/origin/cgi-bin/webhook/send?key=xxxxxxxxxxxx&39;

return True

from requests_toolbelt import MultipartEncoder

:param url: 群组机器人WebHook

multipart = MultipartEncoder(

upload_url = f&39;http://qyapi.weixin.qq.com/origin/cgi-bin/webhook/upload_media?key={webHookKey}&type=file&39;

print(f&34;企业微信机器人上传文件失败,file: {filepath}, 详情:{e}&34;)

发送请求

headers = {&34;Accept&34;: &34;application/json, text/plain, */*&34;, &34;Accept-Encoding&34;: &34;gzip, deflate&34;,

:param filepath: 文件路径

发送群文件

return &34;&34;

json_res = resp.json()

&34;&34;&34;

&34;text&34;: {

webHookUrl = webHookUrl

&34;&34;&34;

fields={&39;filename&39;: filename, &39;filelength&39;: &39;&39;, &39;name&39;: &39;media&39;,

result = requests.post(url, headers=headers, json=msg)

发送请求

url = webHookUrl

&34;&34;&34;

&34;mentioned_mobile_list&34;: mentioned_mobile_list

10

headers = {&34;content-type&34;: &34;application/json&34;}

return False

url为群组机器人WebHook,配置项

&34;User-Agent&34;: &34;Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.100 Safari/537.36&34;}

print(&34;企业微信机器人上传文件失败,详细信息:&34; + str(e))

:param webHookUrl: 群组机器人WebHook

发送微信群组机器人图片

params = parse.parse_qs(parse.urlparse(webHookUrl).query)

&34;content-type&34;: &34;application/json&34;

图片支持jpg,png两种格式,大小不能超过2Mb

except Exception as e:

url为群组机器人WebHook,配置项

boundary=&39;-------------------------acebdf13572468&39;)

&34;&34;&34;

&34;&34;&34;

url = webHookUrl

7

return False

imagePath = &39;2022050601.png&39;

def UploadFile(filepath, webHookUrl):

except Exception as e:

print(&34;Requset Failed:&34;, e)

:param mentioned_mobile_list: 手机号列表,提醒手机号对应的群成员(@某个成员),@all表示提醒所有人

11

:param filepath: 文件路径

textContent = &39;test01&39;

return True

media_id = UploadFile(filepath, url)

&34;content&34;: textContent,

try:

try:

print(f&34;企业微信机器人上传文件成功,file:{filepath}&34;)

md = hashlib.md5()

import os, re, time, datetime, base64, requests, json, hashlib

with open(imgPath,&34;rb&34;) as f:

SendGroupMsg(textContent,url)

:param mentioned_list: userid的列表,提醒群中的指定成员(@某个成员),@all表示提醒所有人

8

url为群组机器人WebHook,配置项

:param imgPath: 图片的本地路径

url为群组机器人WebHook,配置项

return False

except Exception as e:

&34;content-type&34;: &34;application/json&34;

resp = requests.post(upload_url, headers=headers, data=multipart)

:return:

上传要发送的文件

:param textContent: 消息内容

fd=f.read()

发送微信群组机器人消息

def sendImg(imgPath,webHookUrl):

try:

企业微信机器人上传文件,发送文件前需要先上传--要求文件大小在5B~20M之间

:param webHookUrl: 群组机器人WebHook

fd=f.read()

12

:return:

result = requests.post(url, headers=headers, json=msg)

sendImg(imagePath,url)

base64Content=str(base64.b64encode(fd),&34;utf-8&34;)

msg = {&34;msgtype&34;: &34;file&34;,

:return:

群发文本消息

msg = {&34;msgtype&34;: &34;image&34;,&34;image&34;: {&34;base64&34;: base64Content,&34;md5&34;: md5Content}}

}

try:

&34;&34;&34;

return True

0000
评论列表
共(0)条
热点
关注
推荐