JSAPI支付页面DEMO
<pre><code>注意替换jsApiCall()方法中的
"appId":"wx50207d2390936e26",
"timeStamp":"1427160790332",
"signType":"MD5",
"package":"prepay_id=wx2015032409435699f3c23fd30370937173",
"nonceStr":"0d6HuxczrznWuXb8",
"paySign":"D61AE52D8167C42B341A9290E88EE7AA"
参数为实际支付返回的正式参数即可掉起支付。
建议!!!
测试之初,建议直接使用该页面进行测试,等到实际调起支付,排除相关的干扰之后,再添加页面中业务相关的部分。</code></pre>
<pre><code class="language-html"><!doctype html>
<html>
<head>
<head>
<title>微信JSAPI支付页面demo</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=UTF-8">
</head>
<body>
</br></br></br></br>
<div align="center">
正在支付,请等待....
</div>
<script type="text/javascript" src="http://static.solaridc.com/jquery/jquery-1.9.1.js"></script>
<script type="text/javascript">
callpay();
//调用微信JS api 支付
function jsApiCall()
{
WeixinJSBridge.invoke(
'getBrandWCPayRequest',
{
"appId":"wx50207d2390936e26",
"timeStamp":"1427160790332",
"signType":"MD5",
"package":"prepay_id=wx2015032409435699f3c23fd30370937173",
"nonceStr":"0d6HuxczrznWuXb8",
"paySign":"D61AE52D8167C42B341A9290E88EE7AA"
},
function(res){
//WeixinJSBridge.log(res.err_msg);
//alert(res.err_code+res.err_desc+res.err_msg);
if(res.err_msg == "get_brand_wcpay_request:ok" ) {
alert('支付成功!');
}
}
);
}
function callpay()
{
if (typeof WeixinJSBridge == "undefined"){
if( document.addEventListener ){
document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
}else if (document.attachEvent){
document.attachEvent('WeixinJSBridgeReady', jsApiCall);
document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
}
}else{
jsApiCall();
}
}
// 支付宝网页版调起支付
function alipay(data, fun) {
AlipayJSBridge.call("tradePay", {
tradeNO : data.tradeNo
}, function(result) {
fun(result);
});
}
alipay(data, function(result) {
if (result.resultCode == "9000") {
alert('支付成功!');
} else {
alert('支付失败!');
}
});
</script>
</body>
</html></code></pre>