austgl

微信公众平台搭建之二(手机号归属)
接上文,增加一个IP查询功能
调用新浪接口查IP,

function city_ip($ip) {
$url = \'http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=\' . $ip;
$f = new SaeFetchurl();
$str = $f->fetch($url);
preg_match(\'|var remote_ip_info =(.*)\;|\',$str,$ar);
$obj = json_decode($ar[1]);
$city =$obj->city;
return $city;
}

在responseMsg()函数中增加处理

if(!empty( $keyword ))
{
$msgType = "text";
$wel = "百度查正在为你服务,暂时只支持单词翻译及IP查询,手机号查询,支持日语,韩语译成中文。(以后会增加身份证等查询。)";
$format = "查ip 请用英文 ,+ip ;"."\n"."翻译单词请直接发送单词。"."\n"."查手机号归属地请用英文 .+手机号"."\n"."(例如: ,58.243.79.221 방귀 .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 == ",")
{
      $city_name = city_ip($key2);//用户发来的IP
      if($city_name !== "")
           $contentStr = $city_name;
       else 
          $contentStr = "未查到有关信息或输入有误!";
}
else 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;
}else{

下面是运行截图:

 

原帖地址:

http://www.austgl.com/b/thread-307-1-1.html

分类:

技术点:

相关文章:

  • 2021-12-27
  • 2021-07-28
  • 2022-03-06
  • 2021-05-23
  • 2021-12-07
猜你喜欢
  • 2022-02-07
  • 2022-12-23
  • 2021-11-25
  • 2021-06-15
  • 2021-12-15
  • 2021-09-20
相关资源
相似解决方案