Skip to content

Instantly share code, notes, and snippets.

@peter279k
Created June 26, 2016 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peter279k/f433dc6cc052e37199d50930dd66afa6 to your computer and use it in GitHub Desktop.
Save peter279k/f433dc6cc052e37199d50930dd66afa6 to your computer and use it in GitHub Desktop.
plurk for testing
<?php
set_time_limit(0);
function do_action($url,$new_parms=array()) {
$oauth_consumer_key = ""; //你的consumer_key talk
$oauth_consumer_secret = ""; //你的consumer_secret
$oauth_token = ""; //你的tokeny_key
$oauth_token_secret = ""; //你的token_secret
// global $oauth_consumer_key,$oauth_token,$oauth_consumer_secret,$oauth_token_secret;
$oauth_nonce = rand(10000000,99999999);
$oauth_timestamp = time();
$parm_array = array(
"oauth_consumer_key"=>$oauth_consumer_key,
"oauth_nonce"=>$oauth_nonce,
"oauth_consumer_key"=>$oauth_consumer_key,
"oauth_signature_method"=>"HMAC-SHA1",
"oauth_timestamp"=>$oauth_timestamp,
"oauth_token"=>$oauth_token,
"oauth_version"=>"2.0");
$parm_array = array_merge($parm_array,$new_parms);
$base_string = sort_data($parm_array);
$base_string = "POST&".rawurlencode($url)."&".rawurlencode($base_string);
$key = rawurlencode($oauth_consumer_secret)."&".rawurlencode($oauth_token_secret);
$oauth_signature = rawurlencode(base64_encode(hash_hmac("sha1",$base_string,$key,true)));
$parm_array = array_merge($parm_array,array("oauth_signature"=>$oauth_signature));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS,sort_data($parm_array));
$data = curl_exec($ch);
curl_close($ch);
return json_decode($data,TRUE);
}
function upload_img($url, $new_parms = array()) {
$oauth_consumer_key = ""; //你的consumer_key talk
$oauth_consumer_secret = ""; //你的consumer_secret
$oauth_token = ""; //你的tokeny_key
$oauth_token_secret = ""; //你的token_secret
// global $oauth_consumer_key,$oauth_token,$oauth_consumer_secret,$oauth_token_secret;
$oauth_nonce = rand(10000000,99999999);
$oauth_timestamp = time();
$parm_array = array(
"oauth_consumer_key"=>$oauth_consumer_key,
"oauth_nonce"=>$oauth_nonce,
"oauth_signature_method"=>"HMAC-SHA1",
"oauth_timestamp"=>$oauth_timestamp,
"oauth_token"=>$oauth_token,
"oauth_version"=>"1.0");
//$parm_array = array_merge($parm_array,$new_parms);
$base_string = sort_data($parm_array);
$base_string = "POST&".rawurlencode($url)."&".rawurlencode($base_string);
$key = rawurlencode($oauth_consumer_secret)."&".rawurlencode($oauth_token_secret);
$oauth_signature = rawurlencode(base64_encode(hash_hmac("sha1",$base_string,$key,true)));
$parm_array = array_merge($parm_array, array("oauth_signature"=>$oauth_signature));
//$parm_array["image"] = new CurlFile(realpath("./pass.jpg"), "image/jpeg");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: multipart/form-data'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, sort_data($parm_array));
echo $data = curl_exec($ch);
echo curl_error($ch);
curl_close($ch);
//return $data;
}
function sort_data($data) {
ksort($data);
$string="";
foreach($data as $key=>$val) {
if($string=="") {
$string = $key."=".$val;
}
else {
$string .= "&".$key."=".$val;
}
}
return $string;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment