接上篇,增加一个手机归属查询。
公众账号:
baiducha
下面是使用淘宝提供的接口查询手机号归属:
- function taobao_m($word){
- $tmapi = “http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=“.$word;
- $fetch = new SaeFetchurl();
- $content = $fetch->fetch($tmapi);
- $content = iconv(“gb18030”,“UTF-8”,$content);
- $jso1 = “/province:\’(.*)\’\,/“;
- $jso2 = “/catName:\’(.*)\’\,/“;
- preg_match_all($jso1,$content,$arr1);
- preg_match_all($jso2,$content,$arr2);
- if(count($arr1) > 1){
- return $arr1[1][0].“\n”.$arr2[1][0];
- }else
- return “请重新输入电话号码!”;
- }
在 responseMsg()函数中对发过来的信息加以处理 部分代码如下:
- if(!emptyempty( $keyword ))
- {
- $msgType = “text”;
- $wel = “百度查正在为你服务,暂时只支持单词翻译,支持日语,韩语译成中文。(增加手机号归属地。)”;
- $format = “翻译单词请直接发送单词。”.“\n”.“查手机号归属地请用英文 .+手机号”.“\n”.“(例如: 방귀 .15850781443 )”;
- $contentStr = $wel.“\n\n”.$format;
- if($keyword == “h” || $keyword == “Hello2BizUser”)
- {
- $contentStr = $format;
- }
- else
- {
- $key1 = substr($keyword,0,1);
- $key2 = substr($keyword,1);
- if($key1 == “.” || $key1 == “。”)
- $contentStr = taobao_m($key2);
- else if($key1 != “,” && $key1 != “.”)
- $contentStr = youdao($keyword);//用户发来的词汇
- else
- $contentStr = $wel.“\n\n”.$format;
- }
- $contentStr .= “\n发送h,查看使用帮助”;
- $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
- echo $resultStr;