PHP实现微信开放平台扫码登录源码下载

PHP实现微信开放平台扫码登录源码下载

最新教程PHP实现微信开放平台扫码登录源码下载

淘建站为您提供更多_微信_登录_下载,在此特别感谢您对我们的支持与厚爱!

加入收藏

下载 265 次

下载资源

34 积分

特别说明:本站资源来自网友发布分享,仅供学习与参考,请勿用于商业用途,若有侵权请联系删除(272966172@qq.com)。
分类:PHP功能模块 > 微信 难易程度:

1、首先到微信开放平台申请http://open.weixin.qq.com/ 获取到appid和APPSECRET,前台显示页面如下

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="content-type" content="text/html;charset=utf-8">
    </head>
    <body>
        <span id="login_container"></span>
        <script src="http://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js"></script>
        <script>
            var obj = new WxLogin({
              id: "login_container",
              appid: "wxed782be999f86e0e",
              scope: "snsapi_login",
              redirect_uri: encodeURIComponent("http://" + window.location.host + "/login.php"),
              state: Math.ceil(Math.random()*1000),
              style: "black",
              href: ""});
        </script>
    </body>
</html>

2、PHP处理代码页面

/*
    require_once('weixin.class.php');
    $weixin = new class_weixin();
*/

define('APPID',		"wx19ba77624e083e08");
define('APPSECRET',	"c1a56a5c4247dd44c320c9719c5ceb90");

class class_weixin
{
    var $appid = APPID;
    var $appsecret = APPSECRET;

    //构造函数,获取Access Token
    public function __construct($appid = NULL, $appsecret = NULL)
    {
        if($appid && $appsecret){
            $this->appid = $appid;
            $this->appsecret = $appsecret;
        }

		//扫码登录不需要该Access Token, 语义理解需要
        //1. 本地写入 
        $res = file_get_contents('access_token.json');
        $result = json_decode($res, true);
        $this->expires_time = $result["expires_time"];
        $this->access_token = $result["access_token"];

        if (time() > ($this->expires_time + 3600)){
            $url = "http://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$this->appid."&secret=".$this->appsecret;
            $res = $this->http_request($url);
            $result = json_decode($res, true);
            $this->access_token = $result["access_token"];
            $this->expires_time = time();
            file_put_contents('access_token.json', '{"access_token": "'.$this->access_token.'", "expires_time": '.$this->expires_time.'}');
        }
    }

    /*
    *  PART1 网站应用
    */

	/*
	header("Content-type: text/html; charset=utf-8");
	require_once('wxopen.class.php');
	$weixin = new class_weixin();
	if (!isset($_GET["code"])){
		$redirect_url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
		$jumpurl = $weixin->qrconnect($redirect_url, "snsapi_login", "123");
		Header("Location: $jumpurl");
	}else{
		$oauth2_info = $weixin->oauth2_access_token($_GET["code"]);
		$userinfo = $weixin->oauth2_get_user_info($oauth2_info['access_token'], $oauth2_info['openid']);
		var_dump($userinfo);
	}
	*/
	//生成扫码登录的URL
    public function qrconnect($redirect_url, $scope, $state = NULL)
    {
        $url = "http://open.weixin.qq.com/connect/qrconnect?appid=".$this->appid."&redirect_uri=".urlencode($redirect_url)."&response_type=code&scope=".$scope."&state=".$state."#wechat_redirect";
		return $url;
    }

    //生成OAuth2的Access Token
    public function oauth2_access_token($code)
    {
        $url = "http://api.weixin.qq.com/sns/oauth2/access_token?appid=".$this->appid."&secret=".$this->appsecret."&code=".$code."&grant_type=authorization_code";
        $res = $this->http_request($url);
        return json_decode($res, true);
    }

    //获取用户基本信息(OAuth2 授权的 Access Token 获取 未关注用户,Access Token为临时获取)
    public function oauth2_get_user_info($access_token, $openid)
    {
        $url = "http://api.weixin.qq.com/sns/userinfo?access_token=".$access_token."&openid=".$openid."&lang=zh_CN";
        $res = $this->http_request($url);
        return json_decode($res, true);
    }

声明:本资料由淘建站会员提供,如转载注明来源,资料来源淘建站免费素材库:https://www.taojz.cn/mokuai/1034.html
PHP实现微信开放平台扫码登录源码下载 希望对你有帮助,感谢您的支持!
  • 最新实用的微信H5手机网站支付源码实例

    最新实用的微信H5手机网站支付源码实例

  • 2017最新微信公众号支付源码演示下载

    2017最新微信公众号支付源码演示下载

  • 最新支付宝即时到账退款接口源码演示下载

    最新支付宝即时到账退款接口源码演示下载

  • 2017年最新PHP整合银联在线支付DEMO演示下载

    2017年最新PHP整合银联在线支付DEMO演示下载

  • 2017最新支付宝PC端支付接口源码演示下载

    2017最新支付宝PC端支付接口源码演示下载

  • 2017最新微信朋友圈装逼神器源码演示下载

    2017最新微信朋友圈装逼神器源码演示下载

  • PHP实现微信兼容支付宝wap支付demo

    PHP实现微信兼容支付宝wap支付demo

  • PHP微信柏拉图性格标签生成器源码

    PHP微信柏拉图性格标签生成器源码

  • 漂亮实用的PHP发邮件功能源码下载

    漂亮实用的PHP发邮件功能源码下载

  • php经典实例图片的等比缩放和Logo水印源码免费下载

    php经典实例图片的等比缩放和Logo水印源码免费下载

  • PHP实现微信分享朋友圈demo源码

    PHP实现微信分享朋友圈demo源码

  • 2017最新微信自定义分享朋友源码演示下载

    2017最新微信自定义分享朋友源码演示下载

  • 留言(0)
    头像
     阿里云限量代金券,戳我领取
    1 2