• 支付宝生活号授权获取用户信息


    1.第一步在蚂蚁开放平台注册申请应用上线

    2.下载支付宝秘钥生成器,生成秘钥(加在代码里面)和公钥(填写到蚂蚁开放平台)下载sdk放到extend文件夹里面

    3.引用SDK

    //头部加上
    use thinkLoader;
    header("Content-type:text/html;charset=utf-8");
    Loader::import('alipay.AopSdk', EXTEND_PATH);

    4.访问方法拼写授权地址

    $encoded_url = 回调地址;
    $appid = APPID;
    $code_url = "https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=$appid&scope=auth_user&redirect_uri=".urlencode($encoded_url);//获取auth_code
    $this->redirect($code_url);

    5.获取用户信息

    $code = $_GET['auth_code'];
            //APPID
            $appid = '支付宝平台的appid';
            //应用私钥  文件名(rsa_private_key.pem)
            $rsaPrivateKey = "应用秘钥";
            //支付宝公钥  文件名 (rsa_public_key.pem)
            $alipayrsaPublicKey = "支付宝公钥";
            //初始化
            $aop = new AopClient ();
            $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
            $aop->appId = $appid;
            $aop->rsaPrivateKey = $rsaPrivateKey;
            $aop->alipayrsaPublicKey = $alipayrsaPublicKey;
            $aop->apiVersion = '1.0';
            $aop->signType = 'RSA2';
            $aop->postCharset='UTF-8';
            $aop->format='json';
            //获取access_token
            $request = new AlipaySystemOauthTokenRequest();
            $request->setGrantType("authorization_code");
            $request->setCode($code);
            $result = $aop->execute($request);
            $access_token = $result->alipay_system_oauth_token_response->access_token;
            //获取用户信息
            $request_a = new AlipayUserinfoShareRequest();
            $result_a = $aop->execute ($request_a,'authusrB4d426f65fc0f4a1299ac3e6cc48ffX00');
            //这里传入获取的access_token
            $responseNode_a = str_replace(".", "_", $request_a->getApiMethodName()) . "_response";
            $user_id = $result_a->$responseNode_a->user_id;
            //用户唯一id
            $headimgurl = $result_a->$responseNode_a->avatar;
            //用户头像
            $nick_name = $result_a->$responseNode_a->nick_name;
            //用户昵称
            var_dump($user_id);
            var_dump($headimgurl);
            var_dump($nick_name);
            var_dump($result_a->$responseNode_a);
            die;
  • 相关阅读:
    angular.isDefined()
    angular.isDate()
    angular.isArray()
    .NET中栈和堆的比较
    SQL Server 2012配置Always On可用性组
    一分钟了解负载均衡的一切
    C# 线程并发锁
    获取Http请求参数
    什么是WCF
    Bitmap算法应用
  • 原文地址:https://www.cnblogs.com/notesbooks/p/9728966.html
Copyright © 2020-2023  润新知