Home  >  Article  >  Web Front-end  >  How to test QQ login in uniapp

How to test QQ login in uniapp

王林
王林Original
2023-05-26 09:59:38917browse

With the development of mobile Internet, more and more applications need to integrate third-party login to improve user convenience and experience. For some large-scale applications, such as QQ login access, it has become necessary. In uniapp development, how to test the effect and function of QQ login access? This article will be divided into the following aspects to introduce how uniapp tests QQ login.

1. Preparation before the test

Before conducting the QQ login test, you need to apply to the QQ Internet official website to obtain parameters such as appkey and appsecret. You also need to ensure that the applied application information has been passed. Review. After the application is completed, you need to save the applied appkey, appsecret and other parameters for use in subsequent tests.

2. Test the QQ login function

In uniapp development, you can use the uni-login plug-in officially provided by uniapp to quickly access the third-party login function.

  1. Install the uni-login plug-in

Open the command line tool and enter the root directory of the uniapp project, enter the following command to install the uni-login plug-in:

npm install -S @dcloudio/uni-login

After the installation is complete, add the "pages/plugin/uni-login/authorize/authorize" page in uniapp's pages.json for subsequent calls.

  1. Write QQ login code

In uniapp development, you can call the login function of the uni-login plug-in through the uni.login method to implement the QQ login function. The code is as follows:

uni.login({
    provider: 'qq',
    success: function (res) {
        console.log(res);
        uni.setStorageSync('token',res.code);
    }
});

Among them, the provider parameter is the name of the third-party login interface, here it is "qq". After the call is successful, the user's login status code (res.code) can be obtained and stored in the cache for later use.

  1. Test the QQ login function

When testing the QQ login function, you need to ensure that the mobile phone you are using has the QQ client installed, and preview or package it through the mobile phone during uniapp development into the APP for testing. When calling the QQ login function, you can open the QQ client for authorized login. If the authorization is successful, the user's openid, token and other information will be returned.

It should be noted that authorization failure may occur during testing, which may be caused by incomplete settings on the QQ client or QQ Internet account. Please check the relevant configuration information.

3. Test the QQ login expiration time

After the QQ login is successful, the token information needs to be saved and used where needed. However, the QQ login token has an expiration time. In order to test the expiration time, you can use uni.checkSession to check the token expiration time in uniapp development.

uni.checkSession({

success() {
    console.log('token未过期');
},
fail() {
   console.log('token已过期');
}

});

The expiration status of the token can be determined by checking the value returned by the function.

4. Summary

Through the above method, we can quickly test the QQ login function and check the expiration of the token in uniapp development to ensure the normal use of the user's login function. At the same time, when accessing the QQ login function, you need to carefully check the relevant configuration information to ensure the correctness of the interface.

The above is the detailed content of How to test QQ login in uniapp. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn