uniapp调起微信支付查询订单状态逻辑处理
首先看页面效果:
<template>
<view class="page">
<view class="page-bd">
<view class="page-container">
<view class="xzje">
<view class="bt">请选择充值金额</view>
<view class="lb">
<view class="mx" v-for="(item, index) in moneyList" :key="index"
@click="selectList(item, index)">
<view class="one">模拟成本{{ item.capitalValue }}</view>
<view class="two">¥{{ item.moneyValue }}</view>
<view class="three">{{ item.desc }}</view>
<image v-if="currentList == index" src="/static/images/pay_select.png" class="select">
</image>
</view>
</view>
</view>
</view>
<view class="db">
<view class="lf">还需支付:¥{{ payVal }}</view>
<view class="lr" @click="gopay">立即支付</view>
</view>
</view>
</view>
</template>
<script>
import { // session数据缓存
getSession
} from "@/util/storage";
import { // 后端接口
queryVeinverStmoreMoney,
sendPayApp,
queryPayStatus
} from "@/api/practice.js";
export default {
data() {
return {
moneyList: [], // 金额列表
discount: "", // 支付金额
currentList: 0,
payVal: "", // 优惠后的支付金额
capitalValue: "",
userInfo: {}
};
},
onShow() {
this.getMoneyList();
this.userInfo = getSession("userInfo");
},
onLoad(option) {
this.capitalDate.totalCapital = option.userTotalCapital
this.capitalDate.capital.availableCapital = option.availableCapital
this.capitalDate.todayProfitLoss = option.todayProfitLoss
},
methods: {
// 获取优惠票列表
async getMoneyList() {
let res = await queryVeinverStmoreMoney();
if (res.result) {
this.moneyList = res.result[0].datas;
this.discount = res.result[0].discount / 10;
let moneyValue = this.moneyList[this.currentList].moneyValue;
this.payVal = moneyValue * this.discount;
this.capitalValue = this.moneyList[this.currentList].capitalValue;
}
},
// 选择票
selectList(item, index) {
this.currentList = index;
this.payVal = item.moneyValue * this.discount;
this.capitalValue = item.capitalValue;
},
// 支付
gopay() {
const extendParam = {
MatchID: getSession("raceInfo").matchID, // 接口所需参数
Amount: this.capitalValue, // 接口所需参数
};
const payParams = {
total_fee: this.payVal,
body: "模拟资金充值",
openId: this.userInfo.userID,
product: 22,
extendParam: JSON.stringify(extendParam),
};
sendPayApp(payParams).then((res) => { // 发起支付
uni.hideLoading(); //下单中提示关闭
if (res.isSuccess) {
let info = {
signType: "MD5",
};
info = Object.assign(info, res.info);
this.callApp(res.info, payParams);
this.getPayStatus(res.info)
} else {
uni.showToast({
title: "发起支付失败!",
icon: "error",
duration: 2000,
});
}
console.log(res);
});
},
// 获取支付状态
getPayStatus(data1){
//显示加载框
uni.showLoading({
title: '支付中...',
mask: true
});
// 循环查询订单状态
let payStatus = 0
let count = 0
let sint = setInterval(() => {
this.getPayStatus_(data1).then((status)=>{
let payStatus = status
count++
if(status==1){
clearInterval(sint);
uni.hideLoading();
uni.navigateBack()
}
if(count==10){//设置10秒后取消循环查询订单状态
clearInterval(sint);
uni.hideLoading();
uni.showToast({
title: "未支付成功!",
icon: "none",
duration: 2000,
});
}
})
}, 1000);
},
// 查询支付状态(支付状态 0:未支付,1:已支付,2:支付失败,9:已退款)
getPayStatus_(data1) {
return new Promise((resolve, reject) => {
let params1 = {
TradeNo: data1.out_trade_no
}
queryPayStatus(params1).then(res => {
if (res[0].payStatus == 1) {
resolve(res[0].payStatus);
}else{
resolve(0);
}
})
})
},
// 支付所需参数(后端接口返回)
callApp(data, payParams) {
let params = {
package: "Sign=WXPay", // 固定值
partnerId: "1557237511", // 微信支付商户号
orderId: payParams.tradeNo,
nonceStr: data.nonceStr,
timeStamp: data.timeStamp,
out_trade_no: data.out_trade_no, // 支付订单号
paySign: data.paySign,
code_url: data.code_url,
appid: data.appid,
signType: data.signType,
prepayid: data.prepayid,
};
params = JSON.stringify(params);
let sysInfo = uni.getSystemInfoSync();
if (sysInfo["platform"].indexOf("ios") > -1) {
window.webkit.messageHandlers.goBuyWx.postMessage(params);
} else {
if (window.ytyJsApi) {
window.ytyJsApi.goBuyWx(params);
} else {
uni.showToast({
title: "window.ytyJsApi.goBuyWx() is null",
icon: "none",
});
}
}
},
},
};
</script>
<style lang="scss" scoped>
.xzje {
width: 706rpx;
margin: 0 auto 0;
.bt {
font-weight: 600;
color: #23292e;
font-size: 34rpx;
padding: 30rpx 0;
padding-bottom: 20rpx;
}
.lb {
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
.mx {
width: 48%;
text-align: center;
border-radius: 10rpx;
border: 1px solid rgba(221, 233, 255, 1);
padding-top: 20rpx;
margin-bottom: 30rpx;
background-color: rgba(221, 233, 255, 1);
position: relative;
.one {
color: #2f569e;
font-size: 30rpx;
font-weight: 600;
}
.two {
color: #fa452d;
font-weight: 600;
padding: 15rpx 0;
}
.three {
color: #2f569e;
font-size: 28rpx;
background-color: rgba(47, 86, 158, 0.25);
padding: 10rpx 0;
}
.select {
width: 44rpx;
height: 44rpx;
position: absolute;
bottom: 0;
right: 0;
}
}
}
}
.db {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
height: 100rpx;
display: flex;
justify-content: space-between;
align-items: center;
background-color: #f1f2f4;
box-sizing: border-box;
.lf {
font-size: 36rpx;
font-family: Microsoft YaHei;
// font-weight: 600;
color: #fa452d;
padding-left: 20rpx;
}
.lr {
background-color: #f40;
color: #fff;
padding: 0 50rpx;
height: 100rpx;
font-size: 30rpx;
line-height: 100rpx;
}
}
</style>
uniapp调起微信支付查询订单状态逻辑处理的更多相关文章
- 利用微信支付的订单查询接口可以在APP 中提高支付的可靠性
最近公司有一个应用,用户可以在微信公众号上面下单,也可以在APP 中下单. 当用户在公共号上面下单时,微信支付成功可以返回微信支付单号,但是在APP 中用户微信支付时,个别时候会出现用户已经付款成功, ...
- 怎样调通微信支付及微信发货通知接口(Js API)
怎样调通微信支付及微信发货通知接口(Js API) 微信支付提供了一个支付測试页面,微信支付正式使用须要測通支付.发货通知接口 .告警接口.维权接口.告警接口.维权接口非常easy.支付界面调通也相对 ...
- Android通过Apk插件调起微信支付
App对接微信调起微信支付需要在微信平台注册,鉴别的标识就是App的包名,所以将申请的包名单独打包成一个Apk文件,则在其他的App调起此Apk的时候同样可以起到调用微信支付的功能.这样就实现了调起微 ...
- jsapi 调起微信支付的的踩坑
问题: 公众微信号调起微信支付的时候,有的时候调起支付成功,有的时候调起支付失败.利用抓包工具抓取数据显示授权和调用后台的微信预支付订单接口都成功并且都返回正确的数据.但是调起支付的时候传入的data ...
- 微信支付 统一订单 $order = WxPayApi::unifiedOrder($input); 断点调试
定位至 CODE /** * 将xml转为array * @param string $xml * @throws WxPayException */ public static function I ...
- java版微信支付/查询/撤销
最近公司接入微信刷卡支付,网上根本没见到很直接的教程(可能眼拙),一直摸滚打爬,加班加点才走通,忍不了必须写一写 微信 刷卡支付/查询/撤销... 必须要有公众号然后去申请,申请自己去看文档,这里主要 ...
- 【微信小程序】调起微信支付完整demo
微信小程序调用微信支付接口 https://blog.csdn.net/u012667477/article/details/80940578
- h5调起微信支付
后台需要进行生成签名获取参数. 前台代码: function onBridgeReady(appId,timeStamp,nonceStr,package1,paySign,signType,open ...
- ecmall 支付成功 订单状态没有改变解决办法
问题原因:ecmall版本较低,或者是没有更新支付宝接口导致的.支付宝修改了返回参数,给支付宝增加了一个返回的状态:TRADE_SUCCESS. 解决方案: 需要修改“includes\payment ...
- app微信支付-java服务端接口 支付-查询-退款
个人不怎么看得懂微信的文档,看了很多前辈的写法,终于调通了,在这里做一下记录. 首先来定义各种处理类(微信支付不需要特殊jar包,很多处理需要自己封装,当然也可以自己写完打个jar包) 参数要用jdo ...
随机推荐
- 浅析Winform的可视样式
每一个C#的Winform项目的Main方法里,都有这么一行代码,那么它究竟是用来做什么的呢? Application.EnableVisualStyles(); 从注释来看,这是一行用作设置样式的代 ...
- 2022-11-22学习内容-Client端代码编写-数据删除
1.Client端代码编写 1.1activity_content_write.xml <?xml version="1.0" encoding="utf-8&qu ...
- iOS数据持久化 - CoreData
前言 1 - CoreData 是苹果公司封装的进行数据持久化的框架,首次在 iOS 3.0 版本系统中出现,它允许按照实体-属性-值模型组织数据,并以 XML.二进制文件或者 SQLite 数据文件 ...
- yestoday once more
夏日的光为百叶窗所驯服,褪去了令人刺痛的热烈.yestoday once more~ 耳机里传来那熟悉的旋律,恍惚间仿佛回到了十五年前的那个午后,老式收音机里放着同样的歌曲,对面办公桌旁某个少年正惶恐 ...
- div垂直居中的4种方式方式
一.使用单元格居中 <!DOCTYPE html> <html> <head> <title>测试</title> </head> ...
- CF1548B Integers Have Friends
洛咕 题意: 给定 \(n\) 和一个长度为 \(n\) 的数组 \(a\),求一个最长的区间 \(\left[l,r\right]\),使得存在 \(m\geq 2\) 和 \(k\),对于所有 \ ...
- Win10使用打印机0x0000011b错误 如何处理(没有KB5005565补丁如何解决??)
1.排查问题 win10连接打印机共享错误显示0x0000011b怎么解决?很多用户在更新了windows系统的最新补丁后,突然发现自己打开打印机的时候提示"无法连接到打印机,错误为0x00 ...
- Java基于springboot大学生宿舍寝室考勤人脸识别管理系统
简介 Java基于springboot开发的大学生寝室管理系统宿舍管理系统.学生可以查找寝室和室友信息,可以申请换寝室,申请维修,寝室长提交考勤信息(宿管确认学生考勤信息),补签,查看寝室通报,宿管信 ...
- Chrome 中的 JavaScript 断点设置和调试技巧--转自hanguokai.com
你是怎么调试 JavaScript 程序的?最原始的方法是用 alert() 在页面上打印内容,稍微改进一点的方法是用 console.log() 在 JavaScript 控制台上输出内容.嗯~,用 ...
- egg开发系列--模板语法
在这里列一下 nunjucks 常用的模板内容 首先需要在plugin.js 当中引入 exports.nunjucks = { enable: true, package: 'egg-view-nu ...