一、环境准备
VFP SP2 7423 祺佑三层开发框架
HBuilder X
看看实现效果
前端代码
代码语言:javascript复制<template>
<view class="content">
<view>订单号:{{ddh}}</view>
<view>金额:{{je}}</view>
<view>{{status}}</view>
<button @click="getpayaddr" v-show="iscreate">生成支付二维码</button>
<!-- <button @click="closepay">关闭支付二维码</button> -->
<uv-qrcode ref="qrcode" size="300px" :value="qrcodeText"></uv-qrcode>
<view>
<text v-for="(row,index) in list" >订单号{{row.orderno}} 状态:{{row.status}}<button @click="querypay(row.orderno,index)">订单查询</button>n</text>
</view>
</view>
</template>
<script>
import qiyu_ajax from '../../common/qiyu_request.js'
export default {
data() {
return {
iscreate:true,
je:0.01,
ddh:"",
qrcodeText: '',
status:"",
list:[],
timer:{}
}
},
onLoad() {
},
methods: {
querypay:async function(orderno,index){
//this.qrcodeText="";
var url="api/ctl_f2fpay.fsp?proc=queryorder"
var senddata={
ddh:orderno
}
var mydata=await qiyu_ajax.qiyu_kv_request(url,senddata);
console.log(mydata);
if(mydata.errno && mydata.errno!=0){
uni.showToast({
title:mydata.errmsg,
icon:"none"
})
return ;
}
this.list[index].status=mydata.status;
},
getpayaddr:async function(){
//获取的二维码,如果刷过一次,便会进入等待支付状态
//扫码之后,如果用户页面关闭,还是处于等待支付状态
//再次扫,会提示用户订单号重复,无法再行支付了。
var date = new Date(); // 获取当前时间
var timestamp = date.getTime(); // 转换成时间戳
console.log(timestamp); // 打印时间戳
this.ddh=timestamp
var url="api/ctl_f2fpay.fsp?proc=getqrocdebypay"
var senddata={
je:this.je,
ddh:timestamp
}
var mydata=await qiyu_ajax.qiyu_kv_request(url,senddata);
console.log(mydata);
if(mydata.errno && mydata.errno!=0){
uni.showToast({
title:mydata.errmsg,
icon:"none"
})
return ;
}
this.qrcodeText=mydata.payurl;
this.iscreate=false;
this.status="等待支付",
this.list.push({
orderno:timestamp,
status:"等待支付"
})
var _this=this;
this.timer = setInterval(async function() {
// 放入你自己的业务逻辑代码
var url="api/ctl_f2fpay.fsp?proc=queryorder"
var senddata={
ddh:timestamp
}
var mydata=await qiyu_ajax.qiyu_kv_request(url,senddata);
console.log(mydata);
if(mydata.errno && mydata.errno!=0){
uni.showToast({
title:mydata.errmsg,
icon:"none"
})
return ;
}
_this.status=mydata.status;
if(_this.status!='等待支付'){
_this.iscreate=true;
clearInterval(_this.timer);
_this.timer = null;
}
}, 3000);
}
}
}
</script>
<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.logo {
height: 200rpx;
width: 200rpx;
margin-top: 200rpx;
margin-left: auto;
margin-right: auto;
margin-bottom: 50rpx;
}
.text-area {
display: flex;
justify-content: center;
}
.title {
font-size: 36rpx;
color: #8f8f94;
}
</style>
后端VFP代码
代码语言:javascript复制DEFINE CLASS ctl_f2fpay as Session
PROCEDURE queryorder
*--撤消订单
cddh=HttpQueryParams2("ddh")
oPay=Newobject("pay_unionpay","pay_unionpay.prg")
oPay.mch_id=""
oPay.paykey=""
?cddh
cReturn=oPay.Pay_QueryByOrderNo(cddh)
IF ISNULL(cReturn)
ERROR oPay.msg
ENDIF
DO CASE
CASE cReturn="SUCCESS"
cReturn="支付成功"
CASE cReturn="REFUND"
cReturn="转入退款"
CASE cReturn="NOTPAY"
cReturn="等待支付"
CASE cReturn="CLOSED"
cReturn="订单已关闭"
CASE cReturn="REVOKED/REVERSE"
cReturn="订单已撤消"
CASE cReturn="USERPAYING"
cReturn="用户支付中"
CASE cReturn="PAYERROR"
cReturn="支付失败"
ENDCASE
RETURN TEXTMERGE([{"errno":0,"errmsg":"ok","status":"<<cReturn>>"}])
ENDPROC
PROCEDURE getqrocdebypay
nJe=val(HttpQueryParams("je"))
cddh=HttpQueryParams2("ddh")
oPay=Newobject("pay_unionpay","pay_unionpay.prg")
oPay.mch_id=""
oPay.paykey=""
*oPay.terminal_id=""
*--金额是分
nJe=Int(nJe*100)
*lc支付码=Thisform._txt支付码.Value
*--通知URL 目前是没有用,可以发布一个中间层来获取值
*--可以用来上报支付流水倒是挺好的
*--回调URL
lcurl="http://wap.tenpay.com/tenpay.asp"
lcQrstring = oPay.Pay_byQrcode(cddh,nje,lcurl)
IF ISNULL(lcQrstring )
ERROR oPay.msg
ENDIF
?lcQrstring
RETURN TEXTMERGE([{"errno":0,"errmsg":"ok","payurl":"<<lcQrstring>>"}])
ENDPROC
ENDDEFINE
反正VFP做支付也是很EASY的事情。