import config from "@/config";

//#ifdef H5
const jweixin = import('weixin-js-sdk')
//#endif
export function configWeiXin(callback) {
	const url = ""

	//#ifdef H5
	if (window.location.host) {
		url = window.location.host;
	}

	if (uni.getStorageSync("serveUrl")) {
		url = uni.getStorageSync("serveUrl");
	}
	//#endif

	uni.request({
		url: "https://qhome.usky.cn/USKYZHAF/sign.php",
		header: {
			'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
		},
		data: {
			"url": url
		},
		method: 'GET',
		success: (res) => {
			// console.log('请求的签名的参数')
			// console.log(res)

			let apiList = [ // 可能需要用到的能力 需要啥就写啥。多写也没有坏处
				'openLocation',
				'getLocation',
				'scanQRCode'
			];
			let info = {
				debug: false, // 调试，发布的时候改为false
				appId: res.data.appid,
				nonceStr: res.data.nonceStr,
				timestamp: parseInt(res.data.timestamp),
				signature: res.data.sha_str,
				jsApiList: apiList
			};

			jweixin.config(info);
			jweixin.error(err => {
				alert('config fail:', err);
				return
			});

			jweixin.ready(res => {
				if (callback) callback(jweixin);
			});
		}
	});
}
