当前位置:网站首页>Uniapp H5 page calls wechat payment
Uniapp H5 page calls wechat payment
2022-07-02 17:24:00 【Jiuwujiuwu】
/* payment */
<!--
1. Click the payment button to trigger payOrder
2.postJSON Is the encapsulated request method , Parameters subData It is based on the backend
3.api It is the back-end payment interface that returns the corresponding things of the order
4. Trigger wechat payment api
-->
// Pay now
payOrder(order_id,order_money){
let that=this;
let subData={
user_id:uni.getStorageSync('userInfo').user_id, // user id
payment_mode:2, // Payment type ,
money:order_money, // Pay the amount
pay_type:1, // Order payment
order_id:order_id // Order id
}
postJSON(api,subData,res=>{
if(res.data.status==1){
console.log(' Get payment parameters :'+res.data.data.timeStamp)
console.log(' Get payment parameters :'+res.data.data.nonceStr)
console.log(' Get payment parameters :'+res.data.data.package)
console.log(' Get payment parameters :'+res.data.data.paySign)
that.payApi(res.data.data.timeStamp,
res.data.data.nonceStr,
res.data.data.package,
res.data.data.paySign)
}else{
that.$toast(res.data.message,'none');
}
});
},
// payment
payApi(timeStamp,nonceStr,packages,paySign){
let that=this;
uni.requestPayment({
'timeStamp':timeStamp, // Backstage return
'nonceStr': nonceStr,// Backstage return , Random string , The length is 32 Less than characters .
'package': packages,// Backstage return , Unified order interface returns prepay_id Parameter values
'signType': 'MD5', // Signature type
'paySign': paySign,// Backstage return , Signature
"success":function(res){
// Operation after successful payment , Pop up prompt or jump to the success page
uni.redirectTo({
url: 'url',
})
},
"fail":function(err){
// Payment failed operation , Pop up prompt or jump to the success page
uni.showToast({
title: ' Failure to pay ',
icon: 'none'
})
uni.redirectTo({
url: 'url',
})
}
})
},
边栏推荐
猜你喜欢

Chapter 3 of hands on deep learning - (1) linear regression is realized from scratch_ Learning thinking and exercise answers

PhD battle-11 preview | review and prospect backdoor attack and defense of neural network

Does digicert SSL certificate support Chinese domain name application?

Ap和F107数据来源及处理
![[fluent] dart data type map type (create map set | initialize map set | traverse map set)](/img/02/75d21470ea0ae4cd3d17696a93d1ca.jpg)
[fluent] dart data type map type (create map set | initialize map set | traverse map set)

ThreadLocal

伟立控股港交所上市:市值5亿港元 为湖北贡献一个IPO

Sword finger offer 22 The penultimate node in the linked list

Tech talk activity preview | building intelligent visual products based on Amazon kVs

深度之眼(三)——矩阵的行列式
随机推荐
默认浏览器设置不了怎么办?
Method of C language self defining function
TCP拥塞控制详解 | 2. 背景
What if the default browser cannot be set?
Nexus簡介及小白使用IDEA打包上傳到Nexus3私服詳細教程
关于我
The difference of message mechanism between MFC and QT
Believe in yourself and finish the JVM interview this time
Smart trash can (V) - light up OLED
社交元宇宙平台Soul冲刺港股:年营收12.8亿 腾讯是股东
How to transfer business data with BorgWarner through EDI?
Shutter: action feedback
什么是敏捷开发流程
QWebEngineView崩溃及替代方案
visibilitychange – 指定标签页可见时,刷新页面数据
871. 最低加油次数
Dgraph: large scale dynamic graph dataset
GeoServer:发布PostGIS数据源
Green bamboo biological sprint Hong Kong stocks: loss of more than 500million during the year, tiger medicine and Beijing Yizhuang are shareholders
13、Darknet YOLO3