consumer-app/api/auth.js

57 lines
1.6 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/**
* 认证相关接口
*/
import { request } from './index.js'
/**
* 账户密码登录
* @param {Object} data 登录数据
* @param {String} data.mobile 手机号
* @param {String} data.password 密码
* @returns {Promise} 返回登录结果包含token等
*/
export function login(data) {
return request({
url: '/app-api/member/auth/login',
method: 'POST',
data: data,
showLoading: true,
needAuth: false // 登录接口不需要token认证
})
}
/**
* 小程序一键授权手机号登录
* @param {Object} data 登录数据
* @param {String} data.phoneCode 手机 code, 小程序通过 wx.getPhoneNumber 方法获得
* @param {String} data.loginCode 登录 code, 小程序通过 wx.login 方法获得
* @param {String} data.state state 参数,必填,用于回调的随机值
* @param {String} data.inviteCode 邀请码可选第一位是类型第二位是用户id例如1-1, 0-1
* @returns {Promise} 返回登录结果包含token等
*/
export function loginByPhone(data) {
return request({
url: '/app-api/member/auth/weixin-mini-app-login',
method: 'POST',
data: data,
showLoading: true,
needAuth: false // 登录接口不需要token认证
})
}
/**
* 刷新token
* @param {String} refreshToken 刷新令牌
* @returns {Promise} 返回新的token信息
*/
export function refreshToken(refreshToken) {
return request({
url: '/app-api/member/auth/refresh', // 根据实际接口调整
method: 'POST',
data: { refreshToken },
showLoading: false,
needAuth: false // 刷新token接口不需要accessToken认证
})
}