YzmCMS PHP轻量级信息管理系统 v6.9.zip

   日期:2024-12-21    作者:o93v3 浏览:77    移动:http://w.yusign.com/mobile/quote/2423.html
<?php // +---------------------------------------------------------------------- // | Site: [ http://www.yzmcms.com] // +---------------------------------------------------------------------- // | Copyright: 袁志蒙工作室,并保留所有权利 // +---------------------------------------------------------------------- // | Author: YuanZhiMeng <214243830@qq.com> // +---------------------------------------------------------------------- // | Explain: 这不是一个自由软件,您只能在不用于商业目的的前提下对程序代码进行修改和使用,不允许对程序代码以任何形式任何目的的再发布! // +---------------------------------------------------------------------- if ( ! class_exists( 'OAuthException')) { class OAuthException extends Exception { // pass } } class SaeTOAuthV2 { public $client_id; public $client_secret; public $access_token; public $refresh_token; public $http_code; public $url; public $host = "https://api.weibo.com/2/"; public $timeout = 30; public $connecttimeout = 30; public $ssl_verifypeer = FALSE; public $format = 'json'; public $decode_json = TRUE; public $http_info; public $useragent = 'Sae T OAuth2 v0.1'; public $debug = FALSE; public static $boundary = ''; function accessTokenURL() { return 'https://api.weibo.com/oauth2/access_token'; } function authorizeURL() { return 'https://api.weibo.com/oauth2/authorize'; } function __construct($client_id, $client_secret, $access_token = NULL, $refresh_token = NULL) { $this->client_id = $client_id; $this->client_secret = $client_secret; $this->access_token = $access_token; $this->refresh_token = $refresh_token; } function getAuthorizeURL( $url, $response_type = 'code', $state = NULL, $display = NULL ) { $params = array(); $params['client_id'] = $this->client_id; $params['redirect_uri'] = $url; $params['response_type'] = $response_type; $params['state'] = $state; $params['display'] = $display; return $this->authorizeURL() . "?" . http_build_query($params); } function getAccessToken( $type = 'code', $keys = array() ) { $params = array(); $params['client_id'] = $this->client_id; $params['client_secret'] = $this->client_secret; if ( $type === 'token' ) { $params['grant_type'] = 'refresh_token'; $params['refresh_token'] = $keys['refresh_token']; } elseif ( $type === 'code' ) { $params['grant_type'] = 'authorization_code'; $params['code'] = $keys['code']; $params['redirect_uri'] = $keys['redirect_uri']; } elseif ( $type === 'password' ) { $params['grant_type'] = 'password'; $params['username'] = $keys['username']; $params['password'] = $keys['password']; } else { throw new OAuthException("wrong auth type"); } $response = $this->oAuthRequest($this->accessTokenURL(), 'POST', $params); $token = json_decode($response, true); if ( is_array($token) && !isset($token['error']) ) { $this->access_token = $token['access_token']; //$this->refresh_token = $token['refresh_token']; } else { throw new OAuthException("get access token failed." . $token['error']); } return $token; } function parseSignedRequest($signed_request) { list($encoded_sig, $payload) = explode('.', $signed_request, 2); $sig = self::base64decode($encoded_sig) ; $data = json_decode(self::base64decode($payload), true); if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') return '-1'; $expected_sig = hash_hmac('sha256', $payload, $this->client_secret, true); return ($sig !== $expected_sig)? '-2':$data; } function base64decode($str) { return base64_decode(strtr($str.str_repeat('=', (4 - strlen($str) % 4)), '-_', '+/')); } function getTokenFromJSSDK() { $key = "weibojs_" . $this->client_id; if ( isset($_COOKIE[$key]) && $cookie = $_COOKIE[$key] ) { parse_str($cookie, $token); if ( isset($token['access_token']) && isset($token['refresh_token']) ) { $this->access_token = $token['access_token']; $this->refresh_token = $token['refresh_token']; return $token; } else { return false; } } else { return false; } } function getTokenFromArray( $arr ) { if (isset($arr['access_token']) && $arr['access_token']) { $token = array(); $this->access_token = $token['access_token'] = $arr['access_token']; if (isset($arr['refresh_token']) && $arr['refresh_token']) { $this->refresh_token = $token['refresh_token'] = $arr['refresh_token']; } return $token; } else { return false; } }
本文地址:http://w.yusign.com/quote/2423.html    述古往 http://w.yusign.com/static/ , 查看更多

特别提示:本信息由相关用户自行提供,真实性未证实,仅供参考。请谨慎采用,风险自负。


举报收藏 0评论 0
0相关评论
相关行情
推荐行情
点击排行
{
网站首页  |  关于我们  |  联系方式  |  用户协议  |  隐私政策  |  版权声明  |  网站地图  |  排名推广  |  广告服务  |  积分换礼  |  网站留言  |  RSS订阅  |  违规举报  |  鄂ICP备2020018471号