Browse Source

说明:微信支付水费这边完成,待电费完成

程志平 4 years ago
parent
commit
bef2881526
9 changed files with 434 additions and 569 deletions
  1. 1 2
      App.vue
  2. 5 4
      manifest.json
  3. 67 21
      pages/index/index.vue
  4. 125 268
      pages/jiaofei/jiaofei.vue
  5. 117 81
      pages/recharge/recharge.vue
  6. 32 109
      pages/reshui/reshui.vue
  7. 75 78
      pages/select/select.vue
  8. 9 3
      static/api.js
  9. 3 3
      store/index.js

+ 1 - 2
App.vue

@@ -10,8 +10,7 @@
 			// console.log('App Hide')
 		},
 		globalData: {
-			primaryColor: '#1296db',
-			test: true  // 控制是否是测试环境
+			primaryColor: '#1296db'
 		}
 	}
 </script>

+ 5 - 4
manifest.json

@@ -43,20 +43,21 @@
             /* ios打包配置 */
             "ios" : {},
             /* SDK配置 */
-            "sdkConfigs" : {}
+            "sdkConfigs" : {
+                "payment" : {}
+            }
         }
     },
     /* 快应用特有相关 */
     "quickapp" : {},
     /* 小程序特有相关 */
     "mp-weixin" : {
-        "appid" : "wxd6f090391d410534",
+        "appid" : "wx2fc3f45732fae5d3",
         "setting" : {
             "urlCheck" : false
         },
         "usingComponents" : true,
-        "plugins" : {
-        },
+        "plugins" : {},
         "permission" : {}
     },
     "mp-alipay" : {

+ 67 - 21
pages/index/index.vue

@@ -16,7 +16,7 @@
 			</view>
 		</view>
 		<!--弹窗-->
-		<modal v-if="showPop" title="请输入学号" confirm-text="确定" cancel-text="取消" @cancel="cancelPop"
+		<modal v-if="showPop" title="请输入学号、身份证号" confirm-text="确定" cancel-text="取消" @cancel="cancelPop"
 			@confirm="confirmPop">
 			<view class="">学号:</view>
 			<input type='text' class="stu-number" maxlength="14" placeholder="请输入学号" v-model="stu_number" />
@@ -30,28 +30,48 @@
 	export default {
 		data() {
 			return {
-				appId: 'wxd6f090391d410534',
-				ocode: '1015730314',
-				appSecret: '58D34C81D82B35179ED896C4362B0FC0',
 				code: '',
-				amount: 0.00,
 				showPop: false, //弹窗
-				stu_number: '20210210140101',
-				id_card: '88888888'
-				// stu_number: '',
-				// id_card: ''
+				// stu_number: '20210210140101',
+				// id_card: '88888888',
+				stu_number: '',
+				id_card: '',
+				ceshi: 'code'
 			}
 		},
 		onLoad() {
+			// 是否是测试环境,查询数据接口中参数的值决定,方便以后测试
+			
+			
 			this.getCode()
 		},
 		methods: {
-			//弹窗
+			/**
+			 * 控制环境,test为true测试环境,false则是正式环境
+			 */
+			async isTestEnvironment() {
+				const res = await this.$myRequest({
+					host: this.ceshi,
+					url: '/',
+					method: 'POST',
+					header: {
+						'content-type': 'application/x-www-form-urlencoded'
+					}
+				})
+			
+				// console.log(res.data.mess);
+				// if (res.data.mess == '绑定成功') {
+				// 	this.$store.state.test = res.data.test
+				// }
+			},
+			/**
+			 * 弹窗
+			 */
 			confirmPop() { //确认
 				if (this.stu_number.length == 14 && this.id_card.length == 18) {
 					this.showPop = false
 					// 获得code
-					this.getCode()
+					this.getCode('confirm')
 				} else {
 					uni.showToast({
 						title: '学号长度错误 或 身份证号 长度错误!',
@@ -64,14 +84,16 @@
 				// this.showPop = false
 			},
 			// 获得code
-			getCode() {
-				wx.login({
+			getCode(param) {
+				uni.login({
 					success: (res) => {
-						// console.log(res);
+						// console.log('index', res);
 						if (res.code) {
-							this.code = res.code
 							// 请求服务器,获得openid
-							this.getOpenId()
+							if (param == 'confirm')
+								this.getOpenId(res.code)
+							else
+								this.selectUser(res.code)
 						} else {
 							uni.showToast({
 								title: res.errMsg,
@@ -84,16 +106,16 @@
 			/**
 			 * 请求服务器,获得openid
 			 */
-			async getOpenId() {
+			async getOpenId(code) {
 				const res = await this.$myRequest({
-					host: 'code',
+					host: this.ceshi,
 					url: '/HotWaters/wpopenid.action',
 					method: 'POST',
 					header: {
 						'content-type': 'application/x-www-form-urlencoded'
 					},
 					data: {
-						code: this.code,
+						code: code,
 						stu_number: this.stu_number,
 						id_card: this.id_card
 					}
@@ -102,10 +124,34 @@
 				// console.log(res.data.mess);
 				if (res.data.mess == '绑定成功') {
 					uni.showToast({
-						title: '首次绑定成功!',
+						title: '用户绑定成功!',
 						icon: 'success'
 					});
-				} else if (res.data.mess == '未查询到用户信息') {
+				} else {
+					uni.showToast({
+						title: res.data.mess,
+						icon: 'success'
+					});
+				}
+			},
+			/**
+			 * 查询用户
+			 */
+			async selectUser(code) {
+				const res = await this.$myRequest({
+					host: this.ceshi,
+					url: '/HotWaters/wpget_stu.action',
+					method: 'POST',
+					header: {
+						'content-type': 'application/x-www-form-urlencoded'
+					},
+					data: {
+						code: code
+					}
+				})
+
+				// console.log(res);
+				if (res.data.mess == '未查询到用户信息') {
 					this.showPop = true
 				}
 			}

+ 125 - 268
pages/jiaofei/jiaofei.vue

@@ -47,7 +47,7 @@
 			</view>
 		</view>
 		<view class="show-item">
-			<input class="input-money" maxlength="4" placeholder="请输入金额(1-200)" v-model:value="inputMoney"
+			<input type="number" class="input-money" maxlength="4" placeholder="请输入金额(1-200)" v-model:value="inputMoney"
 				placeholder-class="#B3B3B3" @input="onInput" @blur="onBlur" />
 		</view>
 		<view class="submit-item">
@@ -79,55 +79,19 @@
 				sub_appid: '', //商户号
 				pay_info: '',
 				xiaofei_items: '', // 消费记录
-				test: getApp().globalData.test
+				ceshi: 'code',
+				dorm_number: '',
+				compus: '',
+				test: this.$store.state.test
 			}
 		},
-		onLoad: function(options) {
-			let item_tmp = decodeURIComponent(options.item)
-			//将字符串解密转换成对象
-			let item = JSON.parse(item_tmp);
+		onLoad: function() {
+			// 初始化参数
+			this.$store.state.building.roomSelect = '';
+			this.$store.state.building.add_class = 0;
+			this.$store.state.building.dom = '';
 
-			// 请求选定的月份消费记录
-			// this.request_consumption_records()
-			try {
-				// 获取存储的用户数据
-				const value = uni.getStorageSync('userinfo_storage_key')
-				// console.log(item)
-				if (item_tmp == '{}') { // 如果没有用户信息,返回首页
-					uni.redirectTo({
-						url: '../index/index'
-					})
-					return
-				}
-				// 如果是选择宿舍号返回
-				if (options.o == 'index') {
-					this.$store.state.building.roomSelect = '';
-					this.$store.state.building.add_class = 0;
-					this.$store.state.building.dom = '';
-
-					this.userinfo = item;
-					// 更新存储的用户信息
-					uni.setStorageSync('userinfo_storage_key', this.userinfo)
-					this.roomSelect = this.campus + this.dom
-				} else if (JSON.stringify(value) !== '{}') {
-					this.userinfo = value;
-				}
-				this.campus = this.userinfo.campus
-				this.dom = this.userinfo.dorm_number
-				this.sub_appid = this.userinfo.sub_appid
-
-				this.add_class = 1
-			} catch (e) {
-				console.log(e)
-			}
-
-			//将缓存中的卡号进行获取
-			this.card_number = this.userinfo.card_number
-
-			if (this.$store.state.hasUserInfo == false) {
-				// 获取应用有效凭证
-				this.get_valid_credentials()
-			}
+			this.getCode()
 		},
 		onShow() {
 			if (this.$store.state.building.roomSelect != '') {
@@ -143,207 +107,109 @@
 		},
 		methods: {
 			/**
-			 * 取得电费额度
+			 * 获得code
 			 */
-			async getDianLiang() {
-				let res;
-				if (this.test) { // 测试环境
-					res = await this.$myRequest({
-						host: 'ceshi',
-						url: 'http://tdqdjt.natappfree.cc/HotWaters/buildoverElec.action',
-						method: 'POST',
-						header: {
-							'content-type': 'application/x-www-form-urlencoded'
-						},
-						data: {
-							'roomSelect': this.roomSelect
-						}
-					})
-				} else {
-					res = await this.$myRequest({
-						host: 'code',
-						url: '/HotWater/buildoverElec.action',
-						method: 'POST',
-						header: {
-							'content-type': 'application/x-www-form-urlencoded'
-						},
-						data: {
-							'roomSelect': this.roomSelect
+			getCode(param) {
+				uni.login({
+					success: (res) => {
+						console.log('jiaofei', res);
+						if (res.code) {
+							this.code = res.code
+							// 请求服务器,获得openid
+							if (param == 'comfirm')
+								this.jsapi()
+							else
+								this.getOpenId()
+						} else {
+							uni.showToast({
+								title: res.errMsg,
+								icon: 'none'
+							});
 						}
-					})
-				}
-				console.log(res.data.amount);
-				if (res.mess != '请选择房间号!') {
-					setTimeout(() => {
-						this.remainElec = res.data.amount.toFixed(2)
-					}, 300);
-				} else {
-					uni.showToast({
-						title: '获取电量失败!',
-						duration: 2000
-					})
-				}
-			},
-			/**
-			 * 获取应用有效凭证
-			 */
-			async get_valid_credentials() {
-				const value = uni.getStorageSync('userinfo_storage_key')
-				// console.log(value)
-				const res = await this.$myRequest({
-					host: 'wecard',
-					url: '/cgi-bin/oauth2/token',
-					method: 'POST',
-					header: {
-						'content-type': 'application/json'
-					},
-					data: {
-						'app_key': value.appkey,
-						'app_secret': value.app_secret,
-						'grant_type': 'client_credentials',
-						'scope': 'base',
-						'ocode': value.ocode
 					}
-				});
-
-				if (typeof(res.data.access_token) != 'undefined') {
-					// 获取到应用有效凭证,保存到页面变量中
-					this.access_token = res.data.access_token
-				} else {
-					uni.showToast({
-						title: '获取凭证失败',
-						duration: 2000
-					})
-				}
-
-				// 查询用户信息
-				this.select_user_info()
+				})
 			},
-
 			/**
-			 * 查询用户信息
+			 * 请求服务器,获得openid
 			 */
-			async select_user_info() {
+			async getOpenId() {
 				const res = await this.$myRequest({
-					host: 'code',
-					url: '/HotWater/userget_stu.action',
+					host: this.ceshi,
+					url: '/HotWaters/wpget_stu.action',
 					method: 'POST',
 					header: {
 						'content-type': 'application/x-www-form-urlencoded'
 					},
 					data: {
-						card_number: this.userinfo.card_number
+						code: this.code
 					}
-				});
-
-				// console.log(res, 'select_user_info');
-				if (res.data.info) {
-					let cnumber = this.userinfo.card_number
-
-					if (cnumber == null || cnumber == undefined || cnumber == '') {
-						// 之前未绑定用户信息,现在去绑定用户信息
-						this.send_save_user_info()
-					}
-				} else {
-					uni.showToast({
-						icon: 'success',
-						title: '获取用户信息失败'
-					})
-				}
-			},
+				})
 
-			/**
-			 * 请求选定的月份消费记录
-			 */
-			async request_consumption_records() {
-				const userinfo = uni.getStorageInfoSync('userinfo_storage_key')
-				this.card_number = userinfo.card_number
+				// console.log(res);
+				if (res.data.mess == '返回成功') {
+					this.$store.state.stu_number = res.data.info[0].stu_number
+					this.amount = res.data.info[0].balance
+					// 宿舍号
+					this.dorm_number = res.data.info[0].build + res.data.info[0].dom
+					// 校区
+					this.compus = res.data.info[0].campus
+					// 填充校区楼栋号
+					this.roomSelect = this.compus + this.dorm_number.split('栋')[1]
+					this.$store.state.building.roomSelect = this.roomSelect
+					this.add_class = 1
+
+					// 请求选定的月份消费记录
+					this.getDianLiang()
 
-				if (this.card_number != '') {
-					this.xiaofei_items = []
-					const res = await this.$myRequest({
-						host: 'code',
-						url: '/HotWater/wxpayqueryConsume.action',
-						method: 'POST',
-						header: {
-							'content-type': 'application/x-www-form-urlencoded'
-						},
-						data: {
-							card_number: this.card_number,
-							begin_time: this.date
-						}
+				} else if (res.data.mess == '未查询到用户信息') {
+					uni.redirectTo({
+						url: '../index/index'
 					});
-
-					// console.log(res.data.mess, 'request_consumption_records');
-					if (typeof(res.data.mess) != 'undefined') {
-						let items = res.data.mess
-						// 按时间倒序排列
-						// items.sort((a, b) => {
-						// 	return a.begin_time < b.begin_time ? 1 : -1;
-						// })
-						for (var i = 0; i < items.length; i++) {
-							// 过滤掉为0的记录,只显示消费大于0的记录
-							// if (items[i].use_amount > 0.00) {
-							this.xiaofei_items.push(items[i])
-							// }
-						}
-					} else {
-						uni.showToast({
-							icon: 'success',
-							title: '该月无消费记录'
-						})
-					}
-				} else {
-					uni.showToast({
-						icon: 'success',
-						title: '用户卡号为空'
-					})
 				}
 			},
-
 			/**
-			 * 绑定用户信息
+			 * 取得电费额度
 			 */
-			async send_save_user_info() {
-				const res = await this.$myRequest({
+			async getDianLiang() {
+				let res;
+				res = await this.$myRequest({
 					host: 'code',
-					url: '/HotWater/userstu_info.action',
+					url: '/HotWaters/buildoverElec.action',
 					method: 'POST',
 					header: {
 						'content-type': 'application/x-www-form-urlencoded'
 					},
 					data: {
-						user: JSON.stringify(this.userinfo)
+						'roomSelect': this.roomSelect
 					}
-				});
+				})
 
-				// console.log('send_save_user_info:', res)
-				let error = res.data.erro;
-				if (error == '未获取到数据!') {
-					uni.showToast({
-						title: '绑定用户失败',
-						duration: 2000
-					})
+				// console.log(res);
+				if (res.data.mess == '0') {
+					setTimeout(() => {
+						this.remainElec = res.data.amount.toFixed(2)
+					}, 30);
 				} else {
-					uni.showToast({
-						icon: 'success',
-						title: '绑定用户成功',
-						duration: 2000
-					})
+					this.remainElec = 0.00.toFixed(2)
+					// uni.showToast({
+					// 	// 未获取到户号
+					// 	title: res.data.mess,
+					// 	duration: 2000
+					// })
 				}
 			},
 
 			//跳转到选择页面
 			navigateToSelect() {
 				uni.navigateTo({
-					url: '../select/select?roomSelect=' + this.roomSelect,
+					url: '../select/select',
 				});
 			},
 
 			//跳转到台账页面
 			navigateToShow(e) {
 				uni.navigateTo({
-					url: '../show/show?card_number=' + this.card_number,
+					url: '../show/show',
 				});
 			},
 
@@ -354,12 +220,15 @@
 
 				this.confirm_room('add_money')
 			},
-
+			/**
+			 * 确认宿舍号
+			 * @param {Object} op
+			 */
 			confirm_room(op) {
 				// 检查房间号
 				if (this.roomSelect == '') {
 					uni.showToast({
-						title: '请选择房间号',
+						title: '请选择宿舍号',
 						icon: 'success'
 					})
 					return
@@ -377,7 +246,7 @@
 
 					if (isNaN(this.inputMoney)) {
 						uni.showToast({
-							title: '请输入数值',
+							title: '请输入正确金额',
 							duration: 2000
 						})
 						return
@@ -398,6 +267,7 @@
 				// 确认充值对话框
 				this.confirm_dialog()
 			},
+
 			// 确认充值对话框
 			confirm_dialog() {
 				uni.showModal({
@@ -405,9 +275,10 @@
 					title: '确定充值' + this.addMoney + '元',
 					success: (res) => {
 						if (res.confirm) {
-							this.jsapi()
+							// 获取code
+							this.getCode('comfirm')
 						} else if (res.cancel) {
-							console.log('用户点击取消');
+							// console.log('用户点击取消');
 						}
 					}
 				})
@@ -417,73 +288,59 @@
 				// console.log(e)
 				this.confirm_room('input_money')
 			},
-
-			//准备支付
+			/**
+			 * 请求服务器,获取支付参数,并支付
+			 */
 			async jsapi() {
 				const res = await this.$myRequest({
-					host: 'wecard',
-					url: "/cgi-bin/pay/app/mppay",
+					host: this.ceshi,
+					url: '/HotWaters/wpPay.action',
 					method: 'POST',
 					header: {
-						'content-type': 'application/json'
+						'content-type': 'application/x-www-form-urlencoded'
 					},
 					data: {
-						'access_token': this.access_token,
-						'sub_appid': this.sub_appid,
-						'user_id': this.card_number,
-						"order_id": this.order_id = this.$getOrderId('dianfei'),
-						"amount": this.addMoney * 100,
-						'order_type': 1,
-						'callback_url': ''
+						code: this.code,
+						num: this.amount,
+						ip: this.IP
 					}
 				})
-
-				if (res.data.code == 0) {
-					this.pay_info = res.data.data.pay_info
-					// 发起支付
-					this.pay_amount()
-				} else {
+				console.log(res);
+				if (res.data.pay == 'error') {
 					uni.showToast({
-						icon: 'none',
-						title: res.data.message,
+						title: '未获得支付参数',
+						icon: 'success',
 						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" // 私有化参数联系微卡客服进行获取
+					});
+				} else {
+					wx.requestPayment({
+						timeStamp: res.data.pay.timeStamp,
+						nonceStr: res.data.pay.nonceStr,
+						package: 'prepay_id=' + res.data.pay.prepay_id,
+						signType: res.data.pay.signType,
+						paySign: res.data.pay.paySign,
+						success: res => {
+							if (res.errMsg == 'requestPayment:ok') {
+								uni.showToast({
+									title: '支付成功',
+									icon: 'success'
+								});
+							}
+						},
+						fail: (res) => {
+							if (res.errMsg == 'requestPayment:fail cancel') {
+								uni.showToast({
+									title: '取消支付',
+									icon: 'success',
+									duration: 2000
+								});
+							}
+						},
+						complete: (res) => {
+							console.log(res);
+						}
+					});
 				}
-
-				var payInfo = this.pay_info; // 请求mppay接口返回的数据
-				// console.log(payInfo)
-				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
-				);
 			},
 			/**
 			 * 输入充值金额

+ 117 - 81
pages/recharge/recharge.vue

@@ -37,85 +37,113 @@
 			return {
 				amount: 10, // 金额
 				phone_number: '13645689854', // 客户热线电话
-				userinfo: '', // 用户信息
-				order_id: '', // 订单号
-				pay_info: '', // 支付参数。将此参数透传给支付 SDK 发起支付
-				access_token: '',
-				appid: '',
-				card_number: '',
-				mchid: '',
-				user_name: '',
-				payer_openid: '',
-				test: getApp().globalData.test // 获取全局变量,控制是否是测试环境
+				IP: '',
+				code: '',
+				ceshi: 'code',
+				test: this.$store.state.test
 			};
 		},
-		onLoad(options) {
-			try {
-				// 获取存储的用户数据
-				const value = uni.getStorageSync('userinfo_storage_key')
-				let item = decodeURIComponent(options.item)
-				// console.log(item)
-				if (item === '{}' && value == '') { // 如果没有用户信息,返回首页
-					uni.redirectTo({
-						url: '../index/index'
-					});
-					return;
-				}
-				// 先用传过来的用户信息
-				if (item != '') {
-					// 处理JSON字符串
-					// this.userinfo = item.replace(/"/g, "'");
-					this.userinfo = JSON.parse(item)
-					// 更新存储的用户信息
-					uni.setStorageSync('userinfo_storage_key', this.userinfo)
-				} else if (JSON.stringify(value) !== '{}') {
-					// 处理JSON字符串
-					// this.userinfo = value.replace(/"/g, "'");
-					this.userinfo = value;
-				}
-			} catch (e) {
-				console.log(e)
-			}
-
-			if (this.test) //测试环境
+		onLoad() {
+			if (this.test) {
 				this.amount = 0.01
-
-			this.mchid = this.userinfo.ocode
-			this.card_number = this.userinfo.card_number
-			this.payer_openid = this.userinfo.weixiao_stu_id
-			this.appid = this.userinfo.appid
-			this.user_name = this.userinfo.name
+			}
 		},
 		methods: {
 			/**
-			 * 组合地址,发起支付
+			 * 获得code
+			 */
+			getCode() {
+				uni.login({
+					success: (res) => {
+						// console.log('recharge', res);
+						if (res.code) {
+							this.code = res.code
+							// 获取IP
+							this.getIP()
+						} else {
+							uni.showToast({
+								title: res.errMsg,
+								icon: 'none'
+							});
+						}
+					}
+				})
+			},
+			/**
+			 * 获取IP
+			 */
+			async getIP() {
+				const res = await this.$myRequest({
+					host: 'ip',
+					url: '/',
+					method: 'POST'
+				})
+
+				if (res) {
+					// console.log(res);
+					const reg = /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/;
+					let ip = reg.exec(res.data);
+					this.IP = ip[0]
+
+					// 组合地址,发起支付
+					this.jsapi()
+				}
+			},
+			/**
+			 * 请求服务器,获取支付参数,并支付
 			 */
 			async jsapi() {
 				const res = await this.$myRequest({
-					host: 'wexin',
-					url: '/v3/pay/transactions/jsapi',
+					host: this.ceshi,
+					url: '/HotWaters/wpPay.action',
 					method: 'POST',
 					header: {
-						'content-type': 'application/json'
+						'content-type': 'application/x-www-form-urlencoded'
 					},
 					data: {
-						"mchid": this.mchid,
-						"out_trade_no": this.order_id = this.$getOrderId('shuifei'),
-						"appid": this.appid,
-						"description": "热水洗浴充值",
-						"notify_url": this.$code_base_url + '/HotWater/wxpayrecharge.action',
-						"amount": {
-							"total": this.amount * 100,
-							"currency": "CNY"
-						},
-						"payer": {
-							"openid": this.payer_openid
-						}
+						code: this.code,
+						num: this.amount,
+						ip: this.IP
 					}
 				})
-				
-				console.log(res);
-				
+				// console.log(res);
+				if (res.data.pay == 'error') {
+					uni.showToast({
+						title: '未获得支付参数',
+						icon: 'success',
+						duration: 3000
+					});
+				} else {
+					wx.requestPayment({
+						timeStamp: res.data.pay.timeStamp,
+						nonceStr: res.data.pay.nonceStr,
+						package: 'prepay_id=' + res.data.pay.prepay_id,
+						signType: res.data.pay.signType,
+						paySign: res.data.pay.paySign,
+						success: (res) => {
+							if (res.errMsg == 'requestPayment:ok') {
+								this.$store.state.payInfo.from = 'reshui_pay'
+								this.$store.state.payInfo.resultMsg = '支付成功'
+								this.$store.state.reshui_amount = this.amount
+								uni.navigateBack({
+									delta: 1
+								})
+							}
+						},
+						fail: (res) => {
+							if (res.errMsg == 'requestPayment:fail cancel') {
+								uni.showToast({
+									title: '支付已取消',
+									icon: 'success',
+									duration: 2000
+								});
+							}
+						},
+						complete: (res) => {
+							// console.log(res);
+						}
+					});
+				}
 			},
 			/**
 			 * 输入充值金额
@@ -170,6 +198,14 @@
 			 * 调用接口实现充值功能
 			 */
 			chongzhi() {
+				if (isNaN(this.amount)) {
+					uni.showToast({
+						title: '请输入正确金额',
+						duration: 2000
+					})
+					return
+				}
+				// 测试环境下执行
 				if (this.test) { // 测试环境
 					uni.showModal({
 						title: '提示',
@@ -178,8 +214,8 @@
 						confirmText: '充值',
 						success: (res) => {
 							if (res.confirm) {
-								// 组合地址,发起支付
-								this.jsapi()
+								// 获取code
+								this.getCode()
 							} else if (res.cancel) {
 								return
 							}
@@ -197,22 +233,22 @@
 						duration: 3000
 					})
 					return
-				} else {
-					uni.showModal({
-						title: '提示',
-						content: '您选择了充值:¥' + this.amount + ' 元',
-						cancelText: '算了',
-						confirmText: '充值',
-						success: (res) => {
-							if (res.confirm) {
-								// 组合地址,发起支付
-								this.jsapi()
-							} else if (res.cancel) {
-								return
-							}
-						}
-					})
 				}
+				// 确认
+				uni.showModal({
+					title: '提示',
+					content: '您选择了充值:¥' + this.amount + ' 元',
+					cancelText: '算了',
+					confirmText: '充值',
+					success: (res) => {
+						if (res.confirm) {
+							// 获取code
+							this.getCode()
+						} else if (res.cancel) {
+							return
+						}
+					}
+				})
 			},
 			/**
 			 * 拨打电话

+ 32 - 109
pages/reshui/reshui.vue

@@ -110,14 +110,12 @@
 				start_code: '',
 				// start_code: '3459A8C660F1C284E41003E80000120000',
 				xiaofei_items: [], // 消费记录
-				userinfo: '',
-				card_number: '',
-				user_name: '',
 				use_amount: 0.0.toFixed(2), // 结算金额
 				amount: 0.0.toFixed(2), // 余额
 				dorm_number: '', // 宿舍号
 				compus: '', // 校区
-				code: ''
+				code: '',
+				ceshi: 'code'
 			}
 		},
 		onLoad() {
@@ -125,18 +123,17 @@
 		},
 		onShow() {
 			if (this.$store.state.payInfo.from == 'reshui_pay') {
-				if (this.$store.state.payInfo.resultCode == 0) {
-					uni.showToast({
-						title: this.$store.state.payInfo.resultMsg,
-						icon: 'success'
-					})
-				} else {
-					uni.showToast({
-						title: this.$store.state.payInfo.resultMsg,
-						icon: 'success'
-					})
-				}
+				uni.showToast({
+					title: this.$store.state.payInfo.resultMsg,
+					icon: 'success'
+				})
+				
+				this.$store.state.payInfo.resultMsg = ''
 				this.$store.state.payInfo.from = ''
+				
+				// this.amount = this.$store.state.reshui_amount + this.amount
+				// 重新调用一次,刷新金额
+				this.getCode()
 			}
 		},
 		methods: {
@@ -144,9 +141,9 @@
 			 * 获得code
 			 */
 			getCode() {
-				wx.login({
+				uni.login({
 					success: (res) => {
-						// console.log(res);
+						// console.log('reshui', res);
 						if (res.code) {
 							this.code = res.code
 							// 请求服务器,获得openid
@@ -165,7 +162,7 @@
 			 */
 			async getOpenId() {
 				const res = await this.$myRequest({
-					host: 'code',
+					host: this.ceshi,
 					url: '/HotWaters/wpget_stu.action',
 					method: 'POST',
 					header: {
@@ -179,13 +176,15 @@
 				// console.log(res);
 				if (res.data.mess == '返回成功') {
 					this.$store.state.stu_number = res.data.info[0].stu_number
-					this.amount = res.data.info[0].balance
+					if (res.data.info[0].balance > 0)
+						this.$store.state.reshui_amount = res.data.info[0].balance
+					this.amount = this.$store.state.reshui_amount
 					this.dorm_number = res.data.info[0].build + res.data.info[0].dom
 					this.compus = res.data.info[0].campus
 
 					// 请求选定的月份消费记录
 					this.request_consumption_records()
-					
+
 				} else if (res.data.mess == '未查询到用户信息') {
 					uni.redirectTo({
 						url: '../index/index'
@@ -216,7 +215,7 @@
 				if (this.$store.state.stu_number != '') {
 					this.xiaofei_items = []
 					const res = await this.$myRequest({
-						host: 'code',
+						host: this.ceshi,
 						url: '/HotWaters/wpqueryConsume.action',
 						method: 'POST',
 						header: {
@@ -248,82 +247,6 @@
 					})
 				}
 			},
-
-			/**
-			 * 查询用户信息
-			 */
-			async select_user_info() {
-				const res = await this.$myRequest({
-					host: 'code',
-					url: '/HotWater/userget_stu.action',
-					method: 'POST',
-					header: {
-						'content-type': 'application/x-www-form-urlencoded'
-					},
-					data: {
-						card_number: this.userinfo.card_number
-					}
-				});
-				// console.log(res, 'select_user_info');
-				if (res.data.info) {
-					// 将JSON字符串转化为JSON对象,取余额
-					let userinfo = res.data.info[0]
-					let amount = userinfo.balance // 余额
-					let cnumber = this.userinfo.card_number
-					this.user_name = userinfo.user_name;
-					this.dorm_number = userinfo.dom // 宿舍号
-					if (amount != 0) {
-						this.amount = amount
-					}
-
-					if (cnumber == null || cnumber == undefined || cnumber == '') {
-						// 之前未绑定用户信息,现在去绑定用户信息
-						this.send_save_user_info()
-					}
-
-					this.$store.state.hasUserInfo == true
-					// 请求选定的月份消费记录
-					this.request_consumption_records()
-				} else {
-					uni.showToast({
-						icon: 'success',
-						title: '获取用户信息失败'
-					})
-				}
-			},
-
-			/**
-			 * 绑定用户信息
-			 */
-			async send_save_user_info() {
-				const res = await this.$myRequest({
-					host: 'code',
-					url: '/HotWater/userstu_info.action',
-					method: 'POST',
-					header: {
-						'content-type': 'application/x-www-form-urlencoded'
-					},
-					data: {
-						user: JSON.stringify(this.userinfo)
-					}
-				});
-
-				// console.log('send_save_user_info:', res)
-				let error = res.data.erro;
-				if (error == '未获取到数据!') {
-					uni.showToast({
-						title: '绑定用户失败',
-						duration: 2000
-					})
-				} else {
-					uni.showToast({
-						icon: 'success',
-						title: '绑定用户成功',
-						duration: 2000
-					})
-				}
-			},
-
 			/**
 			 * 控制进度条显示
 			 * @param {Object} active_value
@@ -347,6 +270,12 @@
 							success: (res) => {
 								if (res.confirm) {
 									this.isChecked = true
+									
+									// 开始连接匹配的蓝牙设备
+									// setTimeout(async () => {
+										// 请求获取设备启动码
+									this.request_device_start_code()
+									// }, 1000)
 								} else if (res.cancel) {
 									setTimeout(() => {
 										this.isChecked = false
@@ -354,11 +283,6 @@
 								}
 							}
 						})
-						// 开始连接匹配的蓝牙设备
-						setTimeout(async () => {
-							// 请求获取设备启动码
-							await this.request_device_start_code()
-						}, 3000)
 					} else {
 						uni.showToast({
 							icon: 'none',
@@ -407,7 +331,7 @@
 			chongzhi_yemian() {
 				//在起始页面跳转到recharge.vue页面并传递参数
 				uni.navigateTo({
-					url: '../recharge/recharge?item=' + encodeURIComponent(JSON.stringify(this.userinfo))
+					url: '../recharge/recharge'
 				});
 			},
 
@@ -1060,16 +984,15 @@
 			async request_device_start_code() {
 				const res = await this.$myRequest({
 					host: 'code',
-					url: '/HotWater/wxpaystart.action',
+					url: '/HotWaters/wpstart.action',
 					data: {
 						collect_code: this.byte35,
-						card_number: this.card_number,
-						user_name: this.user_name
+						stu_number: this.$store.state.stu_number
 					}
 				})
 
-				// console.log(res.data.start_code)
-				if (res.data.start_code != '') {
+				// console.log(res)
+				if (res.data.start_code != 'undefined' && res.data.start_code != '') {
 					this.start_code = res.data.start_code
 					this.send('start')
 				} else {
@@ -1087,7 +1010,7 @@
 			async request_pay() {
 				const res = await this.$myRequest({
 					host: 'code',
-					url: '/HotWater/wxpayconsume.action',
+					url: '/HotWaters/wpconsume.action',
 					data: {
 						collect_code: this.byte35.substring(2)
 					}

+ 75 - 78
pages/select/select.vue

@@ -84,16 +84,14 @@
 				dis_num2: 1,
 				dis_num3: 1,
 				dis_num4: 1,
-				options: '',
 				// dis_num5: 1,
 				allData: [], //所有数据
 				storage: {}, //存放选择数据
-				test: getApp().globalData.test
+				ceshi: 'code',
+				test: this.$store.state.test
 			}
 		},
-		onLoad(options) {
-			// console.log(options)
-			this.options = options
+		onLoad() {
 			// 请求校区、楼栋、层好、宿舍号等数据
 			this.requestAllData()
 		},
@@ -107,85 +105,84 @@
 					title: '数据加载中……',
 					mask: true
 				});
-				let res;
-				if (this.test) {
-					res = await this.$myRequest({
-						host: 'ceshi',
-						url: 'http://3ft7hs.natappfree.cc',
-						method: 'POST',
-						header: {
-							'content-type': 'application/json'
-						}
-					})
-				} else {
-					res = await this.$myRequest({
-						host: 'code',
-						url: '/HotWater/buildelec.action',
-						method: 'POST',
-						header: {
-							'content-type': 'application/json'
-						}
-					})
-				}
-				if (typeof(res.data) != 'undefined') {
-					this.allData = res
-					this.nschool = res.data.length
+				const res = await this.$myRequest({
+					host: this.ceshi,
+					url: '/HotWaters/buildelec.action',
+					method: 'POST',
+					header: {
+						'content-type': 'application/json'
+					}
+				})
+				// console.log(res.data.data);
+				let rooms = JSON.parse('[{"data":' + res.data.data + '}]')[0]
+				// console.log(rooms);
+				if (typeof(rooms) != 'undefined') {
+					this.allData = rooms
+					this.nschool = rooms.data.length
 					this.array1 = []
-					
+
 					for (var i = 0; i < this.nschool; i++) {
-						this.array1.push(res.data[i].school)
+						this.array1.push(rooms.data[i].school)
 					}
-					
+
 					this.dis_num1 = 0
 					uni.hideLoading()
-					// 拆分之前选好的楼栋和宿舍号
-					if (this.options.roomSelect != '') {
-						var str = this.options.roomSelect;
-						var arr = new Array();
-						var i = 0;
-						while (i < str.length) {
-							var tmp = str.charCodeAt(i)
-							var s = "";
-							while (str.charCodeAt(i) < 256) {
-								s = s + str.charAt(i);
-								i++;
-							}
-							arr.push(s);
-							s = "";
-							while (str.charCodeAt(i) > 256) {
-								s = s + str.charAt(i);
-								i++;
-							}
-							arr.push(s);
-						}
-					
-						// 自动填充
-						if (arr.length > 0) {
-							if (arr[1] != null && arr[1].length > 0) {
-								this.arr1 = [arr[1]]
-							}
-							let len = arr[2].length
-							if (arr[2] != null && len > 0) {
-								this.arr2 = [arr[2].substring(0, len - 3) + '栋']
-								this.arr3 = [arr[2].substring(len - 3, len - 2) + '层']
-								this.arr4 = [arr[2]]
-							}
-					
-							this.sel1(this.arr1)
-							this.sel2(this.arr2)
-							this.sel3(this.arr3)
-							this.sel4(this.arr4)
-					
-							this.add_class1 = 1
-							this.add_class2 = 1
-							this.add_class3 = 1
-							this.add_class4 = 1
-					
-							this.dis_num2 = 0
-							this.dis_num3 = 0
-							this.dis_num4 = 0
-						}
+				}
+				
+				if (this.$store.state.building.roomSelect != '') {
+					this.fillData()
+				}
+			},
+			/**
+			 * 填充楼栋号和宿舍号
+			 */
+			fillData() {
+				// 拆分之前选好的楼栋和宿舍号
+
+				var str = this.$store.state.building.roomSelect;
+				var arr = new Array();
+				var i = 0;
+				while (i < str.length) {
+					var tmp = str.charCodeAt(i)
+					var s = "";
+					while (str.charCodeAt(i) < 256) {
+						s = s + str.charAt(i);
+						i++;
+					}
+					arr.push(s);
+					s = "";
+					while (str.charCodeAt(i) > 256) {
+						s = s + str.charAt(i);
+						i++;
+					}
+					arr.push(s);
+				}
+
+				// 自动填充
+				if (arr.length > 0) {
+					if (arr[1] != null && arr[1].length > 0) {
+						this.arr1 = [arr[1]]
+					}
+					let len = arr[2].length
+					if (arr[2] != null && len > 0) {
+						this.arr2 = [arr[2].substring(0, len - 3) + '栋']
+						this.arr3 = [arr[2].substring(len - 3, len - 2) + '层']
+						this.arr4 = [arr[2]]
 					}
+
+					this.sel1(this.arr1)
+					this.sel2(this.arr2)
+					this.sel3(this.arr3)
+					this.sel4(this.arr4)
+
+					this.add_class1 = 1
+					this.add_class2 = 1
+					this.add_class3 = 1
+					this.add_class4 = 1
+
+					this.dis_num2 = 0
+					this.dis_num3 = 0
+					this.dis_num4 = 0
 				}
 			},
 			/**

+ 9 - 3
static/api.js

@@ -1,5 +1,7 @@
 const WEXIN_BASE_URL = 'https://api.mch.weixin.qq.com' // wexin
-const CODE_BASE_URL = 'https://developdomain.chuanghai-tech.com' // code
+// const CODE_BASE_URL = 'https://developdomain.chuanghai-tech.com' // code
+const CODE_BASE_URL = 'http://grzpqy.natappfree.cc' // code
+const IP_BASE_URL = 'http://pv.sohu.com/cityjson?ie=utf-8' // ip
 
 const myRequest = (options) => {
 	// 域名 或 url 为空,则不执行任何操作
@@ -14,9 +16,13 @@ const myRequest = (options) => {
 			BASE_URL = WEXIN_BASE_URL;} 
 		else if (options.host == 'code') {
 			BASE_URL = CODE_BASE_URL;
-		} else if (options.host == 'ceshi') {
-			BASE_URL = '';
+		} else if (options.host == 'ip') {
+			BASE_URL = IP_BASE_URL;
 		} else {
+			uni.showToast({
+				title: '域名无效',
+				icon: 'success'
+			});
 			return;
 		}
 

+ 3 - 3
store/index.js

@@ -4,18 +4,18 @@ import Vuex from "vuex"
 Vue.use(Vuex)
 const store = new Vuex.Store({
 	state: {
+		test: true,  // 控制是否是测试环境
 		payInfo: {
 			from: '',
-			resultCode: 666,
 			resultMsg: ''
 		},
-		hasUserInfo: false,
 		building: {
 			roomSelect: '',
 			add_class: 0,
 			dom: ''
 		},
-		stu_number: ''
+		stu_number: '',
+		reshui_amount: 0.00.toFixed(2)
 	},
 	mutations: {},
 	actions: {}