Browse Source

说明:水费充值jsapi支付,前端已经完成,需要与后端接口对接,再进一步优化。

程志平 5 years ago
parent
commit
d8e585efce
10 changed files with 134 additions and 244 deletions
  1. 1 1
      App.vue
  2. 5 1
      main.js
  3. 17 20
      pages.json
  4. 33 47
      pages/index/index.vue
  5. 7 7
      pages/jiaofei/jiaofei.vue
  6. 31 24
      pages/recharge/recharge.vue
  7. 21 4
      pages/select/select.vue
  8. 19 4
      static/api.js
  9. 0 98
      static/test.js
  10. 0 38
      static/test_xiaofei.js

+ 1 - 1
App.vue

@@ -11,7 +11,7 @@
 		},
 		globalData: {
 			primaryColor: '#1296db',
-			test: false
+			test: true
 		}
 	}
 </script>

+ 5 - 1
main.js

@@ -1,8 +1,12 @@
 import Vue from 'vue'
 import App from './App'
-import {myRequest} from './static/api.js'
+import {
+	CODE_BASE_URL,
+	myRequest
+} from './static/api.js'
 
 Vue.prototype.$myRequest = myRequest
+Vue.prototype.$code_base_url = CODE_BASE_URL
 
 // import {common} from './static/common.js'
 // Vue.prototype.$request = common.axios

+ 17 - 20
pages.json

@@ -14,38 +14,35 @@
 				"enablePullDownRefresh": false
 			}
 		},
-		
+
 		{
 			"path": "pages/recharge/recharge",
 			"style": {
-				"navigationBarTitleText": "钱包充值",
+				"navigationBarTitleText": "热水钱包充值",
 				"enablePullDownRefresh": false
 			}
-		},{
+		}, {
 			"path": "pages/jiaofei/jiaofei",
 			"style": {
-				"navigationBarTitleText": "电费",
+				"navigationBarTitleText": "电费充值",
 				"enablePullDownRefresh": false
 			}
-		}
-		,
+		},
 		{
-		    "path" : "pages/show/show",
-		    "style" :                                                                                    
-		    {
-		        "navigationBarTitleText": "台账管理",
-		        "enablePullDownRefresh": false
-		    }
-		    
+			"path": "pages/show/show",
+			"style": {
+				"navigationBarTitleText": "台账管理",
+				"enablePullDownRefresh": false
+			}
+
 		},
 		{
-		    "path" : "pages/select/select",
-		    "style" :                                                                                    
-		    {
-		        "navigationBarTitleText": "缴电费",
-		        "enablePullDownRefresh": false
-		    }
-		    
+			"path": "pages/select/select",
+			"style": {
+				"navigationBarTitleText": "缴电费",
+				"enablePullDownRefresh": false
+			}
+
 		}
 	],
 	"globalStyle": {

+ 33 - 47
pages/index/index.vue

@@ -10,7 +10,8 @@
 					<image src="../../static/images/shower2x.png" mode=""></image>
 					<text>洗 浴</text>
 				</navigator>
-				<navigator :url="'/pages/jiaofei/jiaofei?o=index&item=' + encodeURIComponent(JSON.stringify(this.userinfo))"
+				<navigator
+					:url="'/pages/jiaofei/jiaofei?o=index&item=' + encodeURIComponent(JSON.stringify(this.userinfo))"
 					open-type="redirect" class="menu_item">
 					<image src="../../static/images/recharge2x.png" mode=""></image>
 					<text>电费充值</text>
@@ -44,7 +45,6 @@
 				wxcode: '',
 				access_token: '',
 				access_token_for_amount: '', // 获取到应用有效凭证
-				refresh_token: '',
 				my_display: false,
 				userinfo: {},
 				amount: 0.00
@@ -153,23 +153,16 @@
 						'redirect_uri': 'mnp://wxd6f090391d410534'
 					}
 				})
-				if (res.statusCode == 200) {
-					if (res.data.refresh_token == '' || res.data.refresh_token == 'undefined') {
-						uni.showToast({
-							title: '未获得token'
-						})
-					} else {
-						this.access_token = res.data.access_token;
-						this.refresh_token = res.data.refresh_token;
 
-						// 通过access_token换取用户信息
-						this.get_user_info();
-					}
-				} else {
+				if (res.data.access_token == '' || res.data.access_token == 'undefined') {
 					uni.showToast({
-						icon: 'none',
-						title: '请求失败,未获得token'
+						title: '未获得token'
 					})
+				} else {
+					this.access_token = res.data.access_token
+
+					// 通过access_token换取用户信息
+					this.get_user_info();
 				}
 			},
 
@@ -189,41 +182,34 @@
 					}
 				});
 
-				if (res.statusCode == 200) {
-					if (res.data.errcode == 0 && res.data.errmsg == 'OK') {
-						try {
-							this.userinfo = res.data
-							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
-							// 存储用户信息
-							uni.setStorageSync('userinfo_storage_key', this.userinfo)
-							// 提示授权成功
-							uni.showToast({
-								icon: 'success',
-								title: '授权成功',
-								duration: 800,
-								success: (res) => {
-									this.my_display = true
-								}
-							})
-						} catch (e) {
-							console.log(e)
-						}
-					} else {
+				if (res.data.errcode == 0 && res.data.errmsg == 'OK') {
+					try {
+						this.userinfo = res.data
+						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
+						// 存储用户信息
+						uni.setStorageSync('userinfo_storage_key', this.userinfo)
+						// 提示授权成功
 						uni.showToast({
-							title: '未获得用户信息',
-							duration: 1000
-						});
+							icon: 'success',
+							title: '授权成功',
+							duration: 800,
+							success: (res) => {
+								this.my_display = true
+							}
+						})
+					} catch (e) {
+						console.log(e)
 					}
 				} else {
 					uni.showToast({
-						icon: 'none',
-						title: '请求失败,未授权成功'
+						title: '未获得用户信息',
+						duration: 1000
 					});
 				}
 			},

+ 7 - 7
pages/jiaofei/jiaofei.vue

@@ -362,7 +362,7 @@
 
 	function get_order_id(head) {
 		const date = new Date()
-
+	
 		let year = date.getFullYear()
 		let month = date.getMonth() + 1
 		let day = date.getDate()
@@ -370,19 +370,19 @@
 		let minute = date.getMinutes()
 		let second = date.getSeconds()
 		let millisecond = date.getMilliseconds()
-		let len_mill = millisecond.length
-
+		let len_mill = millisecond.toString().length
+	
 		month = month > 9 ? month : '0' + month
 		day = day > 9 ? day : '0' + day
 		second = second > 9 ? second : '0' + second
 		if (len_mill == 1) {
-			millisecond = '000' + millisecond
+			millisecond = (Math.floor(Math.random () * 9000) + 10000).toString() + millisecond
 		} else if (len_mill == 2) {
-			millisecond = '00'
+			millisecond = (Math.floor(Math.random () * 900) + 1000).toString() + millisecond
 		} else if (len_mill == 3) {
-			millisecond = '0' + millisecond
+			millisecond = (Math.floor(Math.random () * 900) + 100).toString() + millisecond
 		}
-
+	
 		return `${head}${year}${month}${day}${hour}${minute}${second}${millisecond}`
 	}
 </script>

+ 31 - 24
pages/recharge/recharge.vue

@@ -41,6 +41,9 @@
 				order_id: '', // 订单号
 				pay_info: '', // 支付参数。将此参数透传给支付 SDK 发起支付
 				access_token: '',
+				sub_appid: '',
+				card_number: '',
+				user_name: '',
 				test: getApp().globalData.test
 			};
 		},
@@ -72,6 +75,9 @@
 				console.log(e)
 			}
 
+			this.sub_appid = this.userinfo.sub_appid
+			this.card_number = this.userinfo.card_number
+			this.user_name = this.userinfo.name
 			// 获取应用有效凭证
 			this.get_valid_credentials()
 		},
@@ -119,25 +125,19 @@
 					},
 					data: {
 						'access_token': this.access_token,
-						'sub_appid': this.userinfo.sub_appid,
-						'user_id': this.userinfo.card_number,
+						'sub_appid': this.sub_appid,
+						'user_id': this.card_number,
 						'order_id': this.order_id = get_order_id('shuifei'),
 						'amount': this.amount * 100,
 						'order_type': 1,
-						'callback_url': ''
+						// 'callback_url': 'http://x3ys5i.natappfree.cc'
+						'callback_url': this.$code_base_url + '/HotWater/wxpayrecharge.action'
 					}
 				})
-				if (res.statusCode == 200) {
-					this.pay_info = res.data.data.pay_info
-					// 发起支付
-					this.pay_amount()
-				} else {
-					uni.showToast({
-						icon: 'none',
-						title: res.data.message,
-						duration: 3000
-					})
-				}
+
+				this.pay_info = res.data.data.pay_info
+				// 发起支付
+				this.pay_amount()
 			},
 			// 调起支付
 			pay_amount() {
@@ -156,20 +156,27 @@
 				}
 
 				var payInfo = this.pay_info; // 请求mppay接口返回的数据
-				var appMetaData = "app=test&version=1.1"; // 自定义回调数据
+				// var appMetaData = "card_number=" + this.card_number + "&user_name=" + this.user_name + "&account=" + this
+				// 	.amount; // 自定义回调数据
 
 				OpenMidas.init("test");
 				OpenMidas.pay(
 					payInfo,
-					function(resultCode, innerCode, resultMsg, appMetaData) {
+					// function(resultCode, innerCode, resultMsg, appMetaData) {
+					function(resultCode, innerCode, resultMsg) {
 						console.log(resultCode); // 支付响应状态码
 						console.log(innerCode); // 支付响应内部错误码
 						console.log(resultMsg); // 支付响应说明
 						console.log(appMetaData); // 自定义回调数据
 
 						// todo:处理业务逻辑
-					},
-					appMetaData
+						uni.showToast({
+							title: resultMsg,
+							icon: 'success'
+						})
+					}
+					// },
+					// appMetaData
 				)
 			},
 			/**
@@ -179,7 +186,7 @@
 				if (this.test) {
 					return
 				}
-				
+
 				const v = e.detail.value
 				this.amount = 10
 
@@ -240,7 +247,7 @@
 							}
 						}
 					})
-					
+
 					return
 				}
 				if (this.amount < 10 || this.amount > 100) {
@@ -291,17 +298,17 @@
 		let minute = date.getMinutes()
 		let second = date.getSeconds()
 		let millisecond = date.getMilliseconds()
-		let len_mill = millisecond.length
+		let len_mill = millisecond.toString().length
 
 		month = month > 9 ? month : '0' + month
 		day = day > 9 ? day : '0' + day
 		second = second > 9 ? second : '0' + second
 		if (len_mill == 1) {
-			millisecond = '000' + millisecond
+			millisecond = (Math.floor(Math.random() * 9000) + 10000).toString() + millisecond
 		} else if (len_mill == 2) {
-			millisecond = '00'
+			millisecond = (Math.floor(Math.random() * 900) + 1000).toString() + millisecond
 		} else if (len_mill == 3) {
-			millisecond = '0' + millisecond
+			millisecond = (Math.floor(Math.random() * 900) + 100).toString() + millisecond
 		}
 
 		return `${head}${year}${month}${day}${hour}${minute}${second}${millisecond}`

+ 21 - 4
pages/select/select.vue

@@ -55,7 +55,7 @@
 </template>
 
 <script>
-	import sortdata from '../../static/test.js'
+	// import sortdata from '../../static/test.js'
 	export default {
 		data() {
 			return {
@@ -84,7 +84,7 @@
 				dis_num3: 1,
 				dis_num4: 1,
 				// dis_num5: 1,
-				allData: sortdata, //所有数据
+				allData: [], //所有数据
 				storage: {} //存放选择数据
 			}
 		},
@@ -112,9 +112,10 @@
 			// for (i = 0; i < arr.length; i++) {
 			// 	console.log(arr[i], i);
 			// }
+			this.requestAllData()
 
 			this.nschool = this.allData.data.length
-
+			
 			// 自动填充
 			if (arr.length > 0) {
 				if (arr[1] != null && arr[1].length > 0) {
@@ -140,11 +141,27 @@
 				this.dis_num2 = 0
 				this.dis_num3 = 0
 				this.dis_num4 = 0
-				// this.dis_num5 = 0
 			}
 		},
 
 		methods: {
+			async requestAllData() {
+				const res = await this.$myRequest({
+					host: 'code',
+					url: '',
+					// method: 'POST',
+					header: {
+						'content-type': 'application/json'
+					},
+					data: {
+						// 'access_token': this.access_token
+					}
+				})
+				
+				console.log(res)
+				
+				// this.allData = res.data.data
+			},
 			changeSelect1(e) {
 				this.sel1(e.detail.value)
 			},

+ 19 - 4
static/api.js

@@ -1,8 +1,8 @@
 const WECARD_BASE_URL = 'https://open.wecard.qq.com' // wecard
 const CODE_BASE_URL = 'https://developdomain.chuanghai-tech.com' // code
 
-export const myRequest = (options) => {
-	
+const myRequest = (options) => {
+
 	// 域名 或 url 为空,则不执行任何操作
 	if (options.host == '' || options.url == '') {
 		return
@@ -25,12 +25,22 @@ export const myRequest = (options) => {
 			data: options.data || {},
 			success: (res) => {
 				// console.log(res)
-				resolve(res)
+				if (res.statusCode == 200) {
+					resolve(res)
+				} else {
+					uni.showToast({
+						title: '非正常返回:' + res.statusCode,
+						icon: 'none'
+					})
+
+					resolve(res)
+				}
 			},
 			fail: (err) => {
 				uni.showToast({
 					icon: 'none',
-					title: err.errMsg
+					title: err.errMsg,
+					duration: 1000000
 				})
 				reject(err)
 			}
@@ -41,3 +51,8 @@ export const myRequest = (options) => {
 		}
 	)
 }
+
+export {
+	CODE_BASE_URL,
+	myRequest
+}

+ 0 - 98
static/test.js

@@ -1,98 +0,0 @@
-// const data = [{"黄家湖校区":[{
-// 		"1栋":[{
-
-// 		}]
-// 	}]}
-// 	,
-// 	{"墨轩湖校区":[{
-// 			"1栋":[{
-
-// 			}]
-// 		}]}
-// ]
-
-const data = [{
-	"school": "黄家湖校区",
-	"builds": [{
-			"building": "1栋",
-			"floors": [{
-					"floor": "1层",
-					"rooms": ['1101', '1102', '1103', '1104', '1105']
-				},
-				{
-					"floor": "2层",
-					"rooms": ['1201', '1202', '1203', '1204', '1205']
-				}, {
-					"floor": "3层",
-					"rooms": ['1301', '1302', '1303', '1304', '1305']
-				}, {
-					"floor": "4层",
-					"rooms": ['1401', '1402', '1403', '1404', '1405']
-				}
-			]
-		},
-		{
-			"building": "2栋",
-			"floors": [{
-					"floor": "1层",
-					"rooms": ['2101', '2102', '2103', '2104', '2105']
-				},
-				{
-					"floor": "2层",
-					"rooms": ['2201', '2202', '2203', '2204', '2205']
-				}, {
-					"floor": "3层",
-					"rooms": ['2301', '2302', '2303', '2304', '2305']
-				}, {
-					"floor": "4层",
-					"rooms": ['2401', '2402', '2403', '2404', '2405']
-				}
-			]
-		}
-	]
-}, {
-	"school": "墨轩湖校区",
-	"builds": [{
-			"building": "1栋",
-			"floors": [{
-					"floor": "1层",
-					"rooms": ['1101', '1102', '1103', '1104', '1105']
-				},
-				{
-					"floor": "2层",
-					"rooms": ['1201', '1202', '1203', '1204', '1205']
-				}, {
-					"floor": "3层",
-					"rooms": ['1301', '1302', '1303', '1304', '1305']
-				}, {
-					"floor": "4层",
-					"rooms": ['1401', '1402', '1403', '1404', '1405']
-				}
-			]
-		},
-		{
-			"building": "2栋",
-			"floors": [{
-					"floor": "1层",
-					"rooms": ['2101', '2102', '2103', '2104', '2105']
-				},
-				{
-					"floor": "2层",
-					"rooms": ['2201', '2202', '2203', '2204', '2205']
-				}, {
-					"floor": "3层",
-					"rooms": ['2301', '2302', '2303', '2304', '2305']
-				}, {
-					"floor": "4层",
-					"rooms": ['2401', '2402', '2403', '2404', '2405']
-				}
-			]
-		}
-	]
-}]
-
-
-
-module.exports = {
-	data: data,
-}

+ 0 - 38
static/test_xiaofei.js

@@ -1,38 +0,0 @@
-const data_xiaofei = [{
-	dom: '3310',
-	xiaofei: [{
-		name: "但茂华",
-		tdate: "7月1日",
-		time: "9:00",
-		money: 10.3
-	},{
-		name: "张平",
-		tdate: "7月2日",
-		time: "8:00",
-		money: 20
-	},{
-		name: "陈士柏",
-		tdate: "7月2日",
-		time: "9:00",
-		money: 30
-	},{
-		name: "张平",
-		tdate: "7月3日",
-		time: "11:00",
-		money: 15
-	},{
-		name: "程志平",
-		tdate: "7月5日",
-		time: "14:00",
-		money: 20
-	},{
-		name: "但茂华",
-		tdate: "7月8日",
-		time: "16:00",
-		money: 15
-	}]
-}]
-
-module.exports = {
-	data: data_xiaofei,
-}