我的微信小程序上线了,AI识图生诗词文案,识别图片生成古诗词,欢迎大家使用。
(用户日访问量太少了,大家帮我踩一下,谢谢!)
以下是我在开发中的一些经验和心得。
通过访问uni.login,实现微信授权登录。全程不获取用户的任何信息。所以也不需要用户授权,直接实现后端登录的功能。
以下是小程序代码:
<template>
<view class="wrapper">
<button @click="wechatLogin">微信授权一键登录</button>
</view>
</template>
<script>
import { mapMutations } from 'vuex';
export default {
data() {
return {
};
},
methods: {
...mapMutations(['saveLoginStatus', 'saveUserInfo']),
async wechatLogin() {
try {
const loginRes = await uni.login({ provider: 'weixin' });
const userInfoRes = await uni.getUserInfo({ provider: 'weixin' });
// 获取到用户信息
const userInfo = userInfoRes.userInfo;
// 调用后端接口使用登录凭证(loginRes.code)和用户信息进行登录处理
this.code = loginRes[1].code;
this.doLogin();
// console.log('用户信息', this.code);
} catch (er