小程序

微信小程序获取unionid走过的坑

2019-08-20  本文已影响3人  追逐繁星的阿忠

参考地址:https://blog.csdn.net/a493001894/article/details/80323403

楼主说明:

1.换openId
2.换code
3.调用UserInfo(以按钮的形式触发,取到偏移量,即微信加密的参数)
4.得到前面三步中所有参数后,调用后端接口,从后端接口中获取uuid

获取如下数据:

onGotUserInfo: function (e) {

  var self = this;
        console.log('errMsg', e.detail.errMsg)
        console.log('userInfo', e.detail.userInfo)
        console.log('rawData', e.detail.rawData)
        var userInfo = e.detail.userInfo;
})


let ency = e.detail.encryptedData;
                let iv = e.detail.iv;
换openId

/**获取open_id*/
    getOpenId: function (callBack) {
        var self = this;
        //获取code
        wx.login({
            success: (res) => {
                //获取open_id
                var sendData = {
                    appid: app.appId,
                    code: res.code
                }
                let apiData = {
                    apiUrl: app.apiConfig.getOpenId,
                    type: 'GET',
                    sendData: sendData,
                };
                apiData.success = res => {
                    if (res.data) {
                        callBack && callBack(res.data);
                    }
                };
                app.apiConfig.getApi(apiData);
            },
            fail: () => {
                app.tool.showModal('提示', '登录凭证code获取失败');
            }
        })
    },

换code

上一篇下一篇

猜你喜欢

热点阅读