<?php
Class getapimodel{//get third-party APIs
Get ID Information
Return JSON
/*
{
"Errnum": 0,
"Retmsg": "Success",
"Retdata": {
"Sex": "M",//m-Male, F-female, N-unknown
"Birthday": "1987-04-20",//date of birth
"Address": "Hubei Province Xiaogan Hanchuan"//ID card belongs to the city/county
}
}*/
Public Function Getidnumberinfo ($apikey, $idNumber) {
$ch = Curl_init ();
$url = ' http://apis.baidu.com/apistore/idservice/id?id= '. $idNumber;
$header = Array (
' Apikey: '. $apikey
);
Add Apikey to Header
curl_setopt ($ch, Curlopt_httpheader, $header);
Executing an HTTP request
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, Curlopt_returntransfer, 1);
curl_setopt ($ch, Curlopt_ssl_verifypeer, false);
$res = curl_exec ($ch);
Curl_close ($ch);
Return Json_decode ($res, true);
}
Get Weather information
Return JSON
/*
{
errnum:0,
ErrMsg: "Success",
Retdata: {
City: "Beijing",//Cities
Pinyin: "Beijing",//city Pinyin
Citycode: "101010100",//City code
Date: "15-02-11",//Date
Time: "11:00",//release date
Postcode: "100000",//ZIP code
longitude:116.391,//Longitude
latitude:39.904,//dimension
Altitude: "33",//Altitude
Weather: "Sunny",//weather conditions
Temp: "10",//temperature
L_tmp: "-4",//minimum temperature
H_tmp: "10",//maximum temperature
WD: "No continuous wind Direction",//Wind Direction
WS: "Breeze (<10m/h)",//Wind
Sunrise: "07:12",//Sunrise time
Sunset: "17:44"//Sunset Time
}
}*/
Public Function GetWeather ($apikey, $ADSTRR) {
$ch = Curl_init ();
$url = ' http://apis.baidu.com/apistore/weatherservice/weather?citypinyin= '. $ADSTRR;
$header = Array (
' Apikey: '. $apikey
);
Add Apikey to Header
curl_setopt ($ch, Curlopt_httpheader, $header);
Executing an HTTP request
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, Curlopt_returntransfer, 1);
curl_setopt ($ch, Curlopt_ssl_verifypeer, false);
$res = curl_exec ($ch);
Curl_close ($ch);
Return Json_decode ($res, true);
}
}
PHP Free API call, using (CURL)