Mui 微信支付、支付宝支付

技术分享图片

 

利用mui 发起手机微信和支付宝支付


 

 

payStatement :调起微信支付接口的参数

技术分享图片

参考文档: https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_12&index=2

 

  /**
     * 支付
     * @param {Object} payType  支付类型
     * @param {Object} payStatement  调起支付宝或微信的statment支付订单信息
     */
    paywx(payType, payStatement) {

        /***判断支付通道****/
        //最终的支付通道
        var channel;
        /***
         * 用于标识支付通道: 
         * "alipay" - 表示支付宝;
         * "wxpay" - 表示微信支付; 
         */
        var payId; //支付标识
        if(payType == "ALIPAY_ANDROID") {
            payId = "alipay";
        } else {
            payId = "wxpay";
        }

        // 取出支付宝和微信的支付通道
        plus.payment.getChannels(function(channels) {
            mui.each(channels, function(index, element) {
                if(element.id == payId) {
channel = element;
                }
            });
            if(!channel) {
                mui.toast(‘获取支付通道失败,请重试!‘);
            }
            setTimeout(function() {
                mui.confirm(‘支付已完成‘, ‘提示‘, [‘支付遇到问题‘, ‘支付完成‘], function(e) {
if(e.index == 1) {
    app.tokenAjax_Get({
        url: API_URL_GET_ORDER_STATUS + dataSource.orderId,
        success: function(result) {
            if(result.status == 1) {
                var status = result.data;
                if(status == "JUST_CREATED") {
mui.toast(‘订单未支付‘);
                } else if(status == ‘CANCEL‘) {
mui.toast(‘订单已被取消‘);
//清除定时器
clearInterval(timer);
//打开
plus.webview.currentWebview().close();
plus.webview.getWebviewById("pay").close();
plus.webview.getWebviewById("order").close();
                } else {
//清除定时器
clearInterval(timer);
//打开
app.openRefreshOrderListPage();
                }
            }
        },
        error: function(xhr) {
            app.httpError(xhr.status);
        }
    });
}
                }, ‘div‘)
            }, 3000);
            //发起支付
            plus.payment.request(channel, payStatement, function(result) {
                mui.toast(‘支付完成‘);
                /**
                 *查询订单状态是否已支付
                 * 轮询查询订单状态
                 * 
                 */
                var timer1 = setInterval(function() {
app.tokenAjax_Get({
    url: API_URL_GET_ORDER_STATUS + dataSource.orderId,
    success: function(result) {
        if(result.status == 1) {
            var status = result.data;
            if(status == "JUST_CREATED") {
                mui.toast(‘订单未支付‘);
            } else if(status == ‘CANCEL‘) {
                mui.toast(‘订单已被取消‘);
                //清除定时器
                clearInterval(timer);
                clearInterval(timer1)
                //打开
                plus.webview.currentWebview().close();
                plus.webview.getWebviewById("pay").close();
                plus.webview.getWebviewById("order").close();
            } else {
                //清除定时器
                clearInterval(timer);
                clearInterval(timer1)
                //打开
                app.openRefreshOrderListPage();
            }
        }
    },
    error: function(xhr) {
        app.httpError(xhr.status);
    }
});
                }, 1000);

            }, function(error) {
                console.log(JSON.stringify(error));
                mui.toast("支付失败");
            });

        }, function(e) {
            mui.toast("获取支付通道列表失败:" + e.message);
        });

    }

 

更多错误信息请参考支付(Payment)规范文档:http://www.html5plus.org/#specification#/specification/Payment.html

 

注意: (  微信支付提示{"code":-100,"message":"[payment微信:-1]General errors"}  )

  • 微信支付安卓不支持真机调试
  • 需要打包到手机测试, 打包测试需要使用自己的私有证书打包apk

 

Mui 微信支付、支付宝支付

以上是Mui 微信支付、支付宝支付的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>