当前位置:网站首页>树莓派通过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
边栏推荐
- 并发编程原理学习-reentrantlock源码分析
- 要有遥不可及的梦想,也要有脚踏实地的本事
- R语言ggpubr包的ggline函数可视化折线图、设置add参数为mean_se和dotplot可视化不同水平均值的折线图并为折线图添加误差线(se标准误差)和点阵图、设置折线和数据点边框颜色
- Understand Chisel language. 32. Chisel advanced hardware generator (1) - parameterization in Chisel
- (1), the sequential storage structure of linear table chain storage structure
- dotnet core 隐藏控制台
- 正则过滤字符串中 script 标签
- 机器学习(十三):支持向量机(SVM)
- WEB 渗透之逻辑漏洞
- JVM内存和垃圾回收-08.方法区
猜你喜欢
随机推荐
R语言使用yardstick包的gain_curve函数评估多分类(Multiclass)模型的性能、查看模型在多分类每个分类上的增益(gain)曲线(gain curve)
机器学习(十七):网格搜索(Grid Search)和SVM
拼多多详情API接口深度解读
浅谈运用低代码技术如何实现物流企业的降本增效
最小区间覆盖
R语言dplyr包group_by函数和summarise_at函数计算dataframe计算不同分组的计数个数和均值、使用%>%符号将多个函数串起来
水能自发变成“消毒水”,83岁斯坦福教授:揭示冬天容易得流感的部分原因...
MySQL学习笔记-4.数据更新时的性能问题
安装失败怎么办
init和destory方法
What does the product system of a digital financial enterprise look like?
JVM内存和垃圾回收-08.方法区
正则过滤字符串中 script 标签
WPF 修改 ItemContainerStyle 鼠标移动到未选中项效果和选中项背景
Selenium Webdriver驱动自管理
机器学习(十四):K均值聚类(kmeans)
codeforces每日5题(均1600)-第二十八天
海报 | 夏季高温,危化品安全风险的注意事项必须get!
LeetCode Question of the Day - 1403. Minimum Subsequence in Non-Increasing Order
SAP ABAP SteammPunk 蒸汽朋克的最新进展 - 嵌入式蒸汽朋克









