文章目录
一、小程序快捷登录
1.定义接口
2.获取登录凭证 code
3.获取手机号并登录
注意:获取手机号功能针对非个人开发者,且完成认证
的小程序开放
工作场景:使用企业小程序appid
,且把微信号添加到开发者列表中
二、模拟快捷登录
说明:获取手机号功能针对个人开发者不开放
1.封装模拟登录API
import type { LoginResult } from "@/types/member"
import { http } from "@/utils/http"
export type LoginParams = {
code:string
encryptedData:string
iv:string
}
// 小程序登录-内测版
// POST
// /login/wxMin/simple
export const postLoginWxMinSimpleAPI = (phoneNumber:string) => {
return http<LoginResult>({
method:'POST',
url:'/login/wxMin/simple',
data:{
phoneNumber
}
})
}
2.调用模拟登录
三、保存登录信息
1.类型声明
2.状态管理
// 保存会员信息
const memberStore = useMemberStore()
memberStore.setProfile(profile)