启用脚本进行转发

使用说明

1.javascript脚本运行环境为nodejs,依赖的网络请求工具为request(查看request文档)和axios(查看axios文档);
2.python脚本运行环境为python3,依赖的网络请求工具为requests(查看requests文档);
3.运行脚本的功能目前处于测试期,因此并不能保证稳定性;
4.该功能是为了方便用户自定义转发场景,请勿执行耗时操作或者用于恶意攻击,否则将作封号处理。

使用方法

脚本功能可以灵活实现所有方式的网络转发,比如转发到企业微信,实现自定义消息过滤等。

支持的内置变量

参考【网络转发-支持的内置变量】

GET请求示例

javascript

1
2
3
4
5
6
let url = 'http://localhost/test-get';
//如果url中包含中文等特殊字符,请使用encodeURI函数进行转码
url = encodeURI(url);
request(url, (error, response, body) => {
//你的业务代码
});

python

1
2
3
4
url = "http://localhost/test-get"
params = {"title":"{{title}}","content":"{{content}}"}
response = requests.get(url, params=params)
//你的业务代码

POST请求示例

javascript

1
2
3
4
5
6
7
const options = {
form: {"title":"{{title}}","content":"{{content}}"},
url: "http://localhost/test-post"
};
request.post(options, (error, response, body) => {
//你的业务代码
});

python

1
2
3
4
url = "http://localhost/test-post"
data = {"title":"{{title}}","content":"{{content}}"}
response = requests.post(url, data=data)
//你的业务代码

企业微信javascript示例

请修改脚本前三行变量【如何获取企业微信配置信息?】

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//你的企业ID
const corpid = "wwfefea362ad89f874";
//创建应用后生成的Secret
const corpsecret = "WLviSlFLxbZA_X4qHhPuaxuyoWSDwYahyamEd-UhK6s";
//创建应用后生成的AgentId
const agentid = "1000002";
//要发送的内容
const content = "{{title}}\n{{content}}";

let url = `https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=${corpid}&corpsecret=${corpsecret}`;
//如果url中包含中文等特殊字符,请使用encodeURI函数进行转码
url = encodeURI(url);
request(url, (error, response, body) => {
//你的业务代码
const { access_token } = JSON.parse(body);
const options = {
url: `https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=${access_token}`,
form: JSON.stringify({
touser: "@all",
msgtype: "text",
agentid,
text: {
content
},
safe: 0
})
};
request.post(options, (error, response, body) => {
//你的业务代码
});
});

钉钉机器人python示例

1
2
3
4
5
6
url = 'https://oapi.dingtalk.com/robot/send?access_token=2a9c844e51472d58d8dcc6ec930ed6fd443af7465d1bcb349142ff6d3b4597'
body = {"markdown": {"title": "{{content}}","text": "### {{content}}\n> ##### {{title}}\n> ##### {{timestamp}}"},"msgtype": "markdown"}
headers={'Content-Type':'application/json'}
data = json.dumps(data)
requests.post(url=url, headers=headers, data=data)