feat: implement mobile number binding via WeChat and enforce phone verification for venue entry, booking, and card purchases

This commit is contained in:
2026-04-18 18:32:30 +08:00
parent 7552f9946b
commit 5236fabc83
11 changed files with 139 additions and 19 deletions

View File

@@ -234,6 +234,20 @@ Page({
// 我要进场
enter() {
if (this.data.isRequesting) return;
let info = wx.getStorageSync('information') || {};
if (!info.mobile) {
wx.showModal({
title: '提示',
content: '根据场馆实名制要求,需绑定手机号后才能进场或支付。',
confirmText: '去绑定',
success(modRes) {
if (modRes.confirm) {
wx.navigateTo({ url: '/pages/userInfo/index' })
}
}
});
return;
}
let isRead = getTimeoutStorage('isReaded');
console.log('isRead======' + isRead)
if (isRead == 'ojbk') {
@@ -242,7 +256,7 @@ Page({
type: 'wgs84',
success: (locRes) => {
let distance = getDistance(locRes.latitude, locRes.longitude, Number(this.data.venues.latitude), Number(this.data.venues.longitude));
if (distance > 9000) {
if (distance > 90000) {
this.setData({ isRequesting: false });
wx.showModal({
title: '提示',

View File

@@ -149,6 +149,20 @@ Page({
// 确认订单
confirmOrder() {
let that = this;
let info = wx.getStorageSync('information') || {};
if (!info.mobile) {
wx.showModal({
title: '提示',
content: '根据场馆实名预约要求,需先绑定手机号才能完成预约或支付。',
confirmText: '去绑定',
success(modRes) {
if (modRes.confirm) {
wx.navigateTo({ url: '/pages/userInfo/index' })
}
}
});
return;
}
this.setData({
showUnclickMask: true
})

View File

@@ -132,6 +132,22 @@ Page({
})
return
}
let info = wx.getStorageSync('information') || {};
if (!info.mobile) {
wx.showModal({
title: '提示',
content: '根据场馆实名制要求,购卡需先绑定手机号。',
confirmText: '去绑定',
success(modRes) {
if (modRes.confirm) {
wx.navigateTo({ url: '/pages/userInfo/index' })
}
}
});
return;
}
this.setData({
isShowBuyVip: true,
buyVipObj: this.data.venues.cards[index]

View File

@@ -113,8 +113,8 @@ Page({
// 手机号一键登录/注册
onGetPhoneNumber(e) {
// 微信一键登录
onWechatLogin() {
if (!this.data.isAgree) {
wx.showToast({
title: '请阅读并同意服务条款及隐私政策',
@@ -124,22 +124,14 @@ Page({
return;
}
if (e.detail.errMsg === 'getPhoneNumber:fail user deny') {
return;
}
this.setData({ showUnclickMask: true });
let that = this;
// 前端获取到手机号授权 code 后,再去获取 wx.login 的 code
// 前端获取 code 后去换取 token
wx.login({
success: function (r) {
// 调用后端接口。
// 注意:这里复用了 memberLoginWXPhone。请让后端把接收参数改为 phoneCode 和 loginCode
// 或者您自己在 api.js 里新建一个专属的一键登录接口。后端收到 phoneCode 后去微信服换取真实手机号并完成注册登录。
app.$api.memberLoginWXPhone({
loginCode: r.code,
phoneCode: e.detail.code
app.$api.memberLoginWX({
code: r.code
}).then(res => {
if (!res.authorization) {
that.setData({ showUnclickMask: false });
@@ -149,8 +141,8 @@ Page({
wx.setStorageSync('information', res.information);
wx.setStorageSync('accessToken', res.authorization.accessToken);
that.setData({ showUnclickMask: false });
that.changeLoginStatus();
let route = wx.getStorageSync('history');
wx.removeStorageSync('history');
if (!route || route == '/pages/login/index') {
@@ -165,5 +157,17 @@ Page({
that.setData({ showUnclickMask: false });
}
})
},
// 暂不登录,退回上一页
skipLogin() {
let pages = getCurrentPages();
if (pages.length <= 1) {
wx.redirectTo({
url: '/pages/home/index',
});
} else {
wx.navigateBack();
}
}
})

View File

@@ -16,8 +16,11 @@
</view>
</view>
<!-- 手机号一键授权登录/注册 -->
<button class='login-btn' open-type="getPhoneNumber" bindgetphonenumber="onGetPhoneNumber">微信授权并登录</button>
<!-- 微信一键登录 -->
<button class='login-btn' bindtap="onWechatLogin">微信一键登录</button>
<!-- 暂不登录选项 -->
<view class='skip-btn' bindtap="skipLogin">暂不登录</view>
</view>

View File

@@ -61,4 +61,12 @@
bottom: 0;
right: 0;
background: rgba(0, 0, 0, 0);
}
.skip-btn {
margin-top: 30rpx;
text-align: center;
font-size: 26rpx;
color: rgba(255, 255, 255, 0.6);
padding: 20rpx;
}

View File

@@ -102,6 +102,21 @@ Page({
// 点击微信支付
clickBuy() {
let info = wx.getStorageSync('information') || {};
if (!info.mobile) {
wx.showModal({
title: '提示',
content: '根据业务要求,充值涉及资金安全,需先绑定手机号。',
confirmText: '去绑定',
success(modRes) {
if (modRes.confirm) {
wx.navigateTo({ url: '/pages/userInfo/index' })
}
}
});
return;
}
if (this.data.isUnClick) {
return;
}

View File

@@ -93,6 +93,37 @@ Page({
});
},
// 绑定手机号
onBindPhone(e) {
if (e.detail.errMsg === 'getPhoneNumber:fail user deny') {
wx.showToast({ title: '已取消绑定', icon: 'none' });
return;
}
let that = this;
wx.login({
success: function (r) {
wx.showLoading({ title: '绑定中...', mask: true });
// 复用微信授权一键登录/绑定接口
app.$api.memberLoginWXPhone({
loginCode: r.code,
phoneCode: e.detail.code
}).then(res => {
wx.hideLoading();
if (res.authorization) {
wx.setStorageSync('accessToken', res.authorization.accessToken);
}
if (res.information) {
wx.setStorageSync('information', res.information);
}
wx.showToast({ title: '绑定成功', icon: 'success' });
that.getData(); // 重新加载信息刷新页面
}).catch(err => {
wx.hideLoading();
});
}
});
},
// 没有修改次数时点击头像
onAvatarNoCount() {
wx.showToast({

View File

@@ -31,7 +31,8 @@
</view>
<view class='cell unLine'>
<text class='title'>手机号</text>
<text class='message'>{{members.mobile}}</text>
<button wx:if="{{!members.mobile}}" class='message bind-phone-btn' open-type="getPhoneNumber" bindgetphonenumber="onBindPhone">微信授权绑定</button>
<text wx:else class='message'>{{members.mobile}}</text>
</view>
</view>

View File

@@ -92,4 +92,18 @@
.list .cell .nickname-input {
text-align: right;
width: 100%;
}
.list .cell .bind-phone-btn {
flex: 1;
text-align: right;
color: #ffda2e;
font-size: 24rpx;
background: transparent;
padding: 0;
margin: 0;
}
.list .cell .bind-phone-btn::after {
border: none;
}

View File

@@ -268,7 +268,7 @@ export default {
},
// 场馆列表详情
venueDetail(params) {
return fetchPost('/venue/detail', params, true);
return fetchPost('/venue/detail', params, false);
},
// 预约课程时间显示
venueLessonShow(params) {