当前位置:网站首页>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',
})
}
})
},
边栏推荐
- Ocio V2 reverse LUT
- QWebEngineView崩溃及替代方案
- 剑指 Offer 26. 树的子结构
- 移动应用性能工具探索之路
- Tech talk activity preview | building intelligent visual products based on Amazon kVs
- 2020 "Lenovo Cup" National College programming online Invitational Competition and the third Shanghai University of technology programming competition (a sign in, B sign in, C sign in, D thinking +mst
- [fluent] dart data type map type (create map set | initialize map set | traverse map set)
- What is the difference between JSP and servlet?
- class和getClass()的区别
- si446使用记录(一):基本资料获取
猜你喜欢

13、Darknet YOLO3

亚马逊云科技 Community Builder 申请窗口开启

Changwan group rushed to Hong Kong stocks: the annual revenue was 289million, and Liu Hui had 53.46% voting rights

【Leetcode】13. 罗马数字转整数

Sword finger offer 25 Merge two sorted linked lists

Use of openpose

例题 非线性整数规划

TCP congestion control details | 2 background

Sword finger offer 27 Image of binary tree

The poor family once again gave birth to a noble son: Jiangxi poor county got the provincial number one, what did you do right?
随机推荐
Sword finger offer 25 Merge two sorted linked lists
二、mock平台的扩展
linux安装postgresql + patroni 集群问题
Use of openpose
GeoServer:发布PostGIS数据源
Tech Talk 活动预告 | 基于Amazon KVS打造智能视觉产品
Introduction to Hisilicon hi3798mv100 set top box chip [easy to understand]
The beginning of life
伟立控股港交所上市:市值5亿港元 为湖北贡献一个IPO
Nexus Introduction and Xiaobai use idea Packaging and Upload to Nexus 3 private service detailed tutoriel
[shutter] dart data type (dynamic data type)
Meanings of SNAT, DNAT and masquerade in iptables
Linux Installation PostgreSQL + Patroni cluster problem
si446使用记录(一):基本资料获取
人生的开始
Un an à dix ans
Role and function of uboot
海思Hi3798MV100机顶盒芯片介绍[通俗易懂]
【Leetcode】14. 最長公共前綴
寒门再出贵子:江西穷县考出了省状元,做对了什么?