登陆注册
11310

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

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

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

:param imgPath: 图片的本地路径

:return: media_id

SendGroupMsg(textContent,url)

9

fd=f.read()

:param webHookUrl: 群组机器人WebHook

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

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

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

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

url = webHookUrl

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

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

:return:

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

except Exception as e:

:param webHookUrl: 群组机器人WebHook

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

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

发送微信群组机器人文件

发送请求

return True

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

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

}

发送请求

headers = {

webHookUrl = webHookUrl

return False

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

multipart = MultipartEncoder(

:param webHookUrl: 群组机器人WebHook

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

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

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

try:

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

:param filepath: 文件路径

:return:

textContent = &39;test01&39;

media_id = UploadFile(filepath, url)

:param textContent: 消息内容

发送请求

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

return True

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

fd=f.read()

发送微信群组机器人图片

上传要发送的文件

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

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

try:

imagePath = &39;2022050601.png&39;

try:

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

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

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

&34;mentioned_list&34;:mentioned_list,

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

7

&34;&34;&34;

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

except Exception as e:

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

:return:

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

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

def UploadFile(filepath, webHookUrl):

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

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

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

&34;&34;&34;

:param url: 群组机器人WebHook

except Exception as e:

return &34;&34;

&34;&34;&34;

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

md = hashlib.md5()

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

发送微信群组机器人消息

md5Content = md.hexdigest()

&34;&34;&34;

def QYWXSendGroupFile(filepath, url):

headers = {

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

&34;text&34;: {

return False

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

:param filepath: 文件路径

&34;mentioned_mobile_list&34;: mentioned_mobile_list

11

13

except Exception as e:

10

群发图片

12

&34;&34;&34;

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

def sendImg(imgPath,webHookUrl):

&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(f&34;企业微信机器人上传文件失败,file: {filepath}, 详情:{e}&34;)

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

url = webHookUrl

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

filename = os.path.basename(filepath)

8

return True

return False

from requests_toolbelt import MultipartEncoder

url = url

发送群文件

}

群发文本消息

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

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

json_res = resp.json()

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

&34;&34;&34;

}} 发送文本消息27

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

md.update(fd)

&34;&34;&34;

sendImg(imagePath,url)

&34;content&34;: textContent,

from urllib import parse

&34;&34;&34;

try:

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