首先看页面效果:

<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调起微信支付查询订单状态逻辑处理的更多相关文章

  1. 利用微信支付的订单查询接口可以在APP 中提高支付的可靠性

    最近公司有一个应用,用户可以在微信公众号上面下单,也可以在APP 中下单. 当用户在公共号上面下单时,微信支付成功可以返回微信支付单号,但是在APP 中用户微信支付时,个别时候会出现用户已经付款成功, ...

  2. 怎样调通微信支付及微信发货通知接口(Js API)

    怎样调通微信支付及微信发货通知接口(Js API) 微信支付提供了一个支付測试页面,微信支付正式使用须要測通支付.发货通知接口 .告警接口.维权接口.告警接口.维权接口非常easy.支付界面调通也相对 ...

  3. Android通过Apk插件调起微信支付

    App对接微信调起微信支付需要在微信平台注册,鉴别的标识就是App的包名,所以将申请的包名单独打包成一个Apk文件,则在其他的App调起此Apk的时候同样可以起到调用微信支付的功能.这样就实现了调起微 ...

  4. jsapi 调起微信支付的的踩坑

    问题: 公众微信号调起微信支付的时候,有的时候调起支付成功,有的时候调起支付失败.利用抓包工具抓取数据显示授权和调用后台的微信预支付订单接口都成功并且都返回正确的数据.但是调起支付的时候传入的data ...

  5. 微信支付 统一订单 $order = WxPayApi::unifiedOrder($input); 断点调试

    定位至 CODE /** * 将xml转为array * @param string $xml * @throws WxPayException */ public static function I ...

  6. java版微信支付/查询/撤销

    最近公司接入微信刷卡支付,网上根本没见到很直接的教程(可能眼拙),一直摸滚打爬,加班加点才走通,忍不了必须写一写 微信 刷卡支付/查询/撤销... 必须要有公众号然后去申请,申请自己去看文档,这里主要 ...

  7. 【微信小程序】调起微信支付完整demo

    微信小程序调用微信支付接口 https://blog.csdn.net/u012667477/article/details/80940578

  8. h5调起微信支付

    后台需要进行生成签名获取参数. 前台代码: function onBridgeReady(appId,timeStamp,nonceStr,package1,paySign,signType,open ...

  9. ecmall 支付成功 订单状态没有改变解决办法

    问题原因:ecmall版本较低,或者是没有更新支付宝接口导致的.支付宝修改了返回参数,给支付宝增加了一个返回的状态:TRADE_SUCCESS. 解决方案: 需要修改“includes\payment ...

  10. app微信支付-java服务端接口 支付-查询-退款

    个人不怎么看得懂微信的文档,看了很多前辈的写法,终于调通了,在这里做一下记录. 首先来定义各种处理类(微信支付不需要特殊jar包,很多处理需要自己封装,当然也可以自己写完打个jar包) 参数要用jdo ...

随机推荐

  1. Linux修改主机名hostname

    红帽系: [root@f112 ~]# vi /etc/sysconfig/network # Created by anaconda # 加上一行 HOSTNAME=f111 [root@f112 ...

  2. 测试 SqlServer 数据库连接的简单办法

    1.创建一个文件, 命名为"dba.udl".  #保证后缀是.udl即可     2.双击它:     3.输入数据库地址"xxx.xxx.xxx.xxx,端口号&qu ...

  3. 集群分发xsync xcall kafka启动脚本命令,命令方式安装epel源

    安装epel库源 yum install epel-release -y --nogpgcheck yum install glances 安装开始 建立hosts 白名单 127.0.0.1 loc ...

  4. sublime json格式化

    1. 插件安装 install package-->pretty json 2. 快捷键设置 设置(preference):热键设置 [ {"keys": ["al ...

  5. mybatis-关联查询4-多对多查询

    三张表的关联查询  

  6. R7-3 十六进制字符串转换成十进制非负整数

    R7-3 十六进制字符串转换成十进制非负整数 分数 15 全屏浏览题目 切换布局 作者 颜晖 单位 浙大城市学院 输入一个以#结束的字符串,滤去所有的非十六进制字符(不分大小写),组成一个新的表示十六 ...

  7. 裁员潮下,我月薪3W依旧坚挺

    近几年来产品经理一直是求职市场中的香饽饽: 年薪20w起.没有专业限制.职业天花板高,甚至行业中一直流传着一句话:产品经理是CEO的学前班. 在各种光环的加持下,不少应届生或有转行打算的职场人都将目光 ...

  8. git 初始化新的文件夹

    1.  tar xvf new_project.tar.gz 2. cd  new_project 3. git config --global user.email "user.name@ ...

  9. unity tex2Dlod in vert

    https://forum.unity.com/threads/how-to-sample-a-texture-in-vertex-shader.513816/   GreatWall said: ↑ ...

  10. spring缓存创建

    /** * * <b>创建缓存</b> * <p> * 创建缓存,若已存在直接返回. * <p> * @param cacheName * @retur ...