Mui 微信支付、支付宝支付

9 篇文章 0 订阅

在这里插入图片描述
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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值