• 微信小程序 功能函数 支付接口


    // 订单生成返回数据,弹出是否支付模态
    wx.showModal({
    title: '微信支付',
    content: '确定支付吗?',
    success: function (res) {
    if (res.confirm) {
    self.pay(bianhao);
    } else if (res.cancel) {
    setTimeout(function () {
    wx.redirectTo({
    url: "/pages/user/dingdan?id=2&&status=1"
    })
    }, 1500)
    }
    }
    })
     
     
     

    // 支付
    pay: function (a) {
     
    var that=this;
    var allAdd = that.data.allAdd
    console.log(allAdd)
    var gongprice = parseInt(this.data.gongprice);
    // console.log(gongprice)
    var user = wx.getStorageSync('user');
     
    var openid = user.openid;
    var phone = user.userphone;
    var member = user.member;
    //----------------------------------------------------------
    var gongpriceChe=that.data.gongpriceChe

    //----------------------------------------------------------
    // 微信支付请求
    self = this;
    wx.showToast({
    title: '请求中.....',
    icon: 'loading',
    duration: 1000
    })
    wx.request({
    url: 'https://www.didu86.com/Clothes-manager-web/payMoney',
    data: {
    openid: openid,
    wx_total_fee: gongprice,
    wx_body: '时装圈子',
    wx_out_trade_no: a
    },
    header: {
    'content-type': 'application/json'
    },
    success: function (res) {
    // console.log(res)
    var dateTime = new Date();
    var timestamp1 = Date.parse(new Date());
    var json = res.data.result;
    // console.log(json)
    // console.log(json.appid)
    var pk = 'prepay_id=' + json.prepay_id;
    // console.log(pk)
    wx.requestPayment({
    'appId': json.appid,
    'timeStamp': json.timeStamp,
    'nonceStr': json.noncestr,
    'package': pk,
    'signType': 'MD5',
    'paySign': json.paySign,
    'success': function (res) {
    // 修改状态
    var myDate = new Date();
    var myN = myDate.getFullYear();
    var myY = myDate.getMonth();
    var myR = myDate.getDate();
    var myh = myDate.getHours();
    var mym = myDate.getMinutes();
    var mys = myDate.getSeconds();
    if (myDate.getHours() < 10) {
    myh = '0' + myDate.getHours(); //补齐
    }
    if (myDate.getMinutes() < 10) {
    mym = '0' + myDate.getMinutes(); //补齐
    }
    if (myDate.getSeconds() < 10) {
    mys = '0' + myDate.getSeconds(); //补齐
    }
    if (myDate.getDate() < 10) {
    myR = '0' + myDate.getDate(); //补齐
    }
    var successTime = '' + myN + '-' + (myY + 1) + '-' + myR + ' ' + myh + ':' + mym + ':' + mys;

    //------------------
    // 余额支付
    if (that.data.switChange) {
    // 余额支付请求
    wx.request({
    url: 'https://www.didu86.com/Clothes-manager-web/updateOrdersBalance',
    data: {
    balance: that.data.discountsDelete,
    serial: that.data.seriarlChe
    },
    success: function (res) {
    console.log(res.data + "余额花费")
    }
    });

    }
    //------------------
    var linallChe = parseFloat(gongpriceChe * that.data.allAdd);
    if (member=='1'){
    linallChe = linallChe
    }else{
    linallChe=0
    }
    var allFan = parseFloat(that.data.discounts) + linallChe;
    console.log(allFan)
    // 微信
    wx.request({
    url: 'https://www.didu86.com/Clothes-manager-web/updateTotalSpend',
    data: {
    id: user.id,
    openid:user.openid,
    userphone: user.userphone,
    balance: allFan,
    totalspend: gongpriceChe
    },
    success: function (res) {
    console.log(res.data + "余额加总消费")
    }
    });
    //------------------
    // 销量
    wx.request({
    url: 'https://www.didu86.com/Clothes-manager-web/updateVolume',
    data: {
    serial: that.data.seriarlChe,
    },
    success: function (res) {
    console.log(res.data+"销量更改")
    }
    });
    //------------------
    // 修改状态
    // time: successTime,
    wx.request({
    url: 'https://www.didu86.com/Clothes-manager-web/updateOrders',
    data: {
    serial: that.data.seriarlChe,
    status:"2",
    btime: successTime
    },
    success: function (res) {
    console.log(res.data + "状态修改")
    }
    });
    wx.showToast({
    title: '支付成功',
    })

    setTimeout(function () {
    wx.switchTab({
    url: "/pages/user/user"
    })
    }, 1500)
     

    },
    'fail': function (res) {
    // console.log(res)
    wx.showToast({
    title: '支付失败',
    })

    },
    })
    },
    })

    },
  • 相关阅读:
    localtime 和 localtime_r 的区别
    mysql1130远程连接没有权限的解决方法
    pthread_create
    GDB Core,gdb 调试大全,core文件调试
    非root用户 如何将cscope安装到指定目录,vim74安装
    linux查看网络链接状况命令netstat
    在Linux系统如何让程序开机时自动启动
    Linux开机启动程序详解
    u盘出现大文件无法复制的解决
    用JSON报的一个错误java.lang.ClassNotFoundException: org.apache.commons.lang.exception.NestableRuntimeExcep
  • 原文地址:https://www.cnblogs.com/dianzan/p/7886143.html
Copyright © 2020-2023  润新知