const axios = require('axios').default;
const PCWebSocket = require('./src/protocol/lib/PCWebSocket')
var random_useragent = require('random-useragent');
const http = require("http");  // 引入内置http模块
const https = require('https');
const url  = require("url");
var HttpsProxyAgent = require('https-proxy-agent');
 
// console.info('axios',axios);
// 取消关注
function follow_del(){
	const params = new URLSearchParams();
	params.append('tuid',"94140406");
	params.append('act',"p");
	params.append('format',"json");
	params.append('module',"iqg9rubn");
	params.append('uuid',"B5158685914737977");
	params.append('page',"room");
	params.append('pageid',"94140406");
	params.append('from_module',"");
	params.append('from_pageid',"");
	params.append('from_recid',"");
	params.append('watchid',1586862494830);
	params.append('platform',"web");
	params.append('reft',"0");
	params.append('ver',"1.5");

	var cookie = "shrek_uuid=B5158685914737977; shrek_reft=0%7C158685914759934; firVist=1586859148; _LiveGuestUser=1025687532%7C%E6%B8%B8%E5%AE%A2iatg1d; smidV2=202004010042087fd1471e7abc771aa523aec4c52afa1800a4339b735b64a60; ticket_v=RnnIYe7aXb4F-GyqdKCct-ATtuteoVwjpMux8Mb1aHZtf7kT7nIkwJ9RX94dNnoYKqyrTZkWgtzQqcXerG2I5t32x0LN3ug7tvO3ELKSq2f88AifTKWs-F_bMXovej0s10004; _vinfo=90211658%7C%7Cwellsabc; _rinfo=https%3A%2F%2Fvi3.xiu123.cn%2Flive%2F2016%2F05%2F26%2F15%2F1013v1464246499743547801.jpg; currentlyin=90211658_116.1.40.194; _uuid=e9a1e2f7fc546f62; roomCookie=e30%3D; logtm=1586861130; _coin6=90211658%3A0%3A0%3A0%3A%E5%B0%8F%E5%B0%8F%E4%BA%BA%E7%89%A9s%3A240349376%3A0%3A0%3A0%3A3%3A1000%3A1000%3A0%3A1000%3A1585725543%3A0%3A0%3A0%3A1%3A0%3A7%3A";

	var proxy = {
		host:'127.0.0.1',
		port:'8888'
	}
	axios.get('https://v.6.cn/message/follow_del.php',{params:params,proxy:proxy,headers:{cookie:cookie}}).then((result)=>{
		console.info('result',result);
	})
}

// 进入房间
function join_room(){
	let wc = new PCWebSocket();
	var url = 'wss://218-6-175-200.xiu123.cn:6520';
	// 小小人物
	var agentId = '90211658';
	var encpass = 'RnnIYe7aXb4F-GyqdKCct-ATtuteoVwjpMux8Mb1aHZtf7kT7nIkwJ9RX94dNnoYKqyrTZkWgtzQqcXerG2I5t32x0LN3ug7tvO3ELKSq2f88AifTKWs-F_bMXovej0s10004';
	// 房间id https://v.6.cn/6000
	var roomId = '94140406';
	var proxyCallBackRoom = function(eventName,msg){
		console.info('proxyCallBackRoom',eventName,msg);
		if(eventName == 'result'){
			switch(msg){
				case 'login.success':
					wc.sendMessage('{"t":"priv_info", "content":{"encpass":"","reft":"0"}}');
				break;
				case 'send.success':
					// 请求事件
				break;
			}
		}
	}
	wc.login(url, agentId, encpass, roomId, proxyCallBackRoom);
}
function new_join_room(){
const room = require('./src/protocol/room')

	// join_room();
var agentId = '90211658';
var encpass = '9iJcjKoRYGdatD4gDQHamuATtuteoVwjpMux8Mb1aHZAyLy4BtzvJIwuUtqaWqShSGn2kjcrgqi8rg8ED6vUvdjE10xmqEVAyV8Iz-v3ijsFNjHqsGySnntx6CM5-F0E10004';
var r = new room({
	agentId:agentId,
	encpass:encpass,
	roomId:'666',
	headers:{
		'user-agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36',
		'cookie':"firVist=1586911840; _LiveGuestUser=1025844511%7C%E6%B8%B8%E5%AE%A2c9f2zo; shrek_uuid=B5158685914737977; _uuid=d2f3337bf3337d06; roomCookie=e30%3D; smidV2=202004010042087fd1471e7abc771aa523aec4c52afa1800a4339b735b64a60; currentlyin=90211658_116.1.40.194; shrek_reft=0%7C158700423451052; ticket_v=9iJcjKoRYGdatD4gDQHamuATtuteoVwjpMux8Mb1aHZAyLy4BtzvJIwuUtqaWqShSGn2kjcrgqi8rg8ED6vUvdjE10xmqEVAyV8Iz-v3ijsFNjHqsGySnntx6CM5-F0E10004; _vinfo=90211658%7C%7Cwellsabc; _rinfo=https%3A%2F%2Fvi3.xiu123.cn%2Flive%2F2016%2F05%2F26%2F15%2F1013v1464246499743547801.jpg; _coin6=90211658%3A0%3A0%3A0%3A%E5%B0%8F%E5%B0%8F%E4%BA%BA%E7%89%A9s%3A240349376%3A0%3A0%3A0%3A3%3A1000%3A1000%3A0%3A1000%3A1585725543%3A0%3A0%3A0%3A1%3A0%3A6%3A; _vLastT=1587005714; logtm=1587005716; rechargeNum=90211658-1; guide_newuser_rec=1"
	},
	serve:{
		host:'127.0.0.1',
		port:'8000'
	},
	proxy:{
		host:'127.0.0.1',
		port:'8888',
	}
});

// console.info(r.watchid);
r.join();
// r.parseRoomInfo().then((roomInfo)=>{
// 	console.info('roomInfo',roomInfo)	;
// })

// setTimeout(()=>{
// 	r.sendMsg('你好啊');
// },10000);
}


function getHbByAxios(){
	let headers = {
		'Accept':'application/json, text/plain, */*',
		'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) v.6.cn_login/1.0.0 Chrome/80.0.3987.163 Electron/8.2.2 Safari/537.36',
		'Cookie':'firVist=1588177447; _LiveGuestUser=1001561415%7C%E6%B8%B8%E5%AE%A22c1qaw; shrek_uuid=B4158817744990233; shrek_reft=0%7C158817744938648; smidV2=202004300024088b36a729bee6af85df4e1977c8c360df00414e2f79e9fd510; ticket_v=TbuBLmptfyajky8_P3dCQD9f08TOwwHXNfAPP2vYMUx429VL5UEO4lVbIVVD0YSaioPESh1a_j1xO8H10bba-XC50N_2k2FWhCWDfUXm41l34otlaP8Ak9DLeyl9gGjQ10004; _vinfo=92262073%7C%7Cthfox; logtm=1588177450; _rinfo=https%3A%2F%2Fvi3.xiu123.cn%2Flive%2F2016%2F05%2F26%2F15%2F1013v1464246499743547801.jpg; _coin6=92262073%3A0%3A0%3A0%3Athfox%3A240800467%3A0%3A0%3A0%3A3%3A1000%3A1000%3A0%3A1000%3A1588085365%3A0%3A0%3A0%3A1%3A0%3A1%3A',
		'referer':'https://v.6.cn/333',
		'Proxy-Authorization': 'Basic MTQ3MjoxNDcy',
		'host':'v.6.cn'
	}
	let proxy = {
		host: '121.11.113.176',
	    port: 23054,
	    auth: {
	      username: '1472',
	      password: '1472'
    	}
	}
	// proxy = {
	// 	host: '127.0.0.1',
	//     port: 8888,
	// }
	axios.get('https://www.baidu.com',{
        headers:headers,
        proxy:proxy
    }).then((result)=>{
		console.info('hb result',result);
	}).catch((e)=>{
		console.error(e);
	})
}
// getHbByAxios();


function getHbByNode(){
	
	var options = url.parse('http://1472:1472@121.11.113.176:23054');
	var urlEntity = new URL();
	urlEntity.auth = '1472:1472';
	
	console.info('options',options.toString());
	return ;
	var agent = new HttpsProxyAgent(options);
	// 要访问的目标页面
	const targetUrl = "https://www.baidu.com";
	const urlParsed   = url.parse(targetUrl);

	// 代理ip
	const proxyIp = "121.11.113.176";  // 代理服务器ip
	const proxyPort = "23054"; // 代理服务器host

	// http代理验证信息
	const username = "1472";
	const password = "147";
	const base64    = Buffer.from(username + ":" + password).toString("base64");
	// const options = {
	//     // host    : proxyIp,
	//     // port    : proxyPort,
	//     path    : targetUrl,
	//     agent:agent,
	//     method  : "GET",
	//     headers : {
	//         "Host"                : urlParsed.hostname,
	//         // "Proxy-Authenticate"  : "Basic " + base64,
	//         // "Proxy-Authorization" : "Basic " + base64
	//     }
	// };


	axios.get('https://v.6.cn',{httpsAgent:agent}).then((result)=>{
		console.info('baidu result',result);
	})

	// https.get('https://www.baidu.com',{agent},  (res) => {
 //        console.log("got response: " + res.statusCode);
 //        // 输出返回内容(使用了gzip压缩)
 //        if (res.headers['content-encoding'] && res.headers['content-encoding'].indexOf('gzip') != -1) {
 //            let zlib = require('zlib');
 //            let unzip = zlib.createGunzip();
 //            res.pipe(unzip).pipe(process.stdout);
 //        } else {
 //            // 输出返回内容(未使用gzip压缩)
 //            res.pipe(process.stdout);
 //        }
 //    }).on("error", (err) => {
 //        console.log(err);
 //    }).end();

 //    https.get('https://www.baidu.com',{agent},  (res) => {

 //    }).on("error", (err) => {

 //    }).end();
}

getHbByNode();

