iv和encryptData 数据解密有问题
发布于 5 年前 作者 zhengmin 17531 次浏览 来自 问答

用的是官方的php 代码,原来主动请求用户授权的流程,非常稳定,根据iv和encrpytDaa能解密出用户信息);

但是这两天更新了用户主动请求授权的 方式,也就是open-type为getuserinfo的时候,用返回的数据(iv ,encryptData)去请求解密,老是报错41003;前端代码差异如下

主动请求用户授权

_event.subscribe(UNAUTH, async () => {

            console.log(unauthorized);

            let loginRet = await apiEntry.login();

            let uResp = await apiEntry.getUserInfo();

            console.log(uResp);

            let thirdSession = await this._httpClient.post(`${BASE_URL}/v1/wechat-auth/session/${loginRet.code}`, uResp);

            apiEntry.setStorageSync(sKey, thirdSession.data.sKey);

            apiEntry.setStorageSync(user_id, thirdSession.data.user.external_id);

            apiEntry.setStorageSync(user, thirdSession.data.user);

            let currentPage = getCurrentPages().pop();

            if (currentPage.onShow && typeof currentPage.onShow === function) {

                currentPage.onShow();

            }

        });

用户主动请求授权

// 这里是button点击弹出授权之后,返回的userinfo

public async setAuth(userInfo: any) {

        let isAuth = await this.isAuth();

        if (isAuth) return;

        let loginRet = await apiEntry.login();

        let uResp = userInfo;

        let thirdSession = await this._http.post(`${BASE_URL}/v1/wechat-auth/session/${loginRet.code}`, uResp);

        apiEntry.setStorageSync(sKey, thirdSession.data.sKey);

        apiEntry.setStorageSync(user_id, thirdSession.data.user.external_id);

        apiEntry.setStorageSync(user, thirdSession.data.user);

    }

第二种情况也就是下面这种情况,会出现“有时候能解密,有时候又不能解密的情况”,难道是微信的服务器不稳定么?

1 回复

我也出现了有时候能解密,有时候又不能解密的情况,后来发现是前端一定要先获取code,保证密钥没有过期,然后再获取iv和encryptData。我的是这样的,希望对你有帮助

回到顶部