tasker短信接受到快递消息转发到微信

Fenglilinglegeluan 于 2020-12-31 发布 浏览量
  1. 条件选择收到短信

  2. 任务选择代码 javascript

    修改一下id、secret、agentid为企业微信的应用id、secret和agentid

     var ID = "";
     var SECRET = "";
     var AGENTID = 1000002;
     //获取消息
     var smsrf = global('SMSRF');
     var smsrb = global('SMSRB');
     var mmsrs = global('MMSRS');
     var smsrt = global('SMSRT').replace(/\./, ":");
     //flash(smsrf)
     var pnum = global('PNUM').substring(3);
     var smsrd = global('SMSRD');
     //定义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;
     }
     //判断是短信,彩信还是无法获取短信内容
     smsrb = (smsrb == "%SMSRB") ? (mmsrs == "%MMSRS") ? "无法获取短信内容" : mmsrs : smsrb;
     //
     if (smsrb == "无法获取内容") {
    flashLong(smsrb)
     }
     else 
     {
    //获取token
    var tokenUrl = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=" + ID + "&corpsecret=" + SECRET;
    var access_tokenJson = JSON.parse(getHttp(tokenUrl));
    if (access_tokenJson.errcode == 0)
    {
        var access_token = access_tokenJson.access_token;
        //发送消息(文本)
        var content = "发件人: " + smsrf + "\n收件人: " + pnum + "\n时间: " + smsrt + ",  日期: " + smsrd + "\n短信内容: " + smsrb;
        var message = JSON.stringify(
        {
            "touser" : "@all", //@all代表发送给全体成员,也可指定某几个人,比如"a|b|c"
            //"toparty" : "1|2",//部门id
            //"totag" : "1|2",//标签id,文档说明:https://work.weixin.qq.com/api/doc#90000/90135/90236
            "msgtype" : "text", "agentid" : AGENTID, "text" : {
                "content" : content 
            },
            "safe" : 0
        });
        var msgUrl = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + access_token;
     postHttp(msgUrl, message) 
    }
    else if (access_tokenJson.errcode == 40013) {
        flashLong("ID 错误,请检查是否修改正确(请注意不要有空格)");
    }
    else if (access_tokenJson.errcode == 40001) {
        flashLong("SECRET 错误,请检查是否修改正确(请注意不要有空格)");
    }
     };