PHP implementation of QQ Login development tutorial

Source: Internet
Author: User

Third-party login, is to use people familiar with such as QQ, Weibo and other third-party software to login to their own site, which can be removed from the registration account, the purpose of fast retention of users, eliminating the relatively complex registration process. The bottom is to tell you how to use PHP to develop QQ login features.

1, enter the QQ Internet website to log in (can use their own QQ or re-register a QQ number as our project to manage the individual QQ), Address: https://connect.qq.com/

2, click "Application Management" into the QQ Internet Management Center, where the creation of relevant applications, divided into Web applications and mobile applications. Choose the application you want to fill in the information (audit needs to wait about 7 days), audit through you will get the app ID

and App Key, please take a little notebook to remember! Please take a note of the Little notebook! Please take a note of the Little notebook! (important thing to say three times!!!)

  3, audit by obtaining the relevant interface: Get_user_info.

4, download QQ Interconnection related demo Http://wiki.connect.qq.com/sdk%E4%B8%8B%E8%BD%BD I downloaded the PHP SDK v2.1

5, carefully observe the SDK we will find it contains 4 folders, 2 files, the most important of which is the API folder, the rest I think can be ignored (you see nothing), follow this document step-by-step, you can implement the login function.

6, the API folder copy to your project, as for the copy to the project of which folder, as long as you can introduce on the line, look at your mood to be able to prepare well, the next is to write code.

---------------------------------------------------a gorgeous, yet still-angry split line---------------------------------------------------------

7. Open the API folder you copied to the project, there is a Comm folder, open the Comm again you can see a guy named inc.php, open it! Fill in the relevant position with the AppID and Appkey, which are recorded on your laptop, in the approximate form.  

<?php die (' forbidden ');?>
{"AppID": "Your AppID", "Appkey": "Your Appkey", "Callback": "Your site callback domain", "scope": "Get_user_info"}

8, the code is as follows

  

<?PHP/** * Created by Phpstorm. * User:qichao * date:2018/1/31 * Time: PM 7:22*/namespace Wechat\controllers; UseWechat\common\basecontroller;require(__dir__. ‘/.. /tools/api/qqconnectapi.php ');//introduced the QQ Interconnect SDK, which was introduced in accordance with the path of my own project. classQqlogincontrollerextendsbasecontroller{//Login Method     Public functionActionqqlogin () {$QC=New\QC (); $QC-Qq_login (); }    //This method is when you through the success of the QQ login want to jump back to the address, such as you want to log in after the success of the jump to Baidu, then you can change the following to Baidu Link!      Public functionActioncallback () {Header("content-type:text/html; Charset=utf-8 "); /*
Here please according to your project development needs (such as access to login user's nickname, Avatar, age, etc.), the development of relevant code, specific data acquisition method, please check the QQ Internet documentation$QC=New\QC (); $access _token=$QC-Qq_callback (); $openid=$QC-Get_openid (); */ $url= "Http://wechat.xxx.cn/index.php?r=cms/home"; Header("Location:".)$url); Exit(); }}

At this point, your entire process is gone, simple!!! The entire feature flow is similar:

If you encounter the following issues during the development process:

File_get_contents (): Unable to find the wrapper &quot;https&quot; -Did you forget to enable it when do you configured PHP?

The reason for this error is simple,the encryption module in the PHP configuration is not open

Solution:1.  (windows)php.ini config file, navigate to the position shown in blue, put extension=php_openssl.dll front ; semicolon Remove

Remove the subsequent restart of Apache or nginx Server, and then access, there will be no such error.

2. Linux under the PHP, you must install the OpenSSL module, the installation is ready to access.

If you have problems in the development process, please leave a message or add me QQ: 1193553883

This article original, reproduced please leave a message

PHP implementation of QQ Login development tutorial

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.