Home > Backend Development > PHP Tutorial > Ecshop WeChat third-party authorized scan code login interface file source code

Ecshop WeChat third-party authorized scan code login interface file source code

WBOY
Release: 2016-07-25 08:46:34
Original
2009 people have browsed it
In the article "Achieving WeChat Third-Party Authorized Scan Code Login", Tiandi briefly described how to implement WeChat third-party authorized login to the Ecshop system and published the core code, which mainly modified the user's login determination, that is, the file user.php
  1. /***************************/
  2. /* Wechat login/
  3. /* by tiandi 2014.12.6 /
  4. /***************************/
  5. if (defined('WEBSITE' ) || defined('GETINFO'))
  6. {
  7. global $_LANG;
  8. $_LANG['help']['APP_KEY'] = 'AppID applied on WeChat Developer Platform';
  9. $_LANG['help'] ['APP_SECRET'] = 'AppSecret applied on WeChat Developer Platform';
  10. $_LANG['APP_KEY'] = 'AppID';
  11. $_LANG['APP_SECRET'] = 'AppSecret';
  12. $i = isset ($web) ? count($web) : 0;
  13. // Class name
  14. $web[$i]['name'] = 'wechat';
  15. // File name, excluding suffix
  16. $web[$i ]['type'] = 'wechat';
  17. $web[$i]['className'] = 'wechat';
  18. // Author information
  19. $web[$i]['author'] = 'tiandi ';
  20. // Author QQ
  21. $web[$i]['qq'] = '';
  22. // Author's email
  23. $web[$i]['email'] = '';
  24. // Application URL
  25. $web[$i]['website'] = 'http://open.weixin.qq.com';
  26. // Version number
  27. $web[$i]['version'] = '1.0 ';
  28. // Update date
  29. $web[$i]['date'] = '2014-12-6';
  30. // Configuration information
  31. $web[$i]['config'] = array(
  32. array('type'=>'text' , 'name'=>'APP_KEY', 'value'=>''),
  33. array('type'=>'text' , 'name' = > 'APP_SECRET' , 'value' => ''),
  34. );
  35. }
  36. if (!defined('WEBSITE'))
  37. {
  38. include_once(dirname(__FILE__).'/oath2.class. php');
  39. class website extends oath2
  40. {
  41. function website()
  42. {
  43. $this->app_key = APP_KEY;
  44. $this->app_secret = APP_SECRET;
  45. $this->scope = 'snsapi_login' ;
  46. //by tiandi authorizeURL is used when opening WeChat login with PHP, and authorizeURL is not used when calling JS.
  47. $this->authorizeURL = 'https://open.weixin.qq.com/connect/qrconnect';
  48. $this->tokenURL = 'https://api.weixin.qq.com/sns/ oauth2/access_token';
  49. $this->refreshtokenURL = 'https://api.weixin.qq.com/sns/oauth2/refresh_token';
  50. $this->userURL = 'https://api.weixin. qq.com/sns/userinfo';
  51. $this->meth = 'GET';
  52. }
  53. function Code2Token($code)
  54. {
  55. $params = 'appid='.$this->app_key.' &secret='.$this->app_secret.'&code='.$code.
  56. '&grant_type=authorization_code';
  57. $tokenurl = $this->tokenURL."?". $params;
  58. $token = $this ->http($tokenurl, 'GET');
  59. $token = json_decode($token , true);
  60. return $token;
  61. }
  62. function GetRefreshToken($token)
  63. {
  64. $params = 'appid=' .$this->app_key.'&grant_type=refresh_token&refresh_token='.$token;
  65. $tokenurl = $this->refreshtokenURL."?". $params;
  66. $token = $this->http($tokenurl, 'GET');
  67. $token = json_decode($token , true);
  68. return $token;
  69. }
  70. function Getinfo($token,$openid)
  71. {
  72. $params = 'access_token='.$token.' &openid='.$openid;
  73. $userurl = $this->userURL."?". $params;
  74. $userinfo = $this->http($userurl, 'GET');
  75. return json_decode($userinfo , true);
  76. }
  77. }
  78. }
Copy code
Ecshop


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template