zoukankan      html  css  js  c++  java
  • 人人商城修改小程序授权为新版接口

    人人商城小程序用户授权登录失败,getUserProfile小程序登录接口升级

    怎么修改呢?

    1,修改pagesauthindex.wxml

    立即登录按钮改为

    1
    2
    3
    <button bindtap="getUserProfile" class="authBtn" lang="zh_CN">
    立即登录
    </button>

    from clipboard

    2,修改pagesauthindex.js

    第62行添加代码

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    getUserProfile(){
            wx.getUserProfile({
                desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
                success: (res) => {
                    // console.log("获取用户信息成功", res);
                    // return;
                    wx.showLoading({
                        title: "加载中"
                    }), wx.login({           
                        success: function(t) {
                    //         console.log(t);
                    // return;
                            n.post("wxapp/login", {
                                code: t.code
                            }, function(t) {
                    //             console.log(t.openid);
                    // return;
                                t.error ? n.alert("获取用户登录态失败:" + t.message) : n.get("wxapp/auth", {
                                    data: res.encryptedData,
                                    iv: res.iv,
                                    sessionKey: t.session_key,
                                    openId:t.openid
                                }, function(n) {
                                    1 == n.isblack && wx.showModal({
                                        title: "无法访问",
                                        content: "您在商城的黑名单中,无权访问!",
                                        success: function(n) {
                                            n.confirm && e.close(), n.cancel && e.close();
                                        }
                                    }), res.userInfo.openid = n.openId, res.userInfo.id = n.id, res.userInfo.uniacid = n.uniacid,
                                    e.setCache("userinfo", res.userInfo), e.setCache("userinfo_openid", res.userInfo.openid),
                                    e.setCache("userinfo_id", n.id), e.getSet(), wx.navigateBack({
                                        changed: !0
                                    });
                                });
                            });
                        },
                        fail: function() {
                            n.alert("获取用户信息失败!");
                        },
                        complete: function() {
                            wx.hideLoading();
                        }
                    });
                },
                fail: res => {
                    // console.log("获取用户信息失败", res)
                    n.alert("获取用户信息失败!");
                }
            })
        },

    如图,新旧代码对比
    from clipboard

    3,修改登录接口文件addonsewei_shopv2pluginappcoremobilewxapp.php

    由于getUserProfile本身就是不返回openid的,需要openid用login接口

    对应上面js的代码就是

    from clipboard

    接口文件第93行加上代码

    $data['openId'] = $_GPC['openId'];

    如图

    from clipboard

  • 相关阅读:
    Vue-Router路由 Vue-CLI脚手架和模块化开发 之 路由常用配置与路由嵌套
    (最大上升子序列) Super Jumping! Jumping! Jumping! -- hdu -- 1087
    最大连续子序列 -- hdu -- 1231
    (KMP灵活运用 利用Next数组 )Theme Section -- hdu -- 4763
    (KMP 水)Wow! Such Doge! -- hdu -- 4847
    (回文串 Manacher )Girls' research -- hdu -- 3294
    (回文串 Manacher)吉哥系列故事——完美队形II -- hdu -- 4513
    (回文串 )Best Reward -- hdu -- 3613
    Center Alignment
    Chat Server's Outgoing Traffic
  • 原文地址:https://www.cnblogs.com/741570hh/p/15063531.html
Copyright © 2011-2022 走看看