Phpcms V9 realize QQ landing OAuth2.0

Source: Internet
Author: User
Tags array connect openid php file domain name


PhpcmsV9 use of the QQ landing is still OAuth1.0, but now Tencent has not audited the use of OAuth1.0 's website. This is a huge pit for the webmaster who uses the PC. After the Phpcms forum of a classmate to do the plug-in to modify, now perfect QQ landing, no bug found.



Implementation steps:



① Open \phpcms\modules\member\index.php file, the following code to find a place to plug in (can be directly in the PC default QQ landing below).


  1. QQ Landing oAuth2.0

  2. ublic function public_qq_login2 () {

  3. $appid = pc_base::load_config (' System ', ' qq_appid ');

  4. $appkey = pc_base::load_config (' System ', ' Qq_appkey ');

  5. $callback = pc_base::load_config (' System ', ' qq_callback ');

  6. Pc_base::load_app_class (' qqOAuth2 ', ', ', 0);

  7. $info = new QqOAuth2 ($appid, $appkey, $callback);

  8. $this->_session_start ();

  9. if (!isset ($_get[' code ')) {

  10. $info->redirect_to_login ();

  11. }else{

  12. $code = $_get[' code '];

  13. $_session[' OpenID ' = $info->get_openid ($code);//To fetch the QQ OpenID value

  14. if (!emptyempty ($_session[' OpenID ')) {

  15. $r = $this->db->get_one (' Connectid ' =>$_session[' OpenID '), ' from ' => ' QQ ');

  16. if (!emptyempty ($r)) {

  17. QQ already exists in the database, then direct to the landing operation

  18. $password = $r [' Password '];

  19. $this->_init_phpsso ();

  20. $synloginstr = $this->client->ps_member_synlogin ($r [' phpssouid ']);

  21. $userid = $r [' userid '];

  22. $groupid = $r [' GroupID '];

  23. $username = $r [' username '];

  24. $nickname = Emptyempty ($r [' nickname '])? $username: $r [' nickname '];

  25. $this->db->update (Array (' Lastip ' =>ip (), ' lastdate ' =>sys_time, ' nickname ' => $me [' name ']), Array (' UserID ' => $userid));

  26. if (! $cookietime) $get _cookietime = Param::get_cookie (' cookietime ');

  27. $_cookietime = $cookietime? Intval ($cookietime): ($get _cookietime $get _cookietime:0);

  28. $cookietime = $_cookietime? Time + $_cookietime:0;

  29. $phpcms _auth_key = MD5 (pc_base::load_config (' System ', ' Auth_key '). $this->http_user_agent);

  30. $phpcms _auth = Sys_auth ($userid.) \ t ". $password, ' ENCODE ', $phpcms _auth_key);

  31. Param::set_cookie (' auth ', $phpcms _auth, $cookietime);

  32. Param::set_cookie (' _userid ', $userid, $cookietime);

  33. Param::set_cookie (' _username ', $username, $cookietime);

  34. Param::set_cookie (' _groupid ', $groupid, $cookietime);

  35. Param::set_cookie (' Cookietime ', $_cookietime, $cookietime);

  36. Param::set_cookie (' _nickname ', $nickname, $cookietime);

  37. $forward = Isset ($_get[' forward ']) &&!emptyempty ($_get[' forward '])? $_get[' forward ']: ' Index.php?m=member&c=index ';

  38. ShowMessage (L (' login_success '). $synloginstr, $forward);

  39. }else{

  40. Does not exist in the database, skip to refine the data page. Page preset username (QQ return is UTF8 code, if necessary for transcoding)

  41. $user = $info->get_user_info ();

  42. $_session[' connectid '] = $_session[' OpenID '];

  43. $_session[' from '] = ' QQ ';

  44. if (CHARSET!= ' utf-8 ') {//transcoding

  45. $connect _username = iconv (' Utf-8 ', CHARSET, $user [' nickname ']);

  46. }

  47. Include template (' member ', ' Connect ');

  48. }

  49. }

  50. }

  51. }


② put the attached qqOAuth2.class.php file in the \phpcms\modules\member\classes\ folder.



③ in the background to find connect settings, the QQ number landing callback address changed to Http://php100.com/index.php?m=member&c=index&a=public_qq_login2 (Change my domain name to your own)



④ fill in the app ID and app key, and then update the cache.



⑤ Login phpMyAdmin, locate the Connectid field (or custom field) of the V9_member table and change the type to "char (255)" Because the PHPCMS default is 15-bit. So we directly and completely modified into 255, this is no matter Tencent's other third party website accounts (such as Taobao, Alipay, Baidu,  and other third party accounts), can complete data binding. (This article added on July 27, by the Netizen liuyang814 sends the mail to remind)



Later, the code of Sina Weibo and Tencent Weibo will be put up. Phpcms's peripheral code is too few to find on the Internet.




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.