AI编程助手
AI免费问答

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

PHP中文网   2016-05-26 08:20   2010浏览 原创

[PHP]代码 

<?php  
/***************************/
/* Wechat 登录              /
/* by tiandi 2014.12.6      /
/***************************/  

if (defined(&#39;WEBSITE&#39;) || defined(&#39;GETINFO&#39;))
{
	global $_LANG;
	$_LANG[&#39;help&#39;][&#39;APP_KEY&#39;] = &#39;在微信开发者平台申请的AppID&#39;;
	$_LANG[&#39;help&#39;][&#39;APP_SECRET&#39;] = &#39;在微信开发者平台申请的AppSecret&#39;;
	
	$_LANG[&#39;APP_KEY&#39;] = &#39;AppID&#39;;
	$_LANG[&#39;APP_SECRET&#39;] = &#39;AppSecret&#39;;
	
	$i = isset($web) ? count($web) : 0;
	// 类名
	$web[$i][&#39;name&#39;] = &#39;wechat&#39;;
	// 文件名,不包含后缀
	$web[$i][&#39;type&#39;] = &#39;wechat&#39;;
	
	$web[$i][&#39;className&#39;] = &#39;wechat&#39;;
	
	// 作者信息
	$web[$i][&#39;author&#39;] = &#39;tiandi&#39;;
	
	// 作者QQ
	$web[$i][&#39;qq&#39;] = &#39;&#39;;
	
	// 作者邮箱
	$web[$i][&#39;email&#39;] = &#39;&#39;;
	
	// 申请网址
	$web[$i][&#39;website&#39;] = &#39;http://open.weixin.qq.com&#39;;
	
	// 版本号
	$web[$i][&#39;version&#39;] = &#39;1.0&#39;;
	
	// 更新日期
	$web[$i][&#39;date&#39;]  = &#39;2014-12-6&#39;;
	
	// 配置信息
	$web[$i][&#39;config&#39;] = array(
		array(&#39;type&#39;=>'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);
		}
	}
}

                   

                   

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。