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 ...
随机推荐
- grep的正则匹配使用方式
grep正则匹配的命令方式如下 $ grep 'pattern1\|pattern2' filename 或 $ grep -E 'pattern1|pattern2' file grep默认是区分大 ...
- 【NPDP专项练习】第六章 市场研究
第六章 市场研究 1.VOC也叫客户心声,指的是. A 选择一个单一的投资组合项目,并保证所有项目都在策略内 B 利用迭代在专家组中形成共识的决策 C 通过人工"商店"引导潜在客户 ...
- Access to the path 'C:\Windows\TEMP\XXX.tmp' is denied.
System.UnauthorizedAccessException: Access to the path 'C:\Windows\TEMP\ASPNETCORE_935a19f1-814f-4b3 ...
- homebrew 安装node 切换node版本
注意:如果之前使用brew install node安装过node,需要先执行brew unlink node来'解绑'node 1.查找可用的node版本 brew search node 2.安装 ...
- C语言 数据编码方式
一.整形数据类型 1.无符号数的编码 无符号数指的是整个机器字长的全部位数均表示数值位. 我们用函数 来进行运算.(B2U是Binary to Unsigned的缩写,长度为w),x代表为0 ...
- nginx文件上传模块 nginx_upload_module
1.编译安装nginx wget https://github.com/fdintino/nginx-upload-module/archive/refs/heads/master.zip PS:原先 ...
- linux查看是实体机还是虚拟机
1.判断虚拟机三种方式 1.dmesg|grep -i hypervisor [root@localhost ~]# dmesg|grep -i hypervisor [ 0.000000] Hype ...
- 2022-04-11内部群每日三题-清辉PMP
1.项目经理从制造商那里收到一个更新信息,说一个必要的设备修理可能会导致他们的可交付成果迟八周时间.项目经理应该怎么做? A.确定关键路径 B.实施沟通管理计划 C.执行假设情景分析 D.对项目进度赶 ...
- Assetbundle 打包加载场景
public class CreateAssetBundle : Editor{ // 打包unity场景文件 [MenuItem("Assets/Build AssetBundle Sce ...
- Ubuntu20.04上用tmux管理新进程
sudo apt-get install tmux 安装tmux tmux new -s session_name 新开一个会话 tmux a -t session_name 查看指定会话 tmux ...