(笔记)微信开发-配置 分享需要的 信息(node.js)

1、获取access_token

var https = require('https');
var iconv = require("iconv-lite");

var appid = ";
var secret = "";
var url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+appid+"&secret="+secret;
https.get(url, function (res) {    
   var datas = []; 
   var size = 0;    
res.on('data', function (data) {
        datas.push(data);
        size += data.length;
    });
res.on("end", function () {
        var buff = Buffer.concat(datas, size);
        var result = iconv.decode(buff, "utf8");//转码//var result = buff.toString();//不需要转编码,直接tostring
        console.log(result);
        access_token = result.access_token; 
   });}).on("error", function (err) {
    console.log(err);    
});

参考:https://nodejs.org/api/https.html#https_https_get_options_callback
转自:http://blog.csdn.net/baby97/article/details/49702379
http://www.cnblogs.com/willian/p/4254963.html?utm_source=tuicool&utm_medium=referral

2、待续

你可能感兴趣的:((笔记)微信开发-配置 分享需要的 信息(node.js))