当前位置:网站首页>树莓派通过API向企业微信推送图文
树莓派通过API向企业微信推送图文
2022-08-04 17:18:00 【ttyt1217】
参考文献:
【实现】树莓派开机自动向微信发消息报告ip地址(无第三方代理)
在 企业微信 官网 注册,不一定要是已注册的企业,个人筹备中的公司也能注册,只是会对外名字后显示 未验证 字样,个人使用的话不必在意。
注册好之后进入企业微信网页版,在“应用管理>应用>自建”一栏中点击“创建应用”,根据提示创建一个应用 H-GetMsg即可。
记住几个关键信息
以下两个在刚才创建的应用列表里找到:
1. 应用ID(AgentId)
2. 秘钥(corpSecret)
在“我的企业>企业信息”最下方找到“企业ID”
3.企业ID(corpID)在树莓派上,创建sh文件:
----发送文字
/home/pi/myboot/sendmsg2wx.sh#!/bin/bash #usage: sh sendmsg2wx.sh "msgstr" AgentId= corpSecret= corpId= temp=`curl https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$corpId\&corpsecret=$corpSecret` if [ -n `echo $temp|awk -F ':"' '{print $3}'` ];then access_token=`echo $temp|awk -F ':"' '{print $3}'|awk -F '","' '{print $1}'` fi msgstr=$1 PostURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$access_token" curl -H "Content-type: application/json" -X POST -d '{"touser":"@all","msgtype":"text","agentid":"'"$AgentId"'","text":{ "content":"'"$msgstr"'"},"safe":0}' $PostURL使用方式:
sh sendmsg2wx.sh "msgstr"
主要逻辑:- 调用 获取凭证API,使用 corpId 和 corpSecret 获取应用调用api的凭证 access_token。
- 调用 发送应用消息API,将msgstr放在请求结构体中 发送到 终端,msgstr包含空格等字符的话需要用双引号括起来。
(更多API可参见 企业微信API官网文档)
- 在企业微信 手机端 就能接收到H-GetMsg的消息了。
*更新:----发送图片/文件
/home/pi/myboot/sendpic2wx.sh
#!/bin/bash
#usage: sh sendpic2wx.sh picfile
AgentId=
corpSecret=
corpId=
temp=`curl https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$corpId\&corpsecret=$corpSecret`
if [ -n `echo $temp|awk -F ':"' '{print $3}'` ];then
access_token=`echo $temp|awk -F ':"' '{print $3}'|awk -F '","' '{print $1}'`
fi
filename=$1
PostUploadURL="https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token=$access_token&type=file"
resupload=`curl --request POST $PostUploadURL \ --header 'Content-Type: multipart/form-data' \ --form 'name="mypictmp"' \ --form '[email protected]'$1`
if [ -n `echo $resupload|awk -F ':"' '{print $4}'` ];then
media_id=`echo $resupload|awk -F ':"' '{print $4}'|awk -F '","' '{print $1}'`
fi
PostURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$access_token"
curl -H "Content-type: application/json" -X POST -d '{"touser":"@all","msgtype":"image","agentid":"'"$AgentId"'","image":{
"media_id":"'"$media_id"'"},"safe":0}' $PostURL
边栏推荐
猜你喜欢

codeforces每日5题(均1600)-第二十八天

shell脚本详解-------循环语句wuile循环和until循环

php如何查询字符串以什么开头

一张图片怎么旋转90度。利用ps

win11如何退出安全模式

Digital-intelligent supply chain management system for chemical manufacturing industry: build a smart supply system and empower enterprises to improve production efficiency

localhost,127.0.0.1,本机IP

pyhon爬虫之爬取图片(亲测可用)

Learning and Exploration-Introducing Baidu Statistics to the Website

NLP未来,路在何方?从学术前沿和业界热点谈起
随机推荐
机器学习入门到大神专栏总览
太一集团宣布全资收购火币旗下社交产品火信
win11如何退出安全模式
小满nestjs(第一章 介绍nestjs)
44. 通配符匹配 ●●● & HJ71 字符串通配符 ●●
两个对象相同数据赋值
R语言使用cov函数计算矩阵或者dataframe数据变量之间的协方差、cor函数计算相关性、cor函数通过method参数指定相关性、相关性计算方法Pearson,Spearman, Kendall
Unity Apple登录接入
抖音最重要的接口——item_search_video-根据关键词获取视频列表
R语言使用ggpubr包的ggsummarystats函数可视化柱状图(通过ggfunc参数设置)、在可视化图像的下方添加描述性统计结果表格、palette参数配置柱状图及统计数据的颜色
正则过滤字符串中 script 标签
消灭异步回调,还得是async-await
dotnet core 隐藏控制台
HCIP WPN 实验
IDEA以多端口启动同一个服务项目
集群监控——Zabbix使用
Boost库学习笔记(一)安装与配置
化学制品制造业数智化供应链管理系统:打造智慧供应体系,赋能企业产效提升
安装win11提示开启安全模式如何解决
字节二面被问到mysql事务与锁问题,我蚌埠住了