相关动态
【免费】YzmCMS轻量级开源CMSV7.1免费下载
2025-01-02 20:51
<?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 = ''; public $postdata,$remote_ip,$http_header; 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();
    以上就是本篇文章【【免费】YzmCMS轻量级开源CMSV7.1免费下载】的全部内容了,欢迎阅览 ! 文章地址:http://sjzytwl.xhstdz.com/quote/86689.html 
     栏目首页      相关文章      动态      同类文章      热门文章      网站地图      返回首页 物流园资讯移动站 http://sjzytwl.xhstdz.com/mobile/ , 查看更多   
发表评论
0评