一、獲取數據
目前很多網站都提供彩票信息查詢,所以取得彩票數據是件很容易的事。
方倍工作室開發出彩票查詢接口 API,目前已開通'雙色球','3D','七樂彩','大樂透','七星彩','排列3','排列5','勝負彩','六場半全場','四場進球' 10種數據,每日同步更新
使用方式為直接在URL中提交彩票名稱即可,名稱需要先做urlencode
調用url方法:以下是調用雙色球方法
http://api2.sinaapp.com/search/lottery/?appkey=0020130430&appsecert=fa6095e113cd28fd&reqtype=text&keyword=%e5%8f%8c%e8%89%b2%e7%90%83
返回格式如下:(返回中自帶換行\n操作,不用自己再添加)
{
"errcode": 0,
"msgtype": "text",
"text": {
"content": "雙色球\n第2013041期\n開獎時間 2013-04-11\n開獎號碼 02-10-12-17-23-24-05"
}
}
一個完整的請求類似如下:
//以發送 “彩票雙色球” 為例
$lotteryArray = array('雙色球','3D','七樂彩','大樂透','七星彩','排列3','排列5','勝負彩','六場半全場','四場進球');
if(substr($keyword,0,6) == "彩票" && strlen($keyword) > 6){
$content = trim(substr($keyword, 6, strlen($keyword)));
if (in_array($content, $lotteryArray)) {
$apihost = "http://api2.sinaapp.com/";
$apimethod = "search/lottery/?";
$apiparams = array('appkey'=>"0020130430", 'appsecert'=>"fa6095e113cd28fd", 'reqtype'=>"text");
$apikeyword = "&keyword=".urlencode($content);
$apicallurl = $apihost.$apimethod.http_build_query($apiparams).$apikeyword;
$apiJsonInfo = file_get_contents($apicallurl);
$apiInfo = json_decode($apiJsonInfo, true);
$contentStr = $apiInfo['text']['content'];
} else {
$contentStr = "抱歉,暫不支持該彩種!";
}
return $contentStr;
}
三,效果演示

