Ecshop微信第三方授权扫码登录接口文件源码
Freigeben: 2016-07-25 08:46:34
Original
2007 Leute haben es durchsucht
《实现微信第三方授权扫码登录》一文中tiandi简单的叙述了一下如何实现微信第三方授权登录Ecshop系统以及公布了核心代码,主要是修改了用户的登录判定,即user.php这个文件
-
/***************************/
- /* Wechat 登录 /
- /* by tiandi 2014.12.6 /
- /***************************/
-
- if (defined('WEBSITE') || defined('GETINFO'))
- {
- global $_LANG;
- $_LANG['help']['APP_KEY'] = '在微信开发者平台申请的AppID';
- $_LANG['help']['APP_SECRET'] = '在微信开发者平台申请的AppSecret';
-
- $_LANG['APP_KEY'] = 'AppID';
- $_LANG['APP_SECRET'] = 'AppSecret';
-
- $i = isset($web) ? count($web) : 0;
- // 类名
- $web[$i]['name'] = 'wechat';
- // 文件名,不包含后缀
- $web[$i]['type'] = 'wechat';
-
- $web[$i]['className'] = 'wechat';
-
- // 作者信息
- $web[$i]['author'] = 'tiandi';
-
- // 作者QQ
- $web[$i]['qq'] = '';
-
- // 作者邮箱
- $web[$i]['email'] = '';
-
- // 申请网址
- $web[$i]['website'] = 'http://open.weixin.qq.com';
-
- // 版本号
- $web[$i]['version'] = '1.0';
-
- // 更新日期
- $web[$i]['date'] = '2014-12-6';
-
- // 配置信息
- $web[$i]['config'] = array(
- array('type'=>'text' , 'name'=>'APP_KEY', 'value'=>''),
- array('type'=>'text' , 'name' => 'APP_SECRET' , 'value' => ''),
- );
- }
-
-
- if (!defined('WEBSITE'))
- {
- include_once(dirname(__FILE__).'/oath2.class.php');
- class website extends oath2
- {
- function website()
- {
- $this->app_key = APP_KEY;
- $this->app_secret = APP_SECRET;
-
- $this->scope = 'snsapi_login';
- //by tiandi authorizeURL是用来PHP打开微信登录时用,JS调用则不用authorizeURL。
- $this->authorizeURL = 'https://open.weixin.qq.com/connect/qrconnect';
-
- $this->tokenURL = 'https://api.weixin.qq.com/sns/oauth2/access_token';
- $this->refreshtokenURL = 'https://api.weixin.qq.com/sns/oauth2/refresh_token';
- $this->userURL = 'https://api.weixin.qq.com/sns/userinfo';
- $this->meth = 'GET';
- }
-
- function Code2Token($code)
- {
- $params = 'appid='.$this->app_key.'&secret='.$this->app_secret.'&code='.$code.
- '&grant_type=authorization_code';
- $tokenurl = $this->tokenURL."?". $params;
- $token = $this->http($tokenurl, 'GET');
- $token = json_decode($token , true);
- return $token;
- }
-
- function GetRefreshToken($token)
- {
- $params = 'appid='.$this->app_key.'&grant_type=refresh_token&refresh_token='.$token;
- $tokenurl = $this->refreshtokenURL."?". $params;
- $token = $this->http($tokenurl, 'GET');
- $token = json_decode($token , true);
- return $token;
- }
-
- function Getinfo($token,$openid)
- {
- $params = 'access_token='.$token.'&openid='.$openid;
- $userurl = $this->userURL."?". $params;
- $userinfo = $this->http($userurl, 'GET');
- return json_decode($userinfo , true);
- }
- }
- }
复制代码
|
Ecshop
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
Neueste Artikel des Autors
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31