请教关于微信公众号的模拟登录
发布于 10 年前 作者 carly1987 7076 次浏览 最后一次编辑是 8 年前 来自 问答

我遇到的情况是,登录成功了,但是页面转向到别的页面就成了登录超时的页面,发送的时候,headers传了Cookie,结果是

{ [Error: socket hang up] code: 'ECONNRESET' }

。代码如下:

  1. 出现登录超时的代码:
https.get({
		hostname:"mp.weixin.qq.com",
		path: "/advanced/advanced?action=dev&t=advanced/dev&lang=zh_CN&token="+token
	},function(res){
		res.on('data', function(d) {
			process.stdout.write(d);
		});
	});
  1. 出现error的代码:
var headers = {
			"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0", 
			"Host": "mp.weixin.qq.com",
			"Connection": "	keep-alive",
			"Cache-Control":"	max-age=0",
			"Accept-Language": "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3",
			"Accept-Encoding": "gzip, deflate", 
			"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 
			"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"};
var options = { 
		hostname:"mp.weixin.qq.com", 
		path: "/advanced/advanced?action=dev&t=advanced/dev&lang=zh_CN&token="+token,
		method: "GET",
		headers: headers
	};
	options.headers["Referer"] = 'https://mp.weixin.qq.com/cgi-bin/home?t=home/index&lang=zh_CN&token='+token;
	options.headers["Cookie"] = exports.cookie;
	var html = '';
	var req=https.request(options, function (res) {
		res.on('data', function (d) {
			process.stdout.write(d);
			if(res.statusCode == 200){
				//exports.beDev(token);
			}
		})
	}).on('error', function (e) { console.error(e); }); 
	req.end();
  1. 出现乱码的代码:
	https.get({
		hostname:"mp.weixin.qq.com",
		path: "/advanced/advanced?action=dev&t=advanced/dev&lang=zh_CN&token="+token,
		headers: {
			"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0", 
			"Host": "mp.weixin.qq.com",
			"Connection": "	keep-alive",
			"Cache-Control":"	max-age=0",
			"Accept-Language": "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3",
			"Accept-Encoding": "gzip, deflate", 
			"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", 
			"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
			'Referer': 'https://mp.weixin.qq.com/cgi-bin/home?t=home/index&lang=zh_CN&token='+token,
			'Cookie': exports.cookie
		}
	},function(res){
		res.on('data', function(d) {
			process.stdout.write(d);
		});
	});

期待大神解答!!

3 回复

你的主机是不是国外的?以前国外的主机我也遇到过这种情况。之后换成阿里云的就可以了

@ty4z2008 我是在本地,还没放任何服务器呢

@carly1987 先去微信后台填写服务器配置信息( 授权连接+appkey)看看能不能通。如果不能就是路由的问题

回到顶部