Bläddra i källkod

等待appid发起jsapi支付前的提交

程志平 5 år sedan
förälder
incheckning
c05364c0b3
4 ändrade filer med 91 tillägg och 98 borttagningar
  1. 1 0
      components/instructions.vue
  2. 4 10
      pages/index/index.vue
  3. 73 77
      pages/recharge/recharge.vue
  4. 13 11
      pages/reshui/reshui.vue

+ 1 - 0
components/instructions.vue

@@ -90,6 +90,7 @@
 				}
 
 				.bot_text {
+					padding: 5rpx;
 					height: 65rpx;
 					line-height: 65rpx;
 					border-radius: 10rpx;

+ 4 - 10
pages/index/index.vue

@@ -38,13 +38,9 @@
 				showLogin: true,
 				appkey: '5AA49F3E4CACA380',
 				sub_appid: '1015730314_1941301045',
-				appid: 'wx2fc3f45732fae5d3', // 获取用户信息
+				appid: 'wxd6f090391d410534', // 获取用户信息
 				ocode: '1015730314', // 获取用户信息
 				app_secret: '58D34C81D82B35179ED896C4362B0FC0', // 获取用户信息
-				// 用于传给后代页面
-				appid_pass: 'wxd6f090391d410534', // 传给后代页面,用于唤起支付
-				ocode_pass: '1609853253', // 传给后代页面,用于唤起支付
-				app_secret_pass: 'eb99fffa11caa585fcf7c97c891a5e1f', // 传给后代页面,用于唤起支付
 				wxcode: '',
 				access_token: '',
 				access_token_for_amount: '', // 获取到应用有效凭证
@@ -104,7 +100,6 @@
 					console.log(e)
 				}
 			},
-
 			/**
 			 * 授权回调
 			 */
@@ -195,11 +190,10 @@
 						this.userinfo.amount = this.amount
 						// 微校参数
 						this.userinfo.appkey = this.appkey
+						this.userinfo.app_secret = this.app_secret
+						this.userinfo.ocode = this.ocode
 						this.userinfo.sub_appid = this.sub_appid
-						this.userinfo.appid = this.appid_pass
-						this.userinfo.app_secret = this.app_secret_pass
-						this.userinfo.ocode = this.ocode_pass
-						this.userinfo.access_token = this.access_token
+						this.userinfo.appid = this.appid
 						// console.log(this.access_token)
 						// 存储用户信息
 						uni.setStorageSync('userinfo_storage_key', this.userinfo)

+ 73 - 77
pages/recharge/recharge.vue

@@ -94,8 +94,7 @@
 
 				if (typeof(res.data.access_token) != 'undefined') {
 					// 获取到应用有效凭证,保存到页面变量中
-					// this.access_token = res.data.access_token
-					this.access_token = this.userinfo.access_token
+					this.access_token = res.data.access_token
 				} else {
 					uni.showToast({
 						title: '获取凭证失败',
@@ -104,6 +103,77 @@
 				}
 			},
 			/**
+			 * 组合地址,发起支付
+			 */
+			async jsapi() {
+				const res = await this.$myRequest({
+					host: 'wecard',
+					url: '/cgi-bin/pay/app/mppay',
+					method: 'POST',
+					header: {
+						'content-type': 'application/json'
+					},
+					data: {
+						'access_token': this.access_token,
+						'sub_appid': this.userinfo.sub_appid,
+						'user_id': this.userinfo.card_number,
+						'order_id': this.order_id = get_order_id(),
+						'amount': this.amount * 100
+					}
+				})
+				
+				console.log(res.data)
+				console.log('access_token:', this.access_token)
+				console.log('sub_appid:', this.userinfo.sub_appid)
+				console.log('card_number:', this.userinfo.card_number)
+				console.log('order_id:', this.order_id)
+				console.log('amount:', this.amount)
+				if (res.data.code == 0) {
+					this.pay_info = res.data.data.pay_info
+					// 发起支付
+					this.pay_amount()
+				} else {
+					uni.showToast({
+						icon: 'none',
+						title: res.data.message,
+						duration: 3000
+					})
+				}
+			},
+			// 调起支付
+			pay_amount() {
+				var OpenMidas = require("@/static/openMidas.js") // 引入小程序目录下的SDK文件
+				
+				// 设置支付配置
+				wx['OpenMidasConfig'] = {
+				    apiCommonConf: {
+				        version: "weixiao"
+				    },
+				    cgiDomain: {
+				        test: "midas.weixiao.qq.com/api",  // 私有化参数联系微卡客服进行获取
+				    },
+				    webDomain: "https://midas.weixiao.qq.com/h5",// 私有化参数联系微卡客服进行获取
+				    sandboxWebDomain: "https://midas.weixiao.qq.com/h5"// 私有化参数联系微卡客服进行获取
+				}
+				
+				var payInfo = this.pay_info; // 请求mppay接口返回的数据
+				var appMetaData = "app=test&version=1.1"; // 自定义回调数据
+				
+				OpenMidas.init("test");
+				OpenMidas.pay(
+				  payInfo,
+				  function(resultCode, innerCode, resultMsg, appMetaData) {
+				    console.log(resultCode); // 支付响应状态码
+				    console.log(innerCode); // 支付响应内部错误码
+				    console.log(resultMsg); // 支付响应说明
+				    console.log(appMetaData); // 自定义回调数据
+				
+				    // todo:处理业务逻辑
+				  },
+				  appMetaData
+				)
+			},
+			/**
 			 * 输入充值金额
 			 */
 			onInput(e) {
@@ -173,80 +243,6 @@
 					})
 				}
 			},
-
-			/**
-			 * 组合地址,发起支付
-			 */
-			async jsapi() {
-				const res = await this.$myRequest({
-					host: 'wecard',
-					url: '/cgi-bin/pay/app/mppay',
-					method: 'POST',
-					header: {
-						'content-type': 'application/json'
-					},
-					data: {
-						'access_token': this.access_token,
-						'sub_appid': this.userinfo.sub_appid,
-						'user_id': this.userinfo.card_number,
-						'order_id': this.order_id = get_order_id(),
-						'amount': this.amount
-					}
-				})
-
-				console.log(res)
-				console.log(this.access_token)
-				console.log(this.userinfo.sub_appid)
-				console.log(this.userinfo.card_number)
-				console.log(this.order_id)
-				console.log(this.amount)
-				if (res.data.code == 0) {
-					this.pay_info = res.data.data.pay_info
-					// 发起支付
-					this.pay_amount()
-				} else {
-					uni.showToast({
-						icon: 'none',
-						title: res.data.message,
-						duration: 3000
-					})
-				}
-			},
-			// 调起支付
-			pay_amount() {
-				var OpenMidas = require("@/static/openMidas.js"); // 引入小程序目录下的SDK文件
-
-				// 设置支付配置
-				OpenMidas['OpenMidasConfig'] = {
-					apiCommonConf: {
-						version: "weixiao"
-					},
-					cgiDomain: {
-						// release: "midas.weixiao.qq.com/api", // 私有化参数联系微卡客服进行获取
-						test: "midas.weixiao.qq.com/api", // 私有化参数联系微卡客服进行获取
-					},
-					webDomain: "https://midas.weixiao.qq.com/h5", // 私有化参数联系微卡客服进行获取
-					sandboxWebDomain: "https://midas.weixiao.qq.com/h5" // 私有化参数联系微卡客服进行获取
-				}
-
-				var payInfo = this.pay_info; // 请求mppay接口返回的数据
-				var appMetaData = "app=test&version=1.1"; // 自定义回调数据
-
-				// OpenMidas.init("release");
-				OpenMidas.init("test");
-				OpenMidas.pay(
-					payInfo,
-					function(resultCode, innerCode, resultMsg, appMetaData) {
-						console.log(resultCode); // 支付响应状态码
-						console.log(innerCode); // 支付响应内部错误码
-						console.log(resultMsg); // 支付响应说明
-						console.log(appMetaData); // 自定义回调数据
-
-						// todo:处理业务逻辑
-					},
-					appMetaData
-				);
-			},
 			/**
 			 * 拨打电话
 			 */
@@ -277,7 +273,7 @@
 		// 小于4位数,前补0
 		// millisecond = millisecond < 1000 ? '00' + millisecond : millisecond
 		// 小于4位数,前补随机数
-		millisecond = millisecond < 1000 ? Math.floor(Math.random() * 999 + 1000) + millisecond : millisecond
+		millisecond = millisecond < 1000 ? Math.floor(Math.random() * 99 + 100) + millisecond : millisecond
 
 		return `${year}${month}${day}${hour}${minute}${second}${millisecond}`
 	}

+ 13 - 11
pages/reshui/reshui.vue

@@ -26,7 +26,7 @@
 						<text class="iconfont icon-qian"></text>
 						<text class="start_mid_txt">¥{{amount}}</text>
 					</view>
-					<view class="start_payamount" @tap="chongzhi_yemian">
+					<view class="start_payamount" @tap="chongzhi_yemian()" hover-class="scan_hover">
 						<text>点击充值</text>
 						<text class="iconfont icon-dayuhao"></text>
 					</view>
@@ -146,7 +146,7 @@
 			}
 
 			this.card_number = this.userinfo.card_number; // 卡号
-			
+
 			// 查询用户信息
 			this.select_user_info()
 		},
@@ -231,12 +231,7 @@
 				});
 
 				// console.log(res, 'select_user_info');
-				if (res.statusCode == 502) {
-					uni.showToast({
-						icon: 'success',
-						title: '服务器网关错误'
-					})
-				} else {
+				if (res.data.info) {
 					// 将JSON字符串转化为JSON对象,取余额
 					let userinfo = res.data.info[0]
 					let amount = userinfo.balance // 余额
@@ -246,14 +241,19 @@
 					if (amount != 0) {
 						this.amount = amount.toFixed(2)
 					}
-					
+
 					if (cnumber == null || cnumber == undefined || cnumber == '') {
 						// 之前未绑定用户信息,现在去绑定用户信息
 						this.send_save_user_info()
 					}
-					
+
 					// 请求选定的月份消费记录
 					this.request_consumption_records()
+				} else {
+					uni.showToast({
+						icon: 'success',
+						title: '获取用户信息失败'
+					})
 				}
 			},
 
@@ -1173,7 +1173,7 @@
 						color: $my-color-primary;
 					}
 				}
-				
+
 				.scan_hover {
 					border-radius: 15rpx;
 					background-color: $my-color-btn-background;
@@ -1224,8 +1224,10 @@
 						justify-content: flex-end;
 						align-items: center;
 						font-size: 38rpx;
+						padding: 10rpx;
 						font-family: Microsoft YaHei-3970(82674968);
 						color: #B3B3B3;
+						border-radius: 10rpx;
 
 						.icon-dayuhao {
 							margin: 0 0 0 20rpx;