<?php
class GetApiModel{//获取第三方API
//获取身份证信息
//返回json
/*
{
"errNum": 0,
"retMsg": "success",
"retData": {
"sex": "M", //M-男,F-女,N-未知
"birthday": "1987-04-20", //出生日期
"address": "湖北省孝感市汉川市" //身份证归属地 市/县
}
}*/
public function getIdNumberInfo($apikey,$idNumber){
$ch = curl_init();
$url = ‘http://apis.baidu.com/apistore/idservice/id?id=‘.$idNumber;
$header = array(
‘apikey:‘.$apikey
);
// 添加apikey到header
curl_setopt($ch, CURLOPT_HTTPHEADER , $header);
// 执行HTTP请求
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);
}
//获取天气信息
//返回json
/*
{
errNum: 0,
errMsg: "success",
retData: {
city: "北京", //城市
pinyin: "beijing", //城市拼音
citycode: "101010100", //城市编码
date: "15-02-11", //日期
time: "11:00", //发布时间
postCode: "100000", //邮编
longitude: 116.391, //经度
latitude: 39.904, //维度
altitude: "33", //海拔
weather: "晴", //天气情况
temp: "10", //气温
l_tmp: "-4", //最低气温
h_tmp: "10", //最高气温
WD: "无持续风向", //风向
WS: "微风(<10m/h)", //风力
sunrise: "07:12", //日出时间
sunset: "17:44" //日落时间
}
}*/
public function getWeather($apikey,$adstrr){
$ch = curl_init();
$url = ‘http://apis.baidu.com/apistore/weatherservice/weather?citypinyin=‘.$adstrr;
$header = array(
‘apikey:‘.$apikey
);
// 添加apikey到header
curl_setopt($ch, CURLOPT_HTTPHEADER , $header);
// 执行HTTP请求
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);
}
}