This commit is contained in:
@@ -974,12 +974,16 @@ def get_current_wechat_user(request):
|
||||
|
||||
@extend_schema(
|
||||
summary="微信小程序登录",
|
||||
description="支持通过 code 登录,以及可选的 phone_code 用于直接获取手机号并合并 Web 用户账号",
|
||||
description="支持通过 code 登录,以及可选的 phone_code 用于直接获取手机号并合并 Web 用户账号。同时支持传入用户基本信息(gender, country, province, city)。",
|
||||
request={
|
||||
'application/json': {
|
||||
'properties': {
|
||||
'code': {'type': 'string', 'description': 'wx.login获取的code'},
|
||||
'phone_code': {'type': 'string', 'description': 'getPhoneNumber获取的code (可选)'}
|
||||
'phone_code': {'type': 'string', 'description': 'getPhoneNumber获取的code (可选)'},
|
||||
'gender': {'type': 'integer', 'description': '性别 0未知 1男 2女 (可选)'},
|
||||
'country': {'type': 'string', 'description': '国家 (可选)'},
|
||||
'province': {'type': 'string', 'description': '省份 (可选)'},
|
||||
'city': {'type': 'string', 'description': '城市 (可选)'}
|
||||
},
|
||||
'required': ['code']
|
||||
}
|
||||
@@ -991,6 +995,12 @@ def wechat_login(request):
|
||||
code = request.data.get('code')
|
||||
phone_code = request.data.get('phone_code')
|
||||
|
||||
# 获取可选的用户信息
|
||||
gender = request.data.get('gender')
|
||||
country = request.data.get('country')
|
||||
province = request.data.get('province')
|
||||
city = request.data.get('city')
|
||||
|
||||
if not code:
|
||||
return Response({'error': 'Code is required'}, status=400)
|
||||
|
||||
@@ -1133,6 +1143,17 @@ def wechat_login(request):
|
||||
if user.openid == openid:
|
||||
user.session_key = session_key
|
||||
user.unionid = unionid
|
||||
|
||||
# 更新用户基本信息 (如果有传入)
|
||||
if gender is not None:
|
||||
user.gender = gender
|
||||
if country:
|
||||
user.country = country
|
||||
if province:
|
||||
user.province = province
|
||||
if city:
|
||||
user.city = city
|
||||
|
||||
user.save()
|
||||
|
||||
created = False # 简化处理
|
||||
|
||||
Reference in New Issue
Block a user