前端之美-H5

uni-app 支付

2019-11-29  本文已影响0人  荼蘼toome

目前只解决了支付宝支付

判断用户是否登录

刚开始使用的undefined...一直没有走入代码块.....应该是null


                   if (this.uid === '' || this.uid === null) {
                        uni.hideLoading()
                        uni.showToast({
                            title: '您还没有登录',
                            icon: 'none'
                        });
                        return false;
                        console.log("udi", this.uid)
                    }

接着生成订单,进入三方支付

uni.request({
                    url: this.baseUrl + '/order/saveHotelOrder',
                    data: {
                        uid: uni.getStorageSync('userInfo').id,
                        cid: this.id,
                        num: this.num,
                        total: this.money,
                        name: this.realName,
                        phone: this.phone,
                        remark: this.real,
                        type: 1 //生成订单
                    },
                    header: {
                        'content-type': 'application/x-www-form-urlencoded'
                    },
                    success: (res) => {
                        console.log(res)
                        if (res.data.meta.code == 200) {
                            //获得订单数据orderList
                            this.order = res.data.data
                            console.log("订单号", this.order)
                            this.pay()
                        }
                    },
                    fail: (e) => {
                        uni.hideLoading()
                        uni.showToast({
                            title: '请进行验证',
                            icon: 'none'
                        })
                    }
                })
            },
            pay() {
                uni.showToast({
                    title: '正在检测支付环境...',
                    icon: 'none',
                    success: (res) => {
                        if (this.type == 'alipay') {
                            uni.request({
                                url: this.baseUrl + '/payAlis',
                                method: 'POST',
                                data: {
                                    id: this.order,
                                    mo: this.money
                                },
                                header: {
                                    "content-type": 'application/x-www-form-urlencoded'
                                },
                                success: res => {
                                    console.log(res.statusCode)
                                    if (res.statusCode == 200) {
                                        console.log(res.data)
                                        var data=res.data
                                        uni.getProvider({
                                            service: 'payment',
                                            success: function(res) {
                                                uni.requestPayment({
                                                    provider: 'alipay',
                                                    orderInfo: data, //微信、支付宝订单数据
                                                    success: function(res) {
                                                        console.log('success:' + JSON.stringify(res));
                                                    },
                                                    fail: function(err) {
                                                        console.log('fail:' + JSON.stringify(err));
                                                        uni.showModal({
                                                            title: '您已取消操作',
                                                            showCancel: true
                                                        })
                                                    }
                                                });
                                            }
                                        });

                                    }
                                },
                                fail: (e) => {
                                    uni.hideLoading()
                                    uni.showToast({
                                        title: JSON.stringify(e),
                                        icon: 'none'
                                    })
                                },
                                complete: () => {}
                            });
                        } else if (this.type == 'wechat') {
                            uni.request({
                                url: this.baseUrl + '/weixin/pay/wx',
                                method: 'POST',
                                data: {
                                    id: this.order,
                                    money: this.money
                                },
                                header: {
                                    "content-type": 'application/x-www-form-urlencoded'
                                },
                                success: res => {
                                    console.log(res)

                                    var data = {
                                        appid: res.data.appId,
                                        noncestr: res.data.nonceStr,
                                        package: res.data.packages,
                                        partnerid: res.data.partnerId,
                                        prepayid: res.data.prepayId,
                                        timestamp: res.data.timeStamp,
                                        sign: res.data.sign
                                    }

                                    if (res.statusCode == 200) {

微信传参格式

                                        var data = {
                                            appid: res.data.appId,
                                            noncestr: res.data.nonceStr,
                                            package: res.data.packages,
                                            partnerid: res.data.partnerId,
                                            prepayid: res.data.prepayId,
                                            timestamp: res.data.timeStamp,
                                            sign: res.data.sign
                                        }
                                        uni.getProvider({
                                            service: 'payment',
                                            success: function(res) {
                                                // uni.showModal({
                                                //  title: data,
                                                //  showCancel: true
                                                // })
                                                uni.requestPayment({
                                                    provider: 'wxpay',
                                                    orderInfo: data, //微信、支付宝订单数据
                                                    success: function(res) {
                                                        console.log('success:' + JSON.stringify(res));
                                                    },
                                                    fail: function(err) {
                                                        uni.showToast({
                                                            title: JSON.stringify(err),
                                                            icon: 'none'
                                                        })
                                                        console.log('fail:' + JSON.stringify(err));
                                                    }
                                                });
                                            }
                                        });
                                    }
                                },
                                fail: (e) => {
                                    uni.hideLoading()
                                    uni.showToast({
                                        title: JSON.stringify(e),
                                        icon: 'none'
                                    })
                                },
                                complete: () => {}
                            });
                        }
                    },
                    fail: (e) => {
                        setTimeout(function() {
                            uni.showToast({
                                icon: "none",
                                title: "请检查网络"
                            })
                        }, 10000);
                    }
                });
            }

其中支付宝的订单数据
alipay_sdk=alipay-sdk-java-dynamicVersionNo&app_id=2019112369402007&biz_content=%7B%22body%22%3A%22%E5%B8%B8%E5%B7%9E%E8%9A%95%E7%8C%AB%E7%BD%91%E7%BB%9C%E7%A7%91%E6%8A%80%E6%9C%89%E9%99%90%E5%85%AC%E5%8F%B8%22%2C%22out_trade_no%22%3A%22157484223056593%22%2C%22product_code%22%3A%22QUICK_MSECURITY_PAY%22%2C%22seller_id%22%3A%222088231505705213%22%2C%22subject%22%3A%22%E7%94%A8%E6%88%B7%E6%94%AF%E4%BB%98%E8%AE%A2%E5%8D%95%3A98.0%E5%85%83%22%2C%22timeout_express%22%3A%2230m%22%2C%22total_amount%22%3A%2298.0%22%7D&charset=utf-8&format=json&method=alipay.trade.app.pay&notify_url=http%3A%2F%2Fhwb2cv.natappfree.cc%2Fnotify_url&sign=lSR7gOM%2B6%2BP3RxstHdSxNNHo19xe5cQWTIA6dyOmxZ4AcY2IJ7qO5tke%2Ft3B1u8SXbSIb94Nf%2FrClS7sM7sgMfau0jm3FlPRbtcZHQAr%2Bw7fUm4lZ%2BoO2UItInuapfUV9LJBOv82SAUrO%2BhY%2BTMbD2FVGu7aYuQKThuN0qJQJ6r1LrMzKo2%2B4zRSoa6JM%2F4qAY86PzvUL%2Fhxm1K52IOIToPCXQyorEZzWteEVhgqpQpwXhdEKmYAfFysy0VJlyKGagyFkiKAKgU%2B4k1jE9eIWwwtKc2Ikgq%2FJYoSHjtH8jWhjAcAX8oe5BO%2FDr5OB4pmO7KJI9Q5zmgTg4VR4uFFoA%3D%3D&sign_type=RSA2&timestamp=2019-11-27+16%3A10%3A30&version=1.0

第一天没有调用成功返回


微信图片_20191129142345.jpg

微信只有第一次成功另外都是返回-1

查看官方文档 AD9B883F-758B-46ae-979E-ABE2792FB3E5.png

到现在还没有能够支付
=-=

----------------------------------------------------------------------------------------------*-

续版

image.png

参考文档 -- and 包下载地址
https://blog.csdn.net/Drothy_qin/article/details/49947823

有时候需要获取安卓应用的签名,直接通过keytool

keytool -list -v -keystore signfile.jks.keystore -storepass password

然后获取到签名文件内部的信息,MD5, SHA1,SHA256, 看需要,一般是填MD5,是要小写还是大写需要看要求选择了

生成签名文件 keytool -genkeypair -alias myappKey -keyalg RSA -validity 20000 -keystore shy_debug.jks

keytool -genkey -alias myappKey -keyalg RSA -validity 20000 -keystore myappSignKey.keystore



# 百度键入”微信开放平台”

# 或直接访问网址[https://open.weixin.qq.com/](https://open.weixin.qq.com/)



       生成安卓证书签名认证之后
1.使用自带包名打包
2.安装包中的应用信息,将其包名放到生成安卓签名的软件中   
    
3.将签名放到微信开发平台中
上一篇下一篇

猜你喜欢

热点阅读