当前位置:网站首页>树莓派通过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
边栏推荐
- 水能自发变成“消毒水”,83岁斯坦福教授:揭示冬天容易得流感的部分原因...
- 全球电子产品需求萎靡:三星越南工厂大幅压缩产能,减少工人工作日
- How to convert an int attribute into a string in the json format returned by the Go language gin framework?
- Boost library study notes (1) Installation and configuration
- 容器化 | 在 NFS 备份恢复 RadonDB MySQL 集群数据
- Unity Apple登录接入
- 图扑软件与华为云共同构建新型智慧工厂
- WEB 渗透之XXE&XML
- The use of QCompleter for Qt auto-completion
- JVM内存和垃圾回收-08.方法区
猜你喜欢
Understand Chisel language. 32. Chisel advanced hardware generator (1) - parameterization in Chisel
麒麟信安石勇博士荣获openEuler社区年度开源贡献之星
集群监控——Zabbix使用
软件测试高频面试题真实分享/网上银行转账是怎么测的,设计一下测试用例。
谷粒商城笔记
yarn详细入门教程
How to convert an int attribute into a string in the json format returned by the Go language gin framework?
租房小程序登顶码云热门
yarn detailed introductory tutorial
【小程序】实现发动态功能
随机推荐
】 【 LeetCode daily one problem - 540. The order of a single element of the array
【LeetCode每日一题】——374.猜数字大小
乐享购(分享购)的模式:优势、亮点、收益
arm交叉编译
What does the product system of a digital financial enterprise look like?
WEB 渗透之逻辑漏洞
华为云数据治理生产线DataArts,让“数据‘慧’说话”
JVM内存和垃圾回收-08.方法区
HCIP WPN 实验
Fork/Join框架
谷歌开发者社区推荐:《Jetpack Compose 从入门到实战》新书上架,带你踏上 Compose 开发之旅~
MySQL学习笔记-4.数据更新时的性能问题
Nacos集群搭建
GraphQL 入门与实践
SRM Supplier Collaborative Management System Function Introduction
在VMD上可视化hdf5格式的分子轨迹文件
机器学习(十八):随机搜索和XGBoost
Compose 类型稳定性注解:@Stable & @Immutable
并发编程原理学习-reentrantlock源码分析
抖音最重要的接口——item_search_video-根据关键词获取视频列表