当前位置:网站首页>uniapp H5页面调用微信支付
uniapp H5页面调用微信支付
2022-07-02 14:51:00 【玖伍玖伍】
/*支付*/
<!--
1.点击支付按钮触发payOrder
2.postJSON是封装的请求方法,参数subData是根据后端的来
3.api 是后端的支付接口返回订单相应的东西
4.触发微信的支付api
-->
//立即支付
payOrder(order_id,order_money){
let that=this;
let subData={
user_id:uni.getStorageSync('userInfo').user_id, //用户id
payment_mode:2, //支付类型,
money:order_money, //支付金额
pay_type:1, //订单支付
order_id:order_id //订单id
}
postJSON(api,subData,res=>{
if(res.data.status==1){
console.log('拿到支付参数:'+res.data.data.timeStamp)
console.log('拿到支付参数:'+res.data.data.nonceStr)
console.log('拿到支付参数:'+res.data.data.package)
console.log('拿到支付参数:'+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');
}
});
},
//支付
payApi(timeStamp,nonceStr,packages,paySign){
let that=this;
uni.requestPayment({
'timeStamp':timeStamp, //后台返回
'nonceStr': nonceStr,//后台返回,随机字符串,长度为32个字符以下。
'package': packages,//后台返回,统一下单接口返回的 prepay_id 参数值
'signType': 'MD5', //签名类型
'paySign': paySign,//后台返回,签名
"success":function(res){
//支付成功之后的操作,弹窗提示或者跳转成功页面
uni.redirectTo({
url: 'url',
})
},
"fail":function(err){
//支付失败的操作,弹窗提示或者跳转成功页面
uni.showToast({
title: '支付失败',
icon: 'none'
})
uni.redirectTo({
url: 'url',
})
}
})
},
边栏推荐
- Does digicert SSL certificate support Chinese domain name application?
- Easy language ABCD sort
- IP地址转换地址段
- Configure MySQL under Linux to authorize a user to access remotely, which is not restricted by IP
- ThreadLocal
- Eth data set download and related problems
- Chapter 3 of hands on deep learning - (1) linear regression is realized from scratch_ Learning thinking and exercise answers
- Un an à dix ans
- 求简单微分方程
- 871. Minimum refueling times
猜你喜欢
PhD battle-11 preview | review and prospect backdoor attack and defense of neural network
[shutter] dart data type (dynamic data type)
871. 最低加油次数
Configure MySQL under Linux to authorize a user to access remotely, which is not restricted by IP
A case study of college entrance examination prediction based on multivariate time series
如何与博格华纳BorgWarner通过EDI传输业务数据?
A few lines of code to complete RPC service registration and discovery
一文看懂:数据指标体系的4大类型
Believe in yourself and finish the JVM interview this time
移动应用性能工具探索之路
随机推荐
Nexus簡介及小白使用IDEA打包上傳到Nexus3私服詳細教程
Shutter: action feedback
Jiuxian's IPO was terminated: Sequoia and Dongfang Fuhai were shareholders who had planned to raise 1billion yuan
VScode知识点——常见报错
Qstype implementation of self drawing interface project practice (II)
Experience home office, feel the completion of the project | community essay solicitation
QStyle实现自绘界面项目实战(二)
绿竹生物冲刺港股:年期内亏损超5亿 泰格医药与北京亦庄是股东
Sword finger offer 25 Merge two sorted linked lists
[fluent] dart data type map type (create map set | initialize map set | traverse map set)
Does digicert SSL certificate support Chinese domain name application?
Visibilitychange – refresh the page data when the specified tab is visible
Ap和F107数据来源及处理
Changwan group rushed to Hong Kong stocks: the annual revenue was 289million, and Liu Hui had 53.46% voting rights
What is agile development process
Idea2021.1 installation tutorial
TCP拥塞控制详解 | 2. 背景
【Leetcode】14. 最长公共前缀
简单线性规划问题
Sword finger offer 21 Adjust the array order so that odd numbers precede even numbers