function jsonToQueryString(json) {
	return Object.keys(json)
		.map(key => encodeURIComponent(key) + '=' + encodeURIComponent(json[key]))
		.join('&');
}

function getUrlParam(name) {
	var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)') //构造一个含有目标参数的正则表达式对象
	var r = window.location.search.substr(1).match(reg) //匹配目标参数
	if (r != null) return unescape(r[2])
	return null //返回参数值
}

export function eventSite(params) {
	var p = jsonToQueryString(Object.assign({
		experiment_id: getUrlParam('experiment_id'),
		experiment_connection_id: getUrlParam('id'),
	}, params))
	var xhr = new XMLHttpRequest();
	xhr.open('GET', `https://saas-dml-pro.ezijing.com/api/lab/v1/experiment/member/event-create-by-shop?${p}`, true);
	xhr.withCredentials = true;
	xhr.send();
}

export function getCurrentTime() {
	var currentTime = new Date();
	var year = currentTime.getFullYear();
	var month = currentTime.getMonth() + 1; // 月份从0开始，因此需要1
	var day = currentTime.getDate();
	var hours = currentTime.getHours();
	var minutes = currentTime.getMinutes();
	var seconds = currentTime.getSeconds();
	return `${year}-${toDo(month)}-${toDo(day)} ${toDo(hours)}:${toDo(minutes)}:${toDo(seconds)}`
}
function toDo(n) {
	return n < 10 ? '0' + n : n
}