var curl = require('curl');
var querystring = require('querystring');
var request = require('request');

var webhook = function(msg) {
	var dataString = {
		"msgtype": "text",
	    "text": {
	    	"content": msg
	    }
	};

	var options = {
	    url: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=8b9af774-902e-4fac-afe4-9da5562596e4',
	    method: 'POST',
	    headers: {
		   'Content-Type': 'application/json'
		},
	    body: JSON.stringify(dataString)
	};
	
	request(options, function (error, response, body) {
	    console.log(error, response.errcode, response.errmsg);
	});

    // var exec = require('child_process').exec;
    // var args = ' -d \'{"msgtype": "text", "text": {"content": 123456789} }\' -H \'Content-Type: application/json\' https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=8b9af774-902e-4fac-afe4-9da5562596e4';
    // exec('curl ' + args, function (error, stdout, stderr) {
    //   console.log('stdout: ' + stdout);
    //   console.log('stderr: ' + stderr);
    //   if (error !== null) {
    //     console.log('exec error: ' + error);
    //   }
    // });	

}

发表评论