Skip to content

Instantly share code, notes, and snippets.

@zh99998
Last active December 14, 2015 22:49
Show Gist options
  • Save zh99998/5161113 to your computer and use it in GitHub Desktop.
Save zh99998/5161113 to your computer and use it in GitHub Desktop.
Work-around api for ucenter. Across the php we can reach every corner in the world!
<?php
include './config.inc.php';
include './uc_client/client.php';
$function = 'uc_'.$_REQUEST['action'];
if(function_exists($function)){
$paramters = json_decode($_REQUEST['paramters']);
if(UC_CHARSET != 'UTF-8'){
foreach($paramters as $index => $paramter){
if(is_string($paramter)){
$paramters[$index] = iconv("UTF-8", UC_CHARSET.'//IGNORE', $paramter);
}
}
}
$result = call_user_func_array($function, $paramters);
if(UC_CHARSET != 'UTF-8'){
foreach($result as $index => $item){
if(is_string($item)){
$result[$index] = iconv(UC_CHARSET, 'UTF-8//TRANSLIT', $item);
}
}
}
echo(json_encode($result));
}else{
header("Status: 404 Not Found");
echo("No such ucenter action: $_REQUEST[action]");
}
?>
module Ucenter
require 'net/http'
require 'json'
Wrapper = URI('http://ucenter-wrapper')
class <<self
def method_missing(method, *args)
res = Net::HTTP.post_form(Wrapper, 'action' => method, 'parameters' => args.to_json)
puts res.body
if res.body == 'null'
nil
else
JSON.parse res.body
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment