var WechatAPI = require('wechat-api');
var api = new WechatAPI(wechatappid, wechatsecret);

var storedCookies = require('./cookies.json');

var dateId = new Date(new Date().toUTCString())
var tempature = function () {
    min = Math.ceil(35);
    max = Math.floor(37);
    return Math.floor(Math.random() * (max - min + 1)) + min;
}()



const Nightmare = require('nightmare')

const { doesNotThrow } = require('assert');
var currentUrl = '';
var vo = require('vo');

function* run() {
    const nightmare = Nightmare({
        show: true,
        maxHeight: 16384,
        maxWidth: 16384,
        width: 600,
        height: 1200,
    })
    if (!storedCookies.length) {
        storedCookies = {}
    }
    yield nightmare.goto('about:blank');


    var url = yield nightmare

        .goto('http://wdt.wbu.edu.cn:9999/wxfwdt/html/wxfwd')
        .cookies.set(
            storedCookies
        )
        .wait(500)
        .url()
        .then(
            url => {
                return url
            })
    if (url.split('/')[2] != "wdt.wbu.edu.cn:9999") {
        console.log(url.split('/'))
        yield nightmare
            .type('#username', userme)
            .type('#password', pass)
            .check('#rememberMe')
            .click('#login_submit')
            .cookies.get()
            .then((cookies) => {
                console.log(cookies)
                require('fs').writeFileSync(
                    'cookies.json',
                    JSON.stringify(cookies, null, 4)
                );
            })
    }
    var dimensions = yield nightmare
        .wait(5000)
        .evaluate(() => {
            var allButtons = document.getElementsByClassName('service-text');
            for (var i = 0; i < allButtons.length; i++) {
                if (allButtons[i].innerText == '健康上报') allButtons[i].id = 'loginbutton';
            }
        })
        .click('div[id=loginbutton]')
        .type('input[name=tw]', tempature)
        .click('#weuiAgree')
        .click('#qrtj')
        .evaluate(function () {
            var body = document.querySelector('body');
            return {
                width: body.scrollWidth,
                height: body.scrollHeight
            }
        })

    var dimensions = yield nightmare.evaluate(function () {
        var body = document.querySelector('html');
        return {
            width: body.scrollWidth,
            height: body.scrollHeight
        }
    })
    console.log(dimensions.width)
    nightmare.viewport(dimensions.width, dimensions.height)
        .wait(1000)
        .screenshot(dateId + '.png');

}

vo(run)(function () {
    console.log('done');
    let data = {
        "temp": {
            "value": tempature,
            "color": "#173177"
        }
    }
    api.sendTemplate(openId, templateId, prefixHost+dateId+'.png',
        data, function (err, data) {
            if (err) {
                console.log(err);
            }
        }
    );
});

标签: none

发表新评论