function onBridgeReady(params) {
	AlipayJSBridge.call("tradePay", {
		tradeNO: params.tradeNo,
	}, function(result) {
		if (result.resultCode == '9000') {
			location.href = params.succUrl
		} else {
			location.href = params.cancelUrl;
		}
		//alert(JSON.stringify(result));
	});
}

export const aliPayJs = (params) => {
	if (typeof window.WeixinJSBridge === 'undefined') {
		if (document.addEventListener) {
			document.addEventListener('AlipayJSBridgeReady', function() {
				onBridgeReady(params)
			}, false)
		} else if (document.attachEvent) {
			document.attachEvent('AlipayJSBridgeReady', function() {
				onBridgeReady(params)
			})
			document.attachEvent('AlipayJSBridgeReady', function() {
				onBridgeReady(params)
			})
		}
	} else {
		onBridgeReady(params)
	}
}
