Browse Source

app支付调试

zhaoxw 4 years ago
parent
commit
448b2b727e
6 changed files with 213 additions and 60 deletions
  1. 1 1
      pages/index/index.vue
  2. 45 34
      pages/index/login.vue
  3. 42 0
      pagesGood/orderPay.vue
  4. 58 25
      pagesMain/entrustForm.vue
  5. 33 0
      pagesMain/orderDetail.vue
  6. 34 0
      pagesMain/orderItem.vue

+ 1 - 1
pages/index/index.vue

@@ -197,7 +197,7 @@
 		}
 	}
 </script>
-<style>
+<style scoped>
 	.search .uni-searchbar {
 		background-color: transparent !important;
 	}

+ 45 - 34
pages/index/login.vue

@@ -21,7 +21,7 @@
 			<!-- #endif -->
 			<!-- #ifdef APP-PLUS -->
 			<button class="authorize-login" @click="getUserinfoApp">
-				登录5
+				登录
 			</button>
 			<!-- #endif -->
 			<view @click="showAgreement = true" class="agreement">点击登录视为同意<text class="underline">平台服务协议</text></view>
@@ -204,9 +204,9 @@
 										data: wxLoginData
 									})
 									this.wxLoginData = wxLoginData
-									this.getUserInfo()
+									this.getUserInfo(1)
 								},
-								fail: () => {
+								fail: (error) => {
 									console.log(33333, error)
 									this.$refs.uTips.show({
 										title: '微信登录授权失败',
@@ -231,47 +231,52 @@
 				let that = this
 				console.log('app enter')
 				uni.login({
-					// provider: 'weixin',
+					provider: 'weixin',
 					success: (res2) => {
 						console.log('res2', res2)
 						uni.getUserInfo({
 							provider: 'weixin',
 							success: (info) => {
-								console.log('info')
-								// uni.setStorage({
-								// 	key: 'wxLoginData',
-								// 	data: {
-								// 		code: res2.code,
-								// 		encryptedData: info.encryptedData,
-								// 		iv: info.iv,
-								// 		rawData: info.rawData,
-								// 		signature: info.signature,
-								// 	}
-								// })
-								// that.wxLoginData = uni.getStorageSync("wxLoginData")
-								// console.log(1111111, that.wxLoginData && that.wxLoginData.rawData)
+								console.log('info',info)
+								uni.setStorage({
+									key: 'wxLoginData',
+									data: {
+										nickName: info.userInfo.nickName,
+										gender: info.userInfo.gender,
+										avatarUrl: info.userInfo.avatarUrl,
+										unionId: info.userInfo.unionId,
+										openId:info.userInfo.openId
+										// code: res2.code,
+										// encryptedData: info.encryptedData,
+										// iv: info.iv,
+										// rawData: info.rawData,
+										// signature: info.signature,
+									}
+								})
+								that.wxLoginData = uni.getStorageSync("wxLoginData")
+								console.log(1111111, that.wxLoginData)
 								// that.userNmae = JSON.parse(that.wxLoginData.rawData).nickName
-								// that.getUserInfo()
-								// this.$refs.uTips.show({
-								// 	title: '获取角色信息成功',
-								// 	type: 'success',
-								// })
+								that.getUserInfo(0)
+								this.$refs.uTips.show({
+									title: '获取角色信息成功',
+									type: 'success',
+								})
 							},
 							fail: (error) => {
 								console.log(2222, error)
-								// that.$refs.uTips.show({
-								// 	title: '微信登录授权失败',
-								// 	type: 'warning',
-								// })
+								that.$refs.uTips.show({
+									title: '微信登录授权失败',
+									type: 'warning',
+								})
 							}
 						})
 					},
-					fail: () => {
+					fail: (error) => {
 						console.log(33333, error)
-						// that.$refs.uTips.show({
-						// 	title: '微信登录授权失败',
-						// 	type: 'warning',
-						// })
+						that.$refs.uTips.show({
+							title: '微信登录授权失败',
+							type: 'warning',
+						})
 					}
 				})
 				// uni.getProvider({
@@ -294,28 +299,34 @@
 			},
 			//#endif
 
-			// 发请求获取个人数据
-			getUserInfo() {
+			// 发请求获取个人数据 envType:1小程序 0:app
+			getUserInfo(envType) {
+				console.log('发请求获取个人数据envType',envType)
 				NET.request(API.WxLogin, {
 					...this.wxLoginData,
 					// ...this.wxPhoneData,
 				}, 'POST').then(res => {
+					console.log('token',res)
 					uni.setStorage({
 						key: 'token',
 						data: res.data.token
 					})
+					console.log('缓存中wxLoginData',this.wxLoginData)
 					uni.setStorage({
 						key: 'userData',
 						data: {
-							headImage: JSON.parse(this.wxLoginData.rawData).avatarUrl,
+							headImage: envType ? this.wxLoginData.rawData.avatarUrl : this.wxLoginData.avatarUrl,
 							userName: res.data.name,
 							userId: res.data.userId,
 						}
 					})
+					console.log('存个人信息')
 					uni.switchTab({
 						url: '/pages/index/index'
 					})
+					console.log('switchTab')
 				}).catch(error => {
+					console.log(44444, error)
 					this.$refs.uTips.show({
 						title: '微信登录授权失败',
 						type: 'warning',

+ 42 - 0
pagesGood/orderPay.vue

@@ -302,7 +302,11 @@
 						orderType: this.orderType,
 						//  备注
 						notes: this.notes,
+					    // #ifdef APP-PLUS
+						channel: 2
+					    //#endif
 					}, 'POST').then(res => {
+						console.log('提交订单', res)
 						if (res.isSuccess) {
 							if (res.data) {
 								this.orderId = res.data.orderId
@@ -326,6 +330,7 @@
 									}, 1000)
 									return;
 								}
+							// #ifdef MP-WEIXIN
 								uni.requestPayment({
 									provider: 'wxpay',
 									timeStamp: res.data.timeStamp,
@@ -355,6 +360,43 @@
 										}, 1000)
 									}
 								})
+							//#endif
+							
+							// #ifdef APP-PLUS
+							    uni.requestPayment({
+							    	provider: 'wxpay',
+									orderInfo:{
+										"package": res.data.packageValue,
+										"appid": res.data.appId,
+										"sign": res.data.paySign,
+										"partnerid": res.data.partnerId,
+										"prepayid": res.data.prepayId,
+										"noncestr": res.data.nonceStr,
+										"timestamp": res.data.timeStamp,
+									}
+							    	success: (payRes) => {
+							    		console.log('paySuccess:' + JSON.stringify(payRes));
+							    		uni.redirectTo({
+							    			url: '/pagesMain/paySuccess?orderId=' + this.orderId + '&orderStatus=' + 2
+							    		});
+							    	},
+							    	fail: (error) => {
+							    		console.log('payfail:' + JSON.stringify(error));
+							    		this.$refs.uTips.show({
+							    			title: '支付未成功',
+							    			type: 'warning',
+							    		})
+							    		setTimeout(() => {
+							    			// uni.redirectTo({
+							    			//     url: '/pagesMain/orderDetail?orderId=' + this.orderId + '&orderStatus=' + 1
+							    			// });
+							    			uni.navigateTo({
+							    			    url: '/pagesMain/orderDetail?orderId=' + this.orderId + '&orderStatus=' + 1
+							    			});
+							    		}, 1000)
+							    	}
+							    })
+							//#endif
 							} else {
 								uni.redirectTo({
 									url: '/pagesMain/paySuccess'

+ 58 - 25
pagesMain/entrustForm.vue

@@ -117,37 +117,70 @@
 					...this.entrustForm,
 					entrustDurationTime: JSON.stringify(this.entrustForm.entrustDurationTime),
 					payAomount: this.price * Number(this.entrustForm.entrustDurationTime),
-					orderId: Number(this.orderId)
+					orderId: Number(this.orderId),
+				    // #ifdef APP-PLUS
+					channel: 2
+				    //#endif
 				}, 'POST').then(res => {
 					if (res.isSuccess) {
 						if (res.data) {
 							this.orderId = res.data.orderId
+						// #ifdef MP-WEIXIN
 							uni.requestPayment({
-									provider: 'wxpay',
-									timeStamp: res.data.timeStamp,
-									nonceStr: res.data.nonceStr,
-									package: res.data.packageValue,
-									signType: res.data.signType,
-									paySign: res.data.paySign,
-									success: (payRes) => {
-										this.$refs.uTips.show({
-											title: '支付成功',
-											type: 'success',
-										})
-										// setTimeout(() => {
-										// 	uni.reLaunch({
-										// 		url: '/pagesMain/paySuccess?orderId=' + this.orderId
-										// 	});
-										// }, 1000)
-										uni.navigateBack(-1);
-									},
-									fail: (error) => {
-										this.$refs.uTips.show({
-											title: '支付失败',
-											type: 'warning',
-										})
-									}
+								provider: 'wxpay',
+								timeStamp: res.data.timeStamp,
+								nonceStr: res.data.nonceStr,
+								package: res.data.packageValue,
+								signType: res.data.signType,
+								paySign: res.data.paySign,
+								success: (payRes) => {
+									this.$refs.uTips.show({
+										title: '支付成功',
+										type: 'success',
+									})
+									// setTimeout(() => {
+									// 	uni.reLaunch({
+									// 		url: '/pagesMain/paySuccess?orderId=' + this.orderId
+									// 	});
+									// }, 1000)
+									uni.navigateBack(-1);
+								},
+								fail: (error) => {
+									this.$refs.uTips.show({
+										title: '支付失败',
+										type: 'warning',
+									})
+								}
 							})
+						//#endif
+						
+						// #ifdef APP-PLUS
+						    uni.requestPayment({
+								provider: 'wxpay',
+								orderInfo:{
+									"package": res.data.packageValue,
+									"appid": res.data.appId,
+									"sign": res.data.paySign,
+									"partnerid": res.data.partnerId,
+									"prepayid": res.data.prepayId,
+									"noncestr": res.data.nonceStr,
+									"timestamp": res.data.timeStamp,
+								}
+								success: (payRes) => {
+									this.$refs.uTips.show({
+										title: '支付成功',
+										type: 'success',
+									})
+									uni.navigateBack(-1);
+								},
+								fail: (error) => {
+									this.$refs.uTips.show({
+										title: '支付失败',
+										type: 'warning',
+									})
+								}
+						    })
+						//#endif
 						}
 					} else {
 						this.$refs.uTips.show({

+ 33 - 0
pagesMain/orderDetail.vue

@@ -524,8 +524,12 @@
 						mid: uni.getStorageSync("userData").userId,
 						orderCode: this.orderData.orderCode,
 						orderId: this.orderData.orderId,
+					    // #ifdef APP-PLUS
+						channel: 2
+					    //#endif
 					}, 'POST').then(res => {
 						this.modalShow = false
+					// #ifdef MP-WEIXIN
 						uni.requestPayment({
 							provider: 'wxpay',
 							timeStamp: res.data.timeStamp,
@@ -553,6 +557,35 @@
 								})
 							}
 						})
+					//#endif
+					
+					// #ifdef APP-PLUS
+					    uni.requestPayment({
+					    	provider: 'wxpay',
+					    	orderInfo:{
+					    		"package": res.data.packageValue,
+					    		"appid": res.data.appId,
+					    		"sign": res.data.paySign,
+					    		"partnerid": res.data.partnerId,
+					    		"prepayid": res.data.prepayId,
+					    		"noncestr": res.data.nonceStr,
+					    		"timestamp": res.data.timeStamp,
+					    	}
+					    	success: (payRes) => {
+					    		console.log('success:' + JSON.stringify(payRes));
+					    			uni.navigateTo({
+					    				url: '/pagesMain/paySuccess?orderId=' + this.orderData.orderId
+					    			});
+					    	},
+					    	fail: (error) => {
+					    		console.log('fail:' + JSON.stringify(error));
+					    		this.$refs.uTips.show({
+					    			title: '支付失败',
+					    			type: 'warning',
+					    		})
+					    	}
+					    })
+					// #endif
 					}).catch(error => {
 						this.modalShow = false
 						this.$refs.uTips.show({

+ 34 - 0
pagesMain/orderItem.vue

@@ -276,8 +276,12 @@
 						mid: uni.getStorageSync("userData").userId,
 						orderCode: this.orderData.orderCode,
 						orderId: this.orderData.orderId,
+					    // #ifdef APP-PLUS
+						channel: 2
+					    //#endif
 					}, 'POST').then(res => {
 						this.modalShow = false
+					// #ifdef MP-WEIXIN
 						uni.requestPayment({
 							provider: 'wxpay',
 							timeStamp: res.data.timeStamp,
@@ -305,6 +309,36 @@
 								})
 							}
 						})
+					//#endif
+					
+					// #ifdef APP-PLUS
+						uni.requestPayment({
+							provider: 'wxpay',
+							orderInfo:{
+								"package": res.data.packageValue,
+								"appid": res.data.appId,
+								"sign": res.data.paySign,
+								"partnerid": res.data.partnerId,
+								"prepayid": res.data.prepayId,
+								"noncestr": res.data.nonceStr,
+								"timestamp": res.data.timeStamp,
+							}
+							success: (payRes) => {
+								console.log('success:' + JSON.stringify(payRes));
+								uni.navigateTo({
+									url: '/pagesMain/paySuccess?orderId=' + this.orderData.orderId
+								});
+							},
+							fail: (error) => {
+								console.log('fail:' + JSON.stringify(error));
+								this.$refs.uTips.show({
+									title: '支付失败',
+									type: 'warning',
+								})
+							}
+						})
+					//#endif
+
 					}).catch(error => {
 						this.modalShow = false
 						this.$refs.uTips.show({