支付宝授权登录

where(array('receipt_code_no'=>$_GET['receipt_code_no']))->find();
            $employInfo = M('h_company_employee')->where(array('receipt_code_no'=>trim($_GET['receiptCodeNo']),'company_id'=>$_GET['companyId']))->find();
            $this -> assign('companyId',I("get.companyId"));
            $this -> assign('qrCodeType',I("get.qrCodeType"));
            $this -> assign('companyName',I("get.companyName"));
            if(empty($employInfo)){

                $this -> assign('employeeId','');
                $this -> assign('name',$_GET['receiptCodeNo']);
                $this -> assign('mobile', '');
                $this -> assign('receiptCodeNo',I("get.receiptCodeNo"));

            }else{


                $this -> assign('employeeId',$employInfo['id']);
                $this -> assign('name',$employInfo['name']);
                $this -> assign('mobile', $employInfo['mobile']);
                $this -> assign('receiptCodeNo',I("get.receiptCodeNo"));
            }
            cookie("companyId",I("get.companyId"),"/");
            cookie("employeeId",$employInfo['id'],"/");
            cookie("qrCodeType",I("get.qrCodeType"),"/");
            cookie("companyName",I("get.companyName"),"/");
            cookie("name",$employInfo['name'],"/");
            cookie("mobile",$employInfo['mobile'],"/");
            cookie('receiptCodeNo',I("get.receiptCodeNo"),"/");

        }else{
            cookie("companyId",I("get.companyId"),"/");
            cookie("employeeId",I("get.employeeId"),"/");
            cookie("qrCodeType",I("get.qrCodeType"),"/");
            cookie("companyName",I("get.companyName"),"/");
            cookie("name",I("get.name"),"/");
            cookie("mobile",I("get.mobile"),"/");
            cookie('receiptCodeNo',I("get.receiptCodeNo"),"/");
        }

        $_GET['is_cover'] = 1;
        if(empty($_COOKIE['ali_userid'])){

            $appid ='201xxxxxxxxxxxxx';
            //$appid = '2018121xxxxxxxxxxxxxxxxxxxxxxxxxx';
            $url=C("red_url").'index.php/Home/Axxxxxxxxxxxxxxxxxxxx';
            $redirect_uri = urlencode($url);
            //静默状态scope就用auth_base  用户感知就用 auth_user
            $url ='https://openauth.alipay.com/oauth2/publicxxxxxxxxxxxxxxxxx?app_id='.$appid.'&scope=auth_user&redirect_uri='.$redirect_uri;

            header("Location:".$url);
        }else{

            $this->receive();
        }

    }

    //支付宝跳转
    public  function   receive(){

   //echo 333333;;exit;
        if(empty(cookie('ali_userid'))) {


            header("Content-type:text/html;charset=utf-8");
            //引入的SDK

            vendor('alipay.AopSdk');

            vendor('alipay.aop.AopClient');

            vendor('alipay.aop.request.AlipaySystemOauthTokenRequest');
            vendor('alipay.aop.request.AlipayUserUserinfoShareRequest');

            $code = $_GET['auth_code'];
            //var_dump($_GET);
            //EXIT;
            //APPID
            $appid = $_GET['app_id'];

            //私钥  文件名(rsa_private_key.pem)
            $rsaPrivateKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxgSlAgEAAoIBAQDzhWyGpvEPxA/fX67D+M1X5q5/hcKkGpCRJxxxxxxxxxxxxxxxxxxxxxxxxYpis/j716d6QkfE4Xmq1THTvXns38wAVDXHeXOf4XcRibo1CO0HcJbj5LCv84sIu/ZszyrPC93mDz7gu4o0P3s1ddHaEzVtNfMCyYGSP96hslXTR1IgW5uK94CXe5+sn6rwk3bE3cUZ6UzMXbDyLUEMasFHubiTAkq5RVXwg/78pZa1m/vspqwF45fetsK1xfYSFcsryH6J5kUorjUKLtQJWoWjbw3iCXZE4w+TYaiMen1tAYLP5yzc51/o2faPJ6DAgMBAAECggEBAOWSd/As+37Ib8o+MsyvBi6C2yh/GjKIlJcwEtgdh7ZLKtw5PzOWWMrwsRXd8yd06WrOXuiFqeHATMcxYVQ6bJ/XLAsOw10MrrusNQRzqpXGe442KoZAB0z084uLrs8tFxxxxxxxxxxxxxxxxxnympO1Fuv2ZqOvnMm+v5rp9eSz3Jeh4YF1vGVWqH3TEOFRflpm7KdVtibGLQH6CHbBma6OHWsgFxLG5/q7VaS2ZJXnrjW9V6DjNmd0/hXl/CkbSwx8Bqh+gstAQnECgYEA/sRUrWL5yRZqUYWsLvZgKfs8uGolwqHYd1hM6cmfDM/1BzXTojmJ5MrzFEV3jgfhyyh8E+70IbrtWDWxP5WBQFkqkT+wjDTsQGPnP7TrJKiiojTxY2wMHcU5IfCGiN5N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JlyBR9vdQKBgQDq9nAFaj25CRYhzQNsN7x7cu1oC81A/Kjaqir6hwoaotsvWHrYWPijKybJs5rrdWJSmtNNx0J1uUU67tK8ycYh9C7QGT95eXiMSR1BPVuCB//sNgaS8GR99uwiIoIMVgaq3k/hwD3HENvp+X3NG0k+vr07wDr3VuZPPSvy+6GHzg==";
            //公钥  文件名 (rsa_public_key.pem)
            $alipayrsaPublicKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/wbHQZfOs5C6rsZ8xgxTR3e5591f84fAPnUeEx33N83b4O1Hijtct5pyqD8UaHbmPb6dWGxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxdPq5YAOTytHtGsOcGIeuvpMnwfaJsfH4zUfcagZX5036hv3xms/2ULpD0qfwYtHTC81agG4r+N7ZGWEMsOUyQ6p8VU3JusCQcvRujg6JMj6uXmbyn08rP2jYv4PS4+DOZ2VMhYshhPsoK2J2ytZruVTTAbHpqmxxxxxxxxxxxxxxxxxxxeXmLhZFULDQIDAQAB";
            //$alipayrsaPublicKey ="MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAp+wYFPwILwnhKlZvTcOvLikVbbR1w2QeIBuDjwex/uRxYAMibErrYfqIMaoqwE71QzlX5JbId8ZrRlg+Jj6QtOo7PuvWgXNOtG7WO6a6DUgdNQAH8zUwcD0En7h2MckdGVNiBpg3vQW2OCJPzoNt95AlpqElr4GnxirY/CqG2vtG2UdpA1xbYYZqmEaAd6AQMk9hiB45gdrOnxJo6Gc3j6ernqU4F0boRNMgeUR+G893HW5gFs6PwkzSfVgY/iL0UtmCcMgJfSQW+HA7m5s5SrcOiVg52miv/02OxvuTr73PMa34jskZfN0TLUkIJ59GJUDzOqzqG2ROmzirSVfBgQIDAQAB";

            //初始化
            $aop = new \AopClient();
            $aop->gatewayUrl = 'https://openapi.alipxxxxxxxxxxxxxxxxx';
            $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);//这里传入 code

            $result = $aop->execute($request);
            //echo 123123;
            //exit;
            $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
            //       var_dump($result);exit;//静默状态下,到此就可以结束了
            $access_token = $result->$responseNode->access_token;

            //获取用户信息
            $request_a = new \AlipayUserInfoShareRequest();
            $result_a = $aop->execute($request_a, $access_token); //这里传入获取的access_token
            $responseNode_a = str_replace(".", "_", $request_a->getApiMethodName()) . "_response";
            $user_id = $result_a->$responseNode_a->user_id;   //用户唯一id

            if (empty($user_id)) {
                die("");
            }
            // var_dump($user_id);
            $headimgurl = $result_a->$responseNode_a->avatar;   //用户头像
            $nick_name = $result_a->$responseNode_a->nick_name;    //用户昵称

            $ali_info = M('k_member')->where(['ali_userid' => $user_id])->find();
            if ($ali_info) {
                M('k_member')->where('ali_userid',$user_id)->save([ 'member_head_img' => $headimgurl, 'member_nick_name' => $nick_name]);
            } else {
              //  echo $user_id;
                M('k_member')->add(['ali_userid' => $user_id, 'member_head_img' => $headimgurl, 'member_nick_name' => $nick_name]);
            }

            cookie('ali_userid', $user_id);
            cookie('ali_nickname', $nick_name);
            cookie('ali_headimgurl', $headimgurl);
        }
        $url = C('red_ip').'/company/background/image?companyId='.cookie("companyId");
        $resultimg = sqcurl($url,'get',[],array());
        file_put_contents('/hl/logrrr.txt',print_r($resultimg,true),FILE_APPEND);
        $this->assign("resultimg",json_decode($resultimg,true));
        $this->assign("result",'');
        $this -> assign('companyId',cookie("companyId"));
        $this -> assign('employeeId',cookie("employeeId"));
        $this -> assign('qrCodeType',cookie("qrCodeType"));
        $this -> assign('companyName',cookie("companyName"));
        $this -> assign('name',cookie("name"));
        $this -> assign('mobile',cookie("mobile"));
        $this -> assign('receiptCodeNo',cookie("receiptCodeNo"));
        $this->display('PaymentCode/paykeyboard');
    }

}

你可能感兴趣的:(php)