登陆注册
11310

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

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

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

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

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

try:

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

8

fd=f.read()

multipart = MultipartEncoder(

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

12

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

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

md.update(fd)

}

群发文本消息

md5Content = md.hexdigest()

:param url: 群组机器人WebHook

&34;&34;&34;

发送微信群组机器人文件

&34;&34;&34;

json_res = resp.json()

}} 发送文本消息27

SendGroupMsg(textContent,url)

return True

webHookUrl = webHookUrl

群发图片

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

except Exception as e:

7

:return:

&34;&34;&34;

media_id = UploadFile(filepath, url)

filename = os.path.basename(filepath)

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

except Exception as e:

def sendImg(imgPath,webHookUrl):

发送微信群组机器人图片

md = hashlib.md5()

&34;content&34;: textContent,

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

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

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

发送请求

url = webHookUrl

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

}

fd=f.read()

except Exception as e:

sendImg(imagePath,url)

try:

:return:

return False

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

def QYWXSendGroupFile(filepath, url):

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

&34;mentioned_list&34;:mentioned_list,

return True

9

&34;&34;&34;

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

13

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

except Exception as e:

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

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

try:

headers = {

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

发送群文件

&34;&34;&34;

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

:param webHookUrl: 群组机器人WebHook

url = url

11

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

url = webHookUrl

headers = {

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

发送请求

return True

:param webHookUrl: 群组机器人WebHook

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

:param filepath: 文件路径

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

:param filepath: 文件路径

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

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

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

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

&34;&34;&34;

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

textContent = &39;test01&39;

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

imagePath = &39;2022050601.png&39;

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

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

:return:

from requests_toolbelt import MultipartEncoder

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

发送请求

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

return False

try:

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

&34;&34;&34;

:param webHookUrl: 群组机器人WebHook

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

:param imgPath: 图片的本地路径

&34;mentioned_mobile_list&34;: mentioned_mobile_list

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

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

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

:param textContent: 消息内容

&34;&34;&34;

:return: media_id

发送微信群组机器人消息

from urllib import parse

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

return &34;&34;

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

&34;text&34;: {

&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;}

上传要发送的文件

def UploadFile(filepath, webHookUrl):

return False

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

10

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

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