123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- // pages/chargemoney/chargemoney.js
- let log = require('../../utils/log.js');
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- chargemoney_select: null,
- userInfo: {},
- isLogin: false
- },
- bindMoneyTap(e) {
- let chargemoney_select = e.currentTarget.id;
- this.setData({
- chargemoney_select
- });
- },
- saveMoney(e) {
- //console.log(e);
- let chargemoney_select = e.detail.value;
- this.setData({
- chargemoney_select
- });
- },
- beginChargemoney(e) {
- //console.log(this.data.chargemoney_select);
- log.info('[充值]', '[开始充值流程]');
- let that = this;
- if (this.data.chargemoney_select) {
- wx.showLoading({
- title: '充值中...',
- mask: true
- });
- log.info('[充值]', '[开始微信充值]', '[wx.login请求]');
- wx.login({
- success(res) {
- console.log(res);
- log.info('[充值]', '[开始微信充值]', '[wx.login响应]', res);
- if (res.code) {
- // 发起网络请求
- log.info('[充值]', '[服务端微信充值]', '[请求]', {
- //outTradeNo: new Date().getTime(), //订单号
- totalFee: that.data.chargemoney_select, //钱
- //totalFee:0.01,
- code: res.code,
- userId: that.data.userInfo.userId
- });
- wx.request({
- url: getApp().globalData.postHeadAgreement +'/restapi/wechatpay/dopaychargmoney',
- data: {
- //outTradeNo: new Date().getTime(), //订单号
- totalFee: that.data.chargemoney_select, //钱
- //totalFee:0.01,
- code: res.code,
- userId: that.data.userInfo.userId
- },
- header: {
- 'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
- },
- method: 'POST',
- success(res1) {
- log.info('[充值]', '[服务端微信充值]', '[响应]', res1.data);
- //console.log(res1);
- log.info('[充值]', '[微信支付]', '[请求]', {
- timeStamp: res1.data.timeStamp,
- nonceStr: res1.data.nonceStr,
- package: res1.data.package,
- signType: res1.data.signType,
- paySign: res1.data.paySign
- });
- wx.requestPayment({
- timeStamp: res1.data.timeStamp,
- nonceStr: res1.data.nonceStr,
- package: res1.data.package,
- signType: res1.data.signType,
- paySign: res1.data.paySign,
- success(res2) {
- console.log(res2);
- log.info('[充值]', '[微信支付]', '[响应]', res2);
- log.info('[充值]', '[微信支付回调]', '[请求]', {
- userId: that.data.userInfo.userId,
- rechargeMoney: that.data.chargemoney_select
- //rechargeMoney: 0.01,
- });
- wx.request({
- url: getApp().globalData.postHeadAgreement +'/restapi/pileLog/wechatrechargeback',
- data: {
- userId: that.data.userInfo.userId,
- rechargeMoney: that.data.chargemoney_select
- //rechargeMoney: 0.01,
- },
- method: 'POST',
- success(res3) {
- wx.hideLoading();
- let {
- data
- } = res3;
- log.info('[充值]', '[微信支付回调]', '[响应]', data);
- if (data && data.code == 200) {
- // wx.showModal({
- // showCancel: false,
- // content: '充值成功'
- // });
- let url = `/pages/chargemoneyresult/chargemoneyresult?timeStamp=${res1.data.timeStamp}&money=${that.data.chargemoney_select}`;
- wx.redirectTo({
- url
- })
- log.info('[充值]', '[微信支付回调]', '[成功]');
- } else {
- wx.showModal({
- showCancel: false,
- content: '充值失败'
- });
- log.info('[充值]', '[微信支付回调]', '[失败data null||data.code<>200]', data);
- }
- }
- });
- },
- fail(res3) {
- wx.hideLoading();
- console.log(res3);
- log.info('[充值]', '[微信支付]', '[fail]', res3);
- }
- });
- }
- });
- } else {
- wx.hideLoading();
- console.log('登录失败!' + res.errMsg)
- log.info('[充值]', '[开始微信充值]', '[wx.login响应失败code null]', res);
- }
- }
- })
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function(options) {
- log.info('[充值]', '[页面加载完成]');
- let userInfo = wx.getStorageSync('userInfo');
- let isLogin = wx.getStorageSync('isLogin');
- // 页面显示
- if (userInfo && isLogin) {
- //console.log(userInfo);
- //userInfo.flag = true;
- this.setData({
- userInfo: userInfo,
- isLogin: isLogin
- });
- }
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function() {
- }
- })
|