这个微信小程序支付demo代码是我用asp写的,微信小程序端加上服务器端用的asp和mdb数据库,下面是代码分享:
<view class="container">
<view class=\'view\'>订单说明:{{paydata.title}}</view>
<view class=\'view inputview\'>
支付金额:<input bindinput="bindKeyInput" type="number" class="input" placeholder="支付金额" value=\'{{paydata.total_fee}}\' />分
</view>
<view class=\'view\'>
<button bindtap="payoff" class=\'btn\' >支付</button>
</view>
</view>
-----------------------
//index.js
//获取应用实例
var app = getApp()
Page({
data: {
paydata: { title: "支付测试", total_fee:1},
userInfo: {}
},
onLoad: function () {
console.log(\'onLoad\');
//判断是否获取到了详细信息
if (!wx.getStorageSync("userInfo")) {
wx.navigateTo({ url: \'/pages/login/index\'})
}
},
// 监听输入
bindKeyInput: function (e) {
console.log(e.detail.value);
this.setData({
\'paydata.total_fee\': e.detail.value
})
},
//
payoff: function(e){
var that = this;
//获取openid
app.wxlogin(function (re) {
console.log(re);
//判断有无openid
if (re) {
that.setData({ \'paydata.openid\':re })
//下单
that.xiadan();
}
});
},
//下单
xiadan: function (){
var that = this;
wx.request({
url: app.globalData.apiurl+\'c=payorder\',
method: \'POST\',
header: { \'content-type\': \'application/x-www-form-urlencoded\' },
data: that.data.paydata,
success: function(res) {
console.log(res);
if(res.data.code=="0"){
//发起支付
that.requestPayment(res.data.data);
}else{
wx.showModal({
title: \'提示\',
content: \'支付发起失败\',
showCancel:false
});
}
}
})
},
//申请支付
requestPayment: function(obj){
console.log(obj);
var that=this;
wx.requestPayment({
\'timeStamp\': obj.timeStamp,
\'nonceStr\': obj.nonceStr,
\'package\': obj.package,
\'signType\': obj.signType,
\'paySign\': obj.paySign,
\'success\':function(res){
wx.showModal({
title: \'提示\',
content: \'成功支付:\' + that.data.paydata.total_fee+\'分\',
showCancel: false
});
},
\'fail\':function(res){
wx.showModal({
title: \'提示\',
content: \'支付失败\',
showCancel: false
});
}
})
},
})
=============================================
互相学习电话微信:18611436777(加微信注明事由)