PHP Free API call, using (CURL)

Source: Internet
Author: User
Tags sunrise time

<?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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.