Ecshop WeChat third-party authorized scan code login interface file source code
Release: 2016-07-25 08:46:34
Original
1967 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
- /***************************/
- /* Wechat login/
- /* by tiandi 2014.12.6 /
- /***************************/
- if (defined('WEBSITE' ) || defined('GETINFO'))
- {
- global $_LANG;
- $_LANG['help']['APP_KEY'] = 'AppID applied on WeChat Developer Platform';
- $_LANG['help'] ['APP_SECRET'] = 'AppSecret applied on WeChat Developer Platform';
-
- $_LANG['APP_KEY'] = 'AppID';
- $_LANG['APP_SECRET'] = 'AppSecret';
-
- $i = isset ($web) ? count($web) : 0;
- // Class name
- $web[$i]['name'] = 'wechat';
- // File name, excluding suffix
- $web[$i ]['type'] = 'wechat';
-
- $web[$i]['className'] = 'wechat';
-
- // Author information
- $web[$i]['author'] = 'tiandi ';
-
- // Author QQ
- $web[$i]['qq'] = '';
-
- // Author's email
- $web[$i]['email'] = '';
-
- // Application URL
- $web[$i]['website'] = 'http://open.weixin.qq.com';
-
- // Version number
- $web[$i]['version'] = '1.0 ';
-
- // Update date
- $web[$i]['date'] = '2014-12-6';
-
- // Configuration information
- $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 is used when opening WeChat login with PHP, and authorizeURL is not used when calling JS.
- $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);
- }
- }
- }
Copy code
|
Ecshop
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
Latest Articles by Author
-
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