支付宝小程序支付接入

小程序支付文档:https://opendocs.alipay.com/mini/introduce/pay
无需引入额外库:https://opendocs.alipay.com/mini/api/openapi-pay
需要引入Alipay JSSDK:https://myjsapi.alipay.com/alipayjsapi/util/pay/tradePay.html

JSAPI支付

支付宝原生

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// .js
my.tradePay({
// 调用统一收单交易创建接口(alipay.trade.create),获得返回字段支付宝交易号trade_no
tradeNO: '201711152100110410533667792',
success: (res) => {
my.alert({
content: JSON.stringify(res),
});
},
fail: (res) => {
my.alert({
content: JSON.stringify(res),
});
}
});

uni-app

1
2
3
4
5
6
7
8
9
10
uni.requestPayment({
provider: 'alipay',
orderInfo: 'orderInfo', //支付宝订单交易号
success: function (res) {
console.log('success:' + JSON.stringify(res));
},
fail: function (err) {
console.log('fail:' + JSON.stringify(err));
}
});

WAP支付

支付宝原生

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// .js
my.tradePay({
// 调用资金冻结接口(alipay.fund.auth.order.app.freeze),获取资金授权参数
orderStr: 'alipay_sdk=alipay-sdk-java-3.0.118.DEV&app_id=2018112803019836&biz_content=%7B%22amount%22%3A%220.02%22%2C%22extra_param%22%3A%22%7B%5C%22category%5C%22%3A%5C%22CHARGE_PILE_CAR%5C%22%7D%22%2C%22order_title%22%3A%22%D6%A7%B8%B6%B1%A6%D4%A4%CA%DA%C8%A8%22%2C%22out_order_no%22%3A%22ZMOutOrderNoAppFreeze2018052915543415090975%22%2C%22out_request_no%22%3A%22ZMOutReqNoAppFreeze20180529155434581875858%22%2C%22pay_timeout%22%3A%222d%22%2C%22payee_user_id%22%3A%222088202224929664%22%2C%22product_code%22%3A%22PRE_AUTH_ONLINE%22%7D&charset=GBK&format=json&method=alipay.fund.auth.order.app.freeze&sign=L4wk%2FNKcbJOo3n6Q5qbPzn0jUsvZlK4jr7iXnghudR0zeWJMmeNC71qIBSQfIz45n%2B5iTd0NQ5IK581xI2xCShTCiKAywnQcDmA%2Bjf%2BrRdKCDQCMLfCz%2BZ37C%2B6zxAX3e81%2F8Hr29lw4VPFfHkp9FmMwKw%2FGkNfV5ZlWoh7UtN8%3D&sign_type=RSA&timestamp=2018-05-29+15%3A54%3A35&version=1.0',
success: (res) => {
my.alert({
content: JSON.stringify(res),
});
},
fail: (res) => {
my.alert({
content: JSON.stringify(res),
});
}
});

orderStr为payUrl去掉支付宝网关地址的支付串

uni-app

1
2
3
4
5
6
7
8
9
10
uni.requestPayment({
provider: 'alipay',
orderStr: 'orderStr', //支付宝订单数据
success: function (res) {
console.log('success:' + JSON.stringify(res));
},
fail: function (err) {
console.log('fail:' + JSON.stringify(err));
}
});

orderStr为payUrl去掉支付宝网关地址的支付串

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2021 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :