2021-05-13

支付宝小程序

获取用户信息

// 微信授权登录
			getAuthCode: function(e) {
				var that = this
				my.getAuthCode({
					scopes: ['auth_user'],
					// 主动授权:auth_user,静默授权:auth_base。或者其它scope。如需同时获取用户多项授权,可在 scopes 中传入多个 scope 值。
					success: (res) => {
						console.log(res, "authCode")
						var code = res.authCode
						my.getAuthUserInfo({
							success: (res1) => {
								console.log(res1, "user_info")
								if (res.authCode) {
									console.log(res1, "user_info")
									that.$request.httpRequest({
										method: "post",
										url: `index/user/ali_login`, //请求地址
										data: {
											code: code,
											user_info: JSON.stringify(res1)

										} //参数
									}).then(res3 => {
										console.log(res3, "that")
										if (res3.data.code == 0) {
											console.log( res3.data.data.token, " res3.data.data.token")
											uni.setStorageSync("token", res3.data.data.token)
					
										}
									})
								}
							}
						});

					},
				});
			}

支付

		payScuss() {
				var that = this
				uni.showModal({
					title: '',
					content: '确认支付',
					success(res) {
						if (res.confirm) {
							that.$request.httpRequest({
								method: 'POST',
								url: 'index/park/goPay',
								data: {
									pay_type: 2,
									order_id: that.orderId
								}
							}).then(res1 => {
								console.log(res1, "uuuuuuuu")
								if (res1.data.code == 0) {
									my.tradePay({
										// 调用统一收单交易创建接口(alipay.trade.create),获得返回字段支付宝交易号trade_no
										tradeNO: res1.data.data.tradeNo,
										success: (res) => {
											console.log(res, "11")
											// my.alert({
											// 	content: JSON.stringify(res),
											// });
											that.autoplay = false
											console.log(1)
											if (res.resultCode == 9000) {
												that.autoplay = false

												uni.showToast({
													title: "支付成功",
													icon: 'none',
												})
												setTimeout(() => {
													uni.reLaunch({

														url: "../payScuss/payScuss?orderid=" + that.orderId + '&price=' + that.price,

													})
												}, 1000);

											}else{
												uni.showToast({
													title: "支付失败",
													icon: 'none',
												})
											}
										},
										fail: (res) => {
											console.log(res, "22")
											// my.alert({
											// 	content: JSON.stringify(res),
											// });


										}
									});
								}

							});


						} else if (res.cancel) {
							console.log('用户点击取消')
						}
					}
				})
			},
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值