php实现paypal 授权登录,php实现paypal授权
php实现paypal 授权登录
<?php /** * @project paypal login * @author jiangjianhe * @date 2015-04-03 */ class paypallogin { //沙箱token链接 private $_sanbox_oauth2_auth_uri = 'https://www.sandbox.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize'; private $_live_oauth2_auth_uri = 'https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize'; private $_acquire_user_profile_sandbox_url = 'https://www.sandbox.paypal.com/webapps/auth/protocol/openidconnect/v1/userinfo?schema=openid&access_token='; private $_acquire_user_profile_live_url = 'https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/userinfo?schema=openid&access_token='; //沙箱token链接 private $_token_service_sandbox_url = 'https://www.sandbox.paypal.com/webapps/auth/protocol/openidconnect/v1/tokenservice'; private $_token_service_live_url = 'https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/tokenservice'; private $_sanbox_flag = true; private $_client_id = null; private $_client_secret = null; private $_redirect_uri = null; private $_state = ''; private $_scope = 'openid email phone profile address https://uri.paypal.com/services/paypalattributes'; //scope 参数决定访问令牌的访问权限 各个参数详解url;:https://www.paypal-biz.com/product/login-with-paypal/index.html#configureButton public $token = null; public $protocol = "http"; /** * @name 构造函数 * @param $flag 是否沙箱环境 */ public function __construct($redirect_uri, $client_id,$client_secret,$scope,$state,$flag = true) { $this->_sanbox_flag = $flag; $this->_redirect_uri = $redirect_uri; $this->_client_id = $client_id; $this->_client_secret = $client_secret; $this->_scope = $scope; $this->_state = $state; } /** * 创建paypal request url * @return string */ public function create_request_url() { $oauth2_auth_uri = $this->_sanbox_flag ? $this->_sanbox_oauth2_auth_uri :$this->_live_oauth2_auth_uri; $url = $oauth2_auth_uri.'?'. http_build_query( array( 'client_id' => $this->_client_id, //通过应用程序注册流程获得的唯一客户端标识符。必需。 'response_type' =>'code', //表明授权代码被发送回应用程序返回URL。为了使访问令牌在用户代理中不可见, 建议使用<code>code</code>一值。如果您希望在响应中同时收到授权代码和 id_token ,请传递 code+id_token。另一个可能的 response_type 值是 token ——大部分由javascript和移动客户端等公共客户端使用。 'scope' => $this->_scope,//;implode(',', $this->scope), 'redirect_uri' => urlencode($this->_redirect_uri), //应用程序的返回URL。结构、主机名和端口必须与您在注册应用程序时设置的返回URL相符。 'nonce' => time().rand(), //不透明的随机标识符,可减少重放攻击风险。简单的函数是:(timestamp + Base64 encoding (random\[16\]))。 'state' => $this->_state, // CSRF验证码 ) ); return $url; } /** * get PayPal access token * @param string $code ? * @return string access token */ public function acquire_access_token($code ) { $accessToken = null; try { $postvals = sprintf("client_id=%s&client_secret=%s&grant_type=authorization_code&code=%s",$this->_client_id,$this->_client_secret,$code); if($this->_sanbox_flag) $ch = curl_init($this->_token_service_sandbox_url); else $ch = curl_init($this->_token_service_live_url); $options = array( CURLOPT_POST => 1, CURLOPT_VERBOSE => 1, CURLOPT_POSTFIELDS => $postvals, CURLOPT_RETURNTRANSFER => 1, CURLOPT_SSL_VERIFYPEER => FALSE, //CURLOPT_SSLVERSION => 2 ); curl_setopt_array($ch, $options); $response = curl_exec($ch); $error = curl_error($ch); curl_close( $ch ); if (!$response ) { throw new Exception( "Error retrieving access token: " . curl_error($ch)); } $jsonResponse = json_decode($response ); if ( isset( $jsonResponse->access_token) ) { $accessToken = $jsonResponse->access_token; } } catch( Exception $e) { throw new Exception($e->getMessage(), 1); } return $accessToken; } /** * get the PayPal user profile, decoded * @param string $accessToken * @return object */ public function acquire_paypal_user_profile($accessToken ) { try { if($this->_sanbox_flag) $url = $this->_acquire_user_profile_sandbox_url . $accessToken; else $url = $this->_acquire_user_profile_live_url . $accessToken; $ch = curl_init( $url ); $options = array( CURLOPT_RETURNTRANSFER => 1, CURLOPT_SSL_VERIFYPEER => FALSE, //CURLOPT_SSLVERSION => 2 ); curl_setopt_array($ch, $options); $response = curl_exec($ch); $error = curl_error( $ch); curl_close( $ch ); if (!$response ) { return false; } return json_decode($response); } catch( Exception $e ) { return false; } } } ?>
以上所述就是本文的全部内容了,希望大家能够喜欢。

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

在PHP中,可以利用implode()函数的第一个参数来设置没有分隔符,该函数的第一个参数用于规定数组元素之间放置的内容,默认是空字符串,也可将第一个参数设置为空,语法为“implode(数组)”或者“implode("",数组)”。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

Dreamweaver CS6
視覺化網頁開發工具

禪工作室 13.0.1
強大的PHP整合開發環境

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

Atom編輯器mac版下載
最受歡迎的的開源編輯器