Ecshop微信第三方授权扫码登录接口文件源码

WBOY
Freigeben: 2016-07-25 08:46:34
Original
1925 Leute haben es durchsucht
《实现微信第三方授权扫码登录》一文中tiandi简单的叙述了一下如何实现微信第三方授权登录Ecshop系统以及公布了核心代码,主要是修改了用户的登录判定,即user.php这个文件
  1. /***************************/
  2. /* Wechat 登录 /
  3. /* by tiandi 2014.12.6 /
  4. /***************************/
  5. if (defined('WEBSITE') || defined('GETINFO'))
  6. {
  7. global $_LANG;
  8. $_LANG['help']['APP_KEY'] = '在微信开发者平台申请的AppID';
  9. $_LANG['help']['APP_SECRET'] = '在微信开发者平台申请的AppSecret';
  10. $_LANG['APP_KEY'] = 'AppID';
  11. $_LANG['APP_SECRET'] = 'AppSecret';
  12. $i = isset($web) ? count($web) : 0;
  13. // 类名
  14. $web[$i]['name'] = 'wechat';
  15. // 文件名,不包含后缀
  16. $web[$i]['type'] = 'wechat';
  17. $web[$i]['className'] = 'wechat';
  18. // 作者信息
  19. $web[$i]['author'] = 'tiandi';
  20. // 作者QQ
  21. $web[$i]['qq'] = '';
  22. // 作者邮箱
  23. $web[$i]['email'] = '';
  24. // 申请网址
  25. $web[$i]['website'] = 'http://open.weixin.qq.com';
  26. // 版本号
  27. $web[$i]['version'] = '1.0';
  28. // 更新日期
  29. $web[$i]['date'] = '2014-12-6';
  30. // 配置信息
  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是用来PHP打开微信登录时用,JS调用则不用authorizeURL。
  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. }
复制代码
Ecshop


Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!