uniapp 微信小程序,通过手机号一键登录之后,登录状态过期如何实现静默登录?

作者站长头像
站长
· 阅读数 13

uniapp 微信小程序,通过手机号一键登录之后,登录状态过期如何实现静默登录

<template>
      <button type="default" open-type="getPhoneNumber" @getphonenumber="decryptPhoneNumber">一键登录</button>

</template>
<script>
/** 手机号 */
const decryptPhoneNumber = (value) => {
  let phoneCode = value.detail.code
  uni.login({
    provider: 'weixin',
    success: async (res) => {
      let openCode = res.code
      const res2 = await wxLogin(phoneCode, openCode)
      uni.setStorage({
        key: 'token',
        data: res2.data.token,
      });
      uni.setStorage({
        key: 'phone',
        data: res2.data.phone,
      });
      isLogin.value = true
      phone.value = res2.data.phone
    }
  });
}
</script>
回复
1个回答
avatar
test
2024-06-20

使用 wx.login 获取用户 openid 请求后端解密处理验证完成之后返回新的 token

回复
likes
适合作为回答的
  • 经过验证的有效解决办法
  • 自己的经验指引,对解决问题有帮助
  • 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
  • 询问内容细节或回复楼层
  • 与题目无关的内容
  • “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容