修改授权直接获取手机号逻辑
This commit is contained in:
@@ -10,7 +10,7 @@ const LoginPage: React.FC = () => {
|
||||
const [show_terms_layer, set_show_terms_layer] = useState(false);
|
||||
|
||||
// 微信授权登录
|
||||
const handle_wechat_login = async () => {
|
||||
const handle_wechat_login = async (e: any) => {
|
||||
if (!agree_terms) {
|
||||
set_show_terms_layer(true);
|
||||
Taro.showToast({
|
||||
@@ -21,9 +21,20 @@ const LoginPage: React.FC = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查是否获取到手机号
|
||||
if (!e.detail || !e.detail.code) {
|
||||
Taro.showToast({
|
||||
title: '获取手机号失败,请重试',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
set_is_loading(true);
|
||||
try {
|
||||
const response = await wechat_auth_login();
|
||||
// 传递手机号code给登录服务
|
||||
const response = await wechat_auth_login(e.detail.code);
|
||||
if (response.success) {
|
||||
save_login_state(response.token!, response.user_info!);
|
||||
|
||||
@@ -123,7 +134,8 @@ const LoginPage: React.FC = () => {
|
||||
{/* 微信快捷登录 */}
|
||||
<Button
|
||||
className={`login_button wechat_button ${is_loading ? 'loading' : ''}`}
|
||||
onClick={handle_wechat_login}
|
||||
openType="getPhoneNumber"
|
||||
onGetPhoneNumber={handle_wechat_login}
|
||||
disabled={is_loading}
|
||||
>
|
||||
<View className="wechat_icon">
|
||||
|
||||
@@ -36,7 +36,7 @@ export interface VerifyCodeResponse {
|
||||
}
|
||||
|
||||
// 微信授权登录
|
||||
export const wechat_auth_login = async (): Promise<LoginResponse> => {
|
||||
export const wechat_auth_login = async (phone_code?: string): Promise<LoginResponse> => {
|
||||
try {
|
||||
// 先进行微信登录获取code
|
||||
const login_result = await Taro.login();
|
||||
@@ -48,15 +48,12 @@ export const wechat_auth_login = async (): Promise<LoginResponse> => {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 使用 httpService 调用微信授权接口
|
||||
const auth_response = await httpService.post('/user/wx_auth', {
|
||||
code: login_result.code
|
||||
// 使用 httpService 调用微信授权接口,传递手机号code
|
||||
const auth_response = await httpService.post('user/wx_auth', {
|
||||
code: login_result.code,
|
||||
phone_code: phone_code // 传递手机号加密code
|
||||
});
|
||||
|
||||
|
||||
|
||||
if (auth_response.code === 0) {
|
||||
return {
|
||||
success: true,
|
||||
@@ -89,7 +86,7 @@ export interface PhoneLoginParams {
|
||||
export const phone_auth_login = async (params: PhoneLoginParams): Promise<LoginResponse> => {
|
||||
try {
|
||||
// 使用 httpService 调用验证验证码接口
|
||||
const verify_response = await httpService.post('/user/sms/verify', {
|
||||
const verify_response = await httpService.post('user/sms/verify', {
|
||||
phone: params.phone,
|
||||
code: params.verification_code
|
||||
});
|
||||
@@ -127,7 +124,7 @@ export const phone_auth_login = async (params: PhoneLoginParams): Promise<LoginR
|
||||
// 发送短信验证码
|
||||
export const send_sms_code = async (phone: string): Promise<SmsResponse> => {
|
||||
try {
|
||||
const response = await httpService.post('/user/sms/send', {
|
||||
const response = await httpService.post('user/sms/send', {
|
||||
phone: phone
|
||||
});
|
||||
|
||||
@@ -155,7 +152,7 @@ export const send_sms_code = async (phone: string): Promise<SmsResponse> => {
|
||||
// 验证短信验证码
|
||||
export const verify_sms_code = async (phone: string, code: string): Promise<VerifyCodeResponse> => {
|
||||
try {
|
||||
const response = await httpService.post('/user/sms/verify', {
|
||||
const response = await httpService.post('user/sms/verify', {
|
||||
phone: phone,
|
||||
code: code
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user