微信公衆平臺消息接口開發(27)彩票查詢

微信公衆平臺開發 微信公衆平臺開發者 微信公衆平臺開發模式 彩票查詢接口
做者:http://www.cnblogs.com/txw1958/
原文:http://www.cnblogs.com/txw1958/archive/2013/04/13/weixin-if27-lottery.html html

 

1、獲取數據json

目前不少網站都提供彩票信息查詢,因此取得彩票數據是件很容易的事。
方倍工做室開發出彩票查詢接口 API,目前已開通'雙色球','3D','七樂彩','大樂透','七星彩','排列3','排列5','勝負彩','六場半全場','四場進球' 10種數據,每日同步更新api

使用方式爲直接在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操做,不用本身再添加)app

{
    "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;
}

 

三,效果演示
   網站

 

4、試用帳號ui

 

相關文章
相關標籤/搜索