import wx from 'weixin-js-sdk'
import axios from 'axios'
let share = {
	title: "",
	desc: "",
	link: "",
	imgUrl: "",
	init: function () {
		var path = location.href.split('#')[0];
	var url = "";
	var appid = "";
	if (path.indexOf("//wx.igandan.com") > 1 || path.indexOf("oss")>1) {
		url = "https://app.igandan.com/app/manager/getSignature4bing";
		appid = "wxa4132ef4701ac5e4";
		
	} else {
		url = "https://dev-app.igandan.com/app/manager/getSignature4bing";
		appid = "wx68affaa9d23528f8";
	}

axios.get(url, {
		params: {
			path: encodeURIComponent(window.location.href.split('#')[0]),
			appid: appid
		}
	}).then(json => {
			wx.config({
				debug: false,
				appId: appid,
				timestamp: json.data.timestamp,
				nonceStr: json.data.nonceStr,
				signature: json.data.signature,
				jsApiList: ['updateAppMessageShareData', 'updateTimelineShareData', 'onMenuShareTimeline', 'onMenuShareAppMessage','chooseImage'],
				openTagList: ['wx-open-launch-app','chooseImage']
			});
	}).catch((e) => {
		console.log('获取数据失败');
	});
	wx.checkJsApi({
		jsApiList: ['updateAppMessageShareData', 'updateTimelineShareData', 'onMenuShareTimeline', 'onMenuShareAppMessage'], // 需要检测的JS接口列表，所有JS接口列表见附录2,
		success: function (res) {
			console.log(res)
		}
	});
		wx.ready(function () {
		
			
			wx.updateAppMessageShareData({
				title: share.title,
				desc: share.desc,
				link: share.link,
				imgUrl: share.imgUrl,
				success: function () {}
			})
			wx.updateTimelineShareData({
				title: share.title,
				desc: share.desc,
				link: share.link,
				imgUrl: share.imgUrl,
				success: function () {}
			})
			wx.onMenuShareTimeline({
				title: share.title,
				desc: share.desc,
				link: share.link,
				imgUrl: share.imgUrl,
				success: function () {}
			})
			wx.onMenuShareAppMessage({
				title: share.title,
				desc: share.desc,
				link: share.link,
				imgUrl: share.imgUrl,
				success: function () {}
			})
		});
	}
}

function WXSHARE(title, desc, link, imgUrl) {
	share.title = title;
	share.desc = desc;
	share.link = link;
	if (imgUrl == undefined || imgUrl == "") {
		imgUrl = "https://doc.igandan.com/app/html/img/2016/20160714132557.png";
	}
	share.imgUrl = imgUrl;
	share.init();
};


export {
	WXSHARE
}