QQ ??? PHP OAuth ?? ?? ??
Jul 29, 2016 am 08:46 AM?? ??? ?? ??
?? ?? ??? ??? ????
/**
* ?? http://connect.opensns.qq.com/apply
* ?? http://connect.opensns.qq.com/my
*/
session_start();
$qq_oauth_config = ??(
'oauth_consumer_key'=>'********',//? ID
'oauth_consumer_secret'=>'********* *********',//APP KEY
'oauth_callback'=>"http://www.955.cc/qq.php?action=reg",//這里修改為當(dāng)前腳本,但是要保留?action=reg
'oauth_request_token_url'=>"http://openapi.qzone.qq.com/oauth/qzoneoauth_request_token",
'oauth_authorize_url'=>'http:// openapi.qzone.qq.com/oauth/qzoneoauth_authorize',
'oauth_request_access_token_url'=>'http://openapi.qzone.qq.com/oauth/qzoneoauth_access_token',
'user_info_url' => http://openapi.qzone.qq.com/user/get_user_info',
);
$action = isset($_GET['action']) ? $_GET['action'] : '';
$qq = ??? qq_oauth($qq_oauth_config);
switch($action){
//?戶登錄 1??:請(qǐng)求臨時(shí)token
case 'login':
$token = $qq->oauth_request_token();
$_SESSION['oauth_token_secret'] = $token['oauth_token_secret'];
$qq->authorize($token['oauth_token']);
??; $access_token = $qq->request_access_token();
if($token = $qq->save_access_token($access_token)){
//保存, 一般發(fā)給用戶cookie,以及用戶入庫
//var_dump($token);
$_SESSION['oauth_token'] = $token['oauth_token'];
$_SESSION['oauth_token_secret'] = $token['oauth_token_secret'];
$_SESSION['openid'] = $token['openid'];
header('??? ??: ???/html; charset=utf-8');
$user_info = json_decode($qq->get_user_info());
if($user_info->ret!=0){
exit("獲取頭image昵稱時(shí)發(fā)生錯(cuò)誤".$user_info->msg);
} else {
echo 'QQ昵稱:',$user_info->nickname,
'',
'',
'' ;
}
}
??;
??? :
}
class qq_oauth{
private $config;
?? __construct($config){
$this->config = $config;
}
/**
* ?? ??
* @param string $name
*
*/
function C($name){
return isset($this->config[$name]) ? $this->config[$name] : ??;
}
/**
* ?? ?? URL
* @param string $url
* @param array $params
* @param string $oauth_token_secret
*
*/
function build_request_uri($url,$params=array(),$oauth_token_secret=''){
$oauth_consumer_key = $this->C ('oauth_consumer_key');
$oauth_consumer_secret = $this->C('oauth_consumer_secret');
$params = array_merge(array(
'oauth_version'=>'1.0',
'oauth_signature_method'=>'HMAC-SHA1',
'oauth_timestamp'=>time() ,
'oauth_nonce'=>rand(1000,99999999),
'oauth_consumer_key'=>$oauth_consumer_key,
),$params);
$encode_params = $params;
ksort($encode_params);
$oauth_signature = 'GET&'.urlencode($url).'&'.urlencode(http_build_query($encode_params));
$oauth_signature = base64_encode(hash_hmac('sha1',$oauth_signature,$oauth_consumer_secret.'&'.$oauth_token_secret,true));
$params['oauth_signature'] = $oauth_signature;
return $url.'?'.http_build_query($params);
}
/**
* ??? ??? ????? ????? ?????
*/
function check_callback(){
if(isset($_GET['oauth_token']))
if(isset($_GET[' openid']))
if(isset($_GET['oauth_signature']))
if(isset($_GET['timestamp']))
if(isset($_GET['oauth_vericode') ]))
true? ?????.
??? ?????.
}
function get_contents($url){
$curl = ?_init();
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl,CURLOPT_URL,$url);
curl_exec($curl)? ?????.
}
/**
* 1??: ?? ?? ??, 2??: ???? ?? ?? ?? ??
*/
function oauth_request_token(){
$url = $this->build_request_uri($this->C('oauth_request_token_url'));
$tmp_oauth_token = $this->get_contents($url);
parse_str($tmp_oauth_token);
/*
oauth_token 未授權(quán)?臨時(shí)??
oauth_token_secret ???密鑰,該密鑰僅限于臨時(shí)token
error_code 錯(cuò)誤碼
*/ (isset($error_code )) ??($error_code);
?? ??(
'oauth_token'=>$oauth_token,
'oauth_token_secret'=>$oauth_token_secret
);
}
/**
* 3??: ???? Qzone ??? ???? ??
* @param string $oauth_token ???? ?? ?? ??
*/
?? ??($oauth_token){
$str = "HTTP/1.1 302 ??"
??($str)
$url = $this->C('oauth_authorize_url');
$query_strings = http_build_query(array(
'oauth_consumer_key'=>$this->C('oauth_consumer_key'),
'oauth_token'= >$oauth_token,
'oauth_callback'=>$this->C('oauth_callback'),
))
header('??: '.$url.'?'.$ query_strings);
}
/**
* 4??: Qzone? ????? ?? ???????? ????? ?????.
* @return bool ???? ?????
*/
functionregister_user(){
/*
* oauth_token ?? ?? ??
* openid Tencent ??? ?? ?? ID, OpenID? ???? QQ ??
* oauth_signature ?? ?? ???? ????? ?3?? openid? ??? ???? ?? ??? ? ????.
* HMAC-SHA1 ???? ??:
* ?? ???: openid ?????(??? ??? ' ' ??? ???? ???)
* ?: oauth_consumer_secret
* ????? openid ?????
* oauth_vericode ?? ?? ?????.
*/
if($this->check_callback()){
//?? ??
$signature = base64_encode(hash_hmac('sha1',$_GET['openid'].$ _GET['timestamp'],$this->C('oauth_consumer_secret'),true))
if(!emptyempty($_GET['oauth_signature']) && $signature==$_GET['oauth_signature ' ]){
$_SESSION['oauth_token'] = $_GET['oauth_token'];
$_SESSION['oauth_vericode'] = $_GET['oauth_vericode']
??;
}
//?? ??
exit('UNKNOW REQUEST')
}
/**
* 5??: ??? ?? ??
*/
function request_access_token(){
$url = $this->build_request_uri($this->C('oauth_request_access_token_url'),array(
'oauth_token'=>$_SESSION['oauth_token'],
'oauth_vericode'=> ;$_SESSION ['oauth_vericode']
),$_SESSION['oauth_token_secret'])
return $this->get_contents($url)
}
/**
* 6??: ??? ?? ??(??? ?? ??)
*
* access_token ??
* ?? access_token(? ?? ??)? ???? ???? ?? openid? ??? ? ????. ?? ????? ???? ????. ???? openid ??? ?????.
* ??, ???? Qzone?? ?3?? ?? ??? ??? ? ?? ??? ??? ????. ?? access_token? ????? ?? ????? ???? ?? ?????? ???.
* ?? access_token? ???? ?? ???, ?? ???, ??? ??? ??? ??? ?? ???? ?? ??? ?????.
*/
function save_access_token($access_token_str){
parse_str($access_token_str,$access_token_arr);
if(isset($access_token_arr['error_code'])){
return FALSE;
$access_token_arr ??
}
}
/**
* ?? ?????? ? API? ???? ????.
* ???? ??? ?? ?? ??? ??? ???? ??? ??? ??? ? ????.
* http://openapi.qzone.qq.com/user/get_user_info
*/
function get_user_info(){
$url = $this->build_request_uri( $this- >C('user_info_url'),array(
'oauth_token'=>$_SESSION['oauth_token'],
'openid'=>$_SESSION['openid'],
), $_SESSION['oauth_token_secret']);
return $this->get_contents($url);
}
}
?? ??? ???? qq_php.rar
? ??? out QQ ??? PHP OAuth ?? ??? ???? ???, PHP ????? ??? ?? ????? ??? ??? ????.

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

PHP ?? ??? ?? ???? ?? ? ????? ??? ?????. 1. ?? ??? ??? ??? ??? ? ? ??? ??? ??? ?? ?? ??? ???? ???????. 2. ?? ??? ???? ???? ? ?? ????? ?? ?? ?? ??? ?????. 3. $ _get ? $ _post? ?? Hyperglobal ??? ?? ???? ?? ??? ? ??? ??? ??????? ???????. 4. ?? ?? ?? ???? ?? ?? ?? ??? ?????? ?? ??? ??? ?? ??? ???????. ??? ??? ????? ??? ??? ?? ???? ????? ? ??? ? ? ????.

PHP ?? ???? ???? ????? ?? ? ??? ???? ?? ?? ? ??? ???? ?? ??? ?????? ??? ??? ? ? ???????. 1. ??? ?? CSRF? ???? ?? ??? ??? ???? ?????? ??? ???? FINFO_FILE? ?? ?? MIME ??? ?????. 2. ??? ??? ??? ???? ??? ?? ??? ?? ? WEB ????? ??? ???? ??????. 3. PHP ?? ??? ?? ? ?? ???? NGINX/APACHE? ??? ????? ?? ???? ?????. 4. GD ?????? ??? ? ?? ???? ??? ?? ??? ?? ????.

PHP ?? ???? ? ?? ???? ??? ????. 1. // ?? #? ???? ? ?? ??? ???? // ???? ?? ????. 2. ?? /.../ ?? ?? ?? ??? ????? ?? ? ?? ??? ?? ? ? ????. 3. ?? ?? ?? / if () {} /? ?? ?? ??? ????? ??? ?? ?? ?? ??? ???? ????? ???? ??? ?? ???? ???? ??? ? ??? ??????.

PHP ??? ???? ??? ??? ??? ????? ????. ??? ????? ?? ???? ??? "?? ? ?"??? "?"? ???????. 1. ??? ? ??? ??? DocBlock (/*/)? ?? ?? ??? ???? ??? ? ?? ???? ??????. 2. JS ??? ???? ?? ???? ??? ?? ??? ??? ?????. 3. ??? ?? ?? ?? ??? ???? ????? ????? ???? ?? ????? ???? ? ??????. 4. Todo ? Fixme? ????? ???? ? ? ??? ??? ???? ?? ?? ? ??? ???????. ??? ???? ?? ??? ??? ?? ?? ?? ???? ???? ? ????.

Ageneratorinphpisamemory- ???? Way-Erate-Overgedatasetsetsbaluesoneatimeatimeatimeatimallatonce.1.generatorsuseTheyieldKeywordTocroadtOpvaluesondemand, RetingMemoryUsage.2

tolearnpheffectical, startBysetTupaloCalserErverEnmentUsingToolslikexamppandacodeeditor -likevscode.1) installxamppforapache, mysql, andphp.2) useacodeeditorforsyntaxsupport.3)) 3) testimplephpfile.next, withpluclucincludechlucincluclucludechluclucled

toinstallphpquickly, usexampponwindowsorhomebrewonmacos.1. ??, downloadandinstallxAmpp, selectComponents, startApache ? placefilesinhtdocs.2

PHP??? ???? ??? ?? ?? ????? ???? ??? ?? ??? ??? ?? ? ??? ??? ???? ?????. ???? 0?? ???? ?? ??? ???? ? ?? ???? ?? ?? ? ? ????. MB_SUBSTR? ?? ??? ??? ???????. ? : $ str = "hello"; echo $ str [0]; ?? H; ??? MB_SUBSTR ($ str, 1,1)? ?? ??? ??? ??? ??????. ?? ???????? ???? ??? ???? ?? ???? ?? ?? ???? ?????? ??? ????? ?? ??? ?? ??? ???? ???? ?? ????.
