header("Content-Type:text/html;charset=UTF-8");
function nowapi_call($a_parm){
if(!is_array($a_parm)){
return false;
}
//combinations
$a_parm['format']=empty($a_parm['format'])?'json':$a_parm['format'];
$apiurl=empty($a_parm['apiurl'])?'http://api.k780.com/?':$a_parm['apiurl'].'/?';
unset($a_parm['apiurl']);
foreach($a_parm as $k=>$v){
$apiurl.=$k.'='.$v.'&';
}
$apiurl=substr($apiurl,0,-1);
if(!$callapi=file_get_contents($apiurl)){
return false;
}
//format
if($a_parm['format']=='base64'){
$a_cdata=unserialize(base64_decode($callapi));
}elseif($a_parm['format']=='json'){
if(!$a_cdata=json_decode($callapi,true)){
return false;
}
}else{
return false;
}
//array
if($a_cdata['success']!='1'){
echo $a_cdata['msgid'].' '.$a_cdata['msg'];
return false;
}
return $a_cdata['result'];
}
$nowapi_parm['app']='weather.future';
$nowapi_parm['weaId']='1';
$nowapi_parm['appkey']='APPKEY';
$nowapi_parm['sign']='SIGN';
$nowapi_parm['format']='json';
$result=nowapi_call($nowapi_parm);
var_dump($result);
print_r($result);
#python
import json,urllib
from urllib import urlencode
url = 'http://api.k780.com'
params = {
'app' : 'weather.future',
'weaId' : '1',
'appkey' : 'APPKEY',
'sign' : 'SIGN',
'format' : 'json',
}
params = urlencode(params)
f = urllib.urlopen('%s?%s' % (url, params))
nowapi_call = f.read()
#print content
a_result = json.loads(nowapi_call)
if a_result:
if a_result['success'] != '0':
print a_result['result'];
else:
print a_result['msgid']+' '+a_result['msg']
else:
print 'Request nowapi fail.';
import java.net.*;
import java.io.*;
public class test{
public static void main(String args[]) throws Exception {
URL u=new URL("http://api.k780.com/?app=weather.future&weaId=1&appkey=APPKEY&sign=SIGN&format=json");
InputStream in=u.openStream();
ByteArrayOutputStream out=new ByteArrayOutputStream();
try {
byte buf[]=new byte[1024];
int read = 0;
while ((read = in.read(buf)) > 0) {
out.write(buf, 0, read);
}
} finally {
if (in != null) {
in.close();
}
}
byte b[]=out.toByteArray( );
System.out.println(new String(b,"utf-8"));
}
}
curl "http://api.k780.com/?app=weather.future&weaId=1&appkey=APPKEY&sign=SIGN&format=json"