Google Apps Script + pushplus:脚本事件推到微信
效果:表格变更、定时触发或自定义菜单执行后,用
UrlFetchApp把结果推到微信。
前置条件
- 一个 pushplus token(官网扫码获取)
- 能编辑对应 Google 表格 / 文档的 Apps Script
不要把 token 写进别人能打开的脚本副本;可用「脚本属性」保存。
配置步骤
- 打开表格 → 扩展程序 → Apps Script。
- 用脚本属性存放 token:项目设置 → 脚本属性,键名如
PUSHPLUS_TOKEN。 - 发送函数:
function notify_pushplus(title, content) {
const token = PropertiesService.getScriptProperties().getProperty("PUSHPLUS_TOKEN");
const body = {
token: token,
title: title,
content: content,
template: "markdown"
};
const res = UrlFetchApp.fetch("https://www.pushplus.plus/send", {
method: "post",
contentType: "application/json",
payload: JSON.stringify(body),
muteHttpExceptions: true
});
const json = JSON.parse(res.getContentText());
if (json.code !== 200) {
throw new Error(res.getContentText());
}
}
- 在
onEdit、时间驱动触发器或自定义函数里调用notify_pushplus("标题", "正文")。content不能为空。
表单提交场景见 Google Forms。完整参数见 消息接口文档。
验证
先在脚本编辑器直接运行:
function test_pushplus() {
notify_pushplus("Apps Script 配置测试", "token 可用");
}
或本机:
curl -X POST "https://www.pushplus.plus/send" \
-H "Content-Type: application/json" \
-d '{"token":"你的token","title":"Apps Script 配置测试","content":"token 可用","template":"markdown"}'
首次运行需授权「连接外部服务」。返回 code 为 200 即通过。
常见问题
提示无权访问外部地址? 重新运行并同意授权;工作区账号可能被管理员关掉了 UrlFetch。
触发太勤? 给 onEdit 加条件(只盯某列),或改用每小时触发器。见 接口限制。
收不到消息见 排查说明。