tasker监控手短信,收到短信后,将其发送给微信
1.任务
效果:
直接在task的配置文件tab中导入即可
收到短信转发至微信.prf.xml
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
| <TaskerData sr="" dvi="1" tv="5.9.1"> <Profile sr="prof13" ve="2"> <cdate>1577800144113</cdate> <clp>true</clp> <edate>1645886091363</edate> <flags>8</flags> <id>13</id> <limit>true</limit> <mid0>14</mid0> <nme>收到短信转发至微信</nme> <Event sr="con0" ve="2"> <code>7</code> <pri>0</pri> <Int sr="arg0" val="2"/> <Str sr="arg1" ve="3">!13032550691</Str> <Str sr="arg2" ve="3"/> <Str sr="arg3" ve="3"/> </Event> </Profile> <Task sr="task14"> <cdate>1577800167003</cdate> <edate>1645924448052</edate> <id>14</id> <nme>短信转发至微信</nme> <pri>100</pri> <Action sr="act0" ve="7"> <code>131</code> <Str sr="arg0" ve="3">Tasker/JavaScript/SMS2WeChat.js</Str> <Str sr="arg1" ve="3"/> <Int sr="arg2" val="1"/> <Int sr="arg3" val="45"/> </Action> </Task> </TaskerData>
|
2.执行的脚本
将脚本放到Tasker/JavaScript/目录中
SMS2WeChat.js
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 53 54
| var ID = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; var SECRET = "xxxxxxxxxxxxxxxxxxxxxxxxx"; var AGENTID = "xxxxxxxxxxxxxxxxx";
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; }
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; }
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 SMSRN = global('SMSRN'); var SMSRB = global('SMSRB'); var SMSRT = global('SMSRT'); var SMSRD = global('SMSRD'); var CONTENT = "发件人: " + SMSRN + "(" + SMSRF + ")" +"\n时间: " + SMSRT + ", 日期: " + SMSRD + "\n短信内容: \n" + SMSRB; var message = JSON.stringify({ "touser": "xxx", "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);
|