当前位置:网站首页>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',
})
}
})
},
边栏推荐
- ROS知识点——ros::NodeHandle n 和 nh(“~“)的区别
- 深度之眼(三)——矩阵的行列式
- 体验居家办公完成项目有感 | 社区征文
- 剑指 Offer 24. 反转链表
- &lt; IV & gt; H264 decode output YUV file
- 【Leetcode】14. 最长公共前缀
- Goodbye, shucang. Alibaba's data Lake construction strategy is really awesome!
- 深度之眼(二)——矩阵及其基本运算
- Tech Talk 活动预告 | 基于Amazon KVS打造智能视觉产品
- Domestic relatively good OJ platform [easy to understand]
猜你喜欢

QStyle实现自绘界面项目实战(二)

Ap和F107数据来源及处理

Cell: Tsinghua Chenggong group revealed an odor of skin flora. Volatiles promote flavivirus to infect the host and attract mosquitoes

社交元宇宙平台Soul冲刺港股:年营收12.8亿 腾讯是股东

A few lines of code to complete RPC service registration and discovery

关于我

Experience home office, feel the completion of the project | community essay solicitation

Configure MySQL under Linux to authorize a user to access remotely, which is not restricted by IP

The computer comes with software to make the background color of the picture transparent (matting white background)

福元医药上交所上市:市值105亿 胡柏藩身价超40亿
随机推荐
QStyle实现自绘界面项目实战(二)
【Leetcode】14. 最長公共前綴
Configure ARP table entry restrictions and port security based on the interface (restrict users' private access to fool switches or illegal host access)
綠竹生物沖刺港股:年期內虧損超5億 泰格醫藥與北京亦莊是股東
人生的开始
相信自己,这次一把搞定JVM面试
Experience home office, feel the completion of the project | community essay solicitation
寒门再出贵子:江西穷县考出了省状元,做对了什么?
The macrogenome microbiome knowledge you want is all here (2022.7)
Eth data set download and related problems
深度之眼(三)——矩阵的行列式
Soul, a social meta universe platform, rushed to Hong Kong stocks: Tencent is a shareholder with an annual revenue of 1.28 billion
【征文活动】亲爱的开发者,RT-Thread社区喊你投稿啦
Smart trash can (V) - light up OLED
Blog theme "text" summer fresh Special Edition
线性规划例题 投资的收益与风险
Eye of depth (II) -- matrix and its basic operations
Deep learning image data automatic annotation [easy to understand]
visibilitychange – 指定标签页可见时,刷新页面数据
VMware install win10 image