<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<button id="aaa">支付</button>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script type="text/javascript">
$('#aaa').click(function(){
$.post("https://x.2tb.cn/api/im/unifiedOrder",{openid:"orV5O1GOiTxjbBJcDLPMn92m3s4s"}, function (re) {
function onBridgeReady(){
WeixinJSBridge.invoke(
'getBrandWCPayRequest', re.data, function(res){
alert(JSON.stringify(res));
if(res.err_msg == "get_brand_wcpay_request:ok" ) {
//doit 这里处理支付成功后的逻辑,通常为页面跳转
}
});
}
if (typeof WeixinJSBridge == "undefined"){
if( document.addEventListener ){
document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
}else if (document.attachEvent){
document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
}
}else{
onBridgeReady();
}
});
})
</script>
</body>
</html>