search
Homephp教程PHP源码Ecshop微信第三方授权扫码登录接口文件源码

[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;=>&#39;text&#39; , &#39;name&#39;=>&#39;APP_KEY&#39;, &#39;value&#39;=>&#39;&#39;),
		array(&#39;type&#39;=>&#39;text&#39; , &#39;name&#39; => &#39;APP_SECRET&#39; , &#39;value&#39; => &#39;&#39;),
	);
}


if (!defined(&#39;WEBSITE&#39;))
{
	include_once(dirname(__FILE__).&#39;/oath2.class.php&#39;);
	class website extends oath2
	{
		function website()
		{
			$this->app_key = APP_KEY;
			$this->app_secret = APP_SECRET;
			
			$this->scope = &#39;snsapi_login&#39;;
			//by tiandi authorizeURL是用来PHP打开微信登录时用,JS调用则不用authorizeURL。
			$this->authorizeURL = &#39;https://open.weixin.qq.com/connect/qrconnect&#39;;

			$this->tokenURL = &#39;https://api.weixin.qq.com/sns/oauth2/access_token&#39;;
			$this->refreshtokenURL = &#39;https://api.weixin.qq.com/sns/oauth2/refresh_token&#39;;
			$this->userURL = &#39;https://api.weixin.qq.com/sns/userinfo&#39;;
			$this->meth = &#39;GET&#39;;
		}

		function Code2Token($code)
		{
			$params  = &#39;appid=&#39;.$this->app_key.&#39;&secret=&#39;.$this->app_secret.&#39;&code=&#39;.$code.
				&#39;&grant_type=authorization_code&#39;;
			$tokenurl = $this->tokenURL."?". $params;
			$token = $this->http($tokenurl, &#39;GET&#39;);
			$token = json_decode($token , true);
			return $token;
		}

		function GetRefreshToken($token)
		{
			$params  = &#39;appid=&#39;.$this->app_key.&#39;&grant_type=refresh_token&refresh_token=&#39;.$token;
			$tokenurl = $this->refreshtokenURL."?". $params;
			$token = $this->http($tokenurl, &#39;GET&#39;);
			$token = json_decode($token , true);
			return $token;
		}
		
		function Getinfo($token,$openid)
		{
			$params = &#39;access_token=&#39;.$token.&#39;&openid=&#39;.$openid;
			$userurl = $this->userURL."?". $params;
			$userinfo = $this->http($userurl, &#39;GET&#39;);
			return json_decode($userinfo , true);
		}
	}
}

                   

                   

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment