Tasker实现收到短信自动转发到微信

短信自动转发到微信


短信转发到微信上是使用的企业微信的一项功能:企业微信收到的信息可以同步到微信上,而企业微信有着丰富的可开发性。


操作步骤


  • 注册企业微信

  1. 注册

  2. 注册完成后打开复制下网页底部的企业信息中的企业ID备用。

  3. 点击看到一个二维码,使用微信扫码关注,这样就可以使企业微信中收到的信息同步到微信上。

  • 创建一个应用

  1. 点击这里创建上传一个应用logo和自定义应用名字,其他默认。
  2. 创建后打开可以看到在 “应用”中的”自建”里有个应用。点进去打开记录下 AgentId和Secret备用。
  • 创建Tasker配置文件

下面是创建部分图示的说明

点击加号–新建配置打勾–选择触发类型–事件–选择触发条件类型–电话–选择触发内容–收到短信–点击返回–新建任务–自定义任务名称打勾–点击加号–新建操作–选择代码–选择JavaScriptlet–在此位置填写代码(随便填个先)–点击箭头–返回–返回–打勾

  • 代码
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//将下面的三个变量值修改为自己的
var ID = "wwc367de248887ebad";
var SECRET = "KNgBbhHiTo66VSVzqLv0vYCadXE0ndrn5o41xxxB2o4";
var AGENTID = "1000002";

//定义post方法
function posthttp(url, data) {
var xhr = new XMLHttpRequest();
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
flash(this.responseText); //显示返回消息,可删除本行
}
});
xhr.open("POST", url, false);
xhr.send(data);
return xhr.responseText;
}

//定义get方法
function gethttp(url) {
var xhr = new XMLHttpRequest();
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
flash(this.responseText); //显示返回消息,可删除本行
}
});
xhr.open("GET", url, false);
xhr.send();
return xhr.responseText;
}

//获取token
var gettoken = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=" + ID + "&corpsecret=" + SECRET;
var ACCESS_TOKEN = JSON.parse(gethttp(gettoken)).access_token;

//发送消息(文本)
var SMSRF = global('SMSRF');
var SMSRB = global('SMSRB');
var SMSRT = global('SMSRT');
var SMSRD = global('SMSRD');
var CONTENT = "发件人: " + SMSRF + "\n时间: " + SMSRT + ", 日期: " + SMSRD + "\n短信内容: " + SMSRB;
var message = JSON.stringify({
"touser": "@all",
"msgtype": "text",
"agentid": AGENTID,
"text": {
"content": CONTENT
},
"safe": 0
});
var send = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + ACCESS_TOKEN;
posthttp(send, message);

Tasker实现收到短信自动转发到微信
https://couurh.github.io/posts/7f0d2c71.html
Author
Couurh
Posted on
July 18, 2020
Licensed under