微信APP授权登录,使用SpringCloud整合Uniappp 实战微信APP授权登陆

58 阅读1分钟

微信APP授权登录,使用SpringCloud 整合Uniappp 实战微信APP授权登陆

1. 微信注册地址

Spring Cloud全栈实战:手撸企业级项目,从入门到架构师! 在这里插入图片描述

2. 微信APP申请

Spring Cloud全栈实战:手撸企业级项目,从入门到架构师! 在这里插入图片描述

3. 微信APP填写信息申请

Spring Cloud全栈实战:手撸企业级项目,从入门到架构师! 在这里插入图片描述

4. 微信APP开通接口

在这里插入图片描述

5.微信APP验签名

Spring Cloud全栈实战:手撸企业级项目,从入门到架构师! 在这里插入图片描述

6.微信APP签名获取

在这里插入图片描述

7.微信APP审核通过

等待审核通过

在这里插入图片描述

8.微信APP整合uniapp获取授权登陆

Spring Cloud全栈实战:手撸企业级项目,从入门到架构师!

uni.getProvider({
    service: 'oauth',
    success: function(res) {
        if (~res.provider.indexOf('weixin')) {
            uni.login({
                provider: 'weixin',
                success: function(loginRes) {

                    // 获取用户信息
                    uni.getUserInfo({
                        provider: 'weixin',
                        success: function(infoRes) {
                            // console.log('-------获取微信用户所有-----');
                            // console.log(JSON.stringify(infoRes .userInfo));
                            // console.log('-------获取微信用户所有1-----');
                            api.sendLoign({
                                "openId": infoRes.userInfo.openId,
                                "nickName": infoRes.userInfo.nickName,
                                "gender": infoRes.userInfo.gender,
                                "avatarUrl": infoRes.userInfo.avatarUrl,
                                "unionId": infoRes.userInfo.unionId,
                                "country": infoRes.userInfo.country,
                                "province": infoRes.userInfo.province,
                                "city": infoRes.userInfo.city
                            }).then(res = >{

                                if (res.datas.openId) {
                                    that.nickName = res.datas.nickName that.avatarUrl = res.datas.avatarUrl uni.setStorageSync('loign_status', res.datas.openId) uni.setStorageSync('loign_success', res.datas) uni.setStorageSync('radio', res.datas.radio) console.log(res)
                                } else {
                                    console.log('66')
                                }

                            }).
                            catch(err = >{
                                console.log(err)
                            })

                        },
                        fail(e) {
                            uni.showToast({
                                icon: 'none',
                                // title: '登陆失败,请确保已安装或已登录微信',
                                title: res.errMsg,
                                duration: 2000
                            });
                        }
                    });
                }
            });
        }
    },
    fail(e) {

        uni.showToast({
            icon: 'none',
            // title: '登陆失败,请确保已安装或已登录微信',
            title: "登陆失败,请确保已安装或已登录微信",
            duration: 2000
        });
    }
});