>  기사  >  백엔드 개발  >  Ecshop微信第三方授权扫码登录接口文件源码

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

WBOY
WBOY원래의
2016-07-25 08:46:341927검색
《实现微信第三方授权扫码登录》一文中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


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.