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

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

29158 23

实现微信第三方授权扫码登录》一文中tiandi简单的叙述了一下如何实现微信第三方授权登录Ecshop系统以及公布了核心代码,主要是修改了用户的登录判定,即user.php这个文件。

本文作为上一文的补充,上文提到过,另外还需要修改模板文件和接口文件。这里的模板文件主要是增加了微信用户对老用户的绑定操作,如果您不需要做绑定操作,那么可以不改模板文件,如果您需要增加这一功能的话,tiandi也帮不上您的忙,每个人的模板都不同,只能自己改自己的咯。并且在上文提到的修改user.php的代码里也请省略下面一段,这一段只对绑定用户起作用。

/* by tiandi 微信绑定用户  从这里开始到结尾都可以不用加*/   
elseif($action == 'wechatbd') {
   ...
}

下面是微信接口的源码,应该是无需更改,直接可以调用。

<?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);
		}
	}
}
文章评分13次,平均分3.3

本文原始地址:https://www.tiandiyoyo.com/2015/01/wechat_interface_for_ecshop/
本站所有文章,除了特别注明外,均为本站原创,转载请注明出处来自www.tiandiyoyo.com

您可能还会对以下文章感兴趣:

评论前先开启评论开关:


23 Comments

  1. lihua :

    版主怎么联系,ecshop二次开发想找你,我qq1668828928

  2. 您好~user_passport 里面的链接应该怎么写呢

  3. 时代风 :

    include_once(dirname(__FILE__).’/oath2.class.php’);
    这个文件里面是什么

  4. 顶了再看再学 :

    state 的生成, 和 $_REQUEST[‘state’] 判断该怎么写呢?

    • tiandi :

      随机生成,然后返回时检查返回的值是不是和你生成的值一致即可。

      • 顶了再看再学 :

        感谢,大清早的回复! 鞠躬!

        我还有个问题想问你。我现在已经能够支付(浪费了我好多时间,其实很简单,新版的Demo些得很不清楚),也写好了接收notify的函数,(按照文档里的要求:“商户后台系统需回复接收情况,通知微信后台系统不再发送该单的支付通知。”)里面最后是返回echo给微信的消息,告知
        $notifyReply->SetReturn_code(“SUCCESS”);
        $notifyReply->SetReturn_msg(“OK”);
        $notifyReply->ReplyNotify(true);

        不知如何确认,这个ReplyNotify是否成功?

        我登陆了下支付商户平台,好像没这个信息。
        或者这个根本就不是问题。。。。

        • tiandi :

          光看代码看不出这个函数怎么来的,文档里写了接收成功就返回SUCCESS给微信就行了,其他不用管了。

    • 能不能把这个思路或者代码让我看看呢 谢谢

  5. devil :

    请问一下这文件的内容是什么呢 includes/website/jntoo.php

  6. devil :

    请问上面那段代码是放在哪里的呢?

  7. wzn :

    请问一下微信的相关文件哪里找官网我看了 没有,我想知道dirname(__FILE__).’/oath2.class.php’和includes/website/jntoo.php这个文件是从哪里找的 方便能发个看看吗

  8. 楼主,这个插件能否完整的提供,给报酬。

  9. Faris :

    不错的说,不过微信这个东西,我始终不认为会长久

载入分页评论...