微信公众平台体验之五(身份证查询)
微信公众平台搭建之三(Ip查询)
接上文
欢迎关注baiducha(baidu)
这次增加一个身份证号查询,
使用有道接口
function youdao_ID($word){
$ydapi = "http://www.youdao.com/smartresult-xml/search.s?jsFlag=true&type=id&q=".$word;
$fetch = new SaeFetchurl();
$content = $fetch->fetch($ydapi);
$content = iconv("GBK","UTF-8",$content);
$json = "/\'location\'\:\'(.*?)\'/";
preg_match_all($json,$content,$arr);
if(count($arr) > 1)
{
return $arr[1][0];
}else
{
return "请输入正确的身份证号!";
}
}
再在responseMsg()函数中修改下 对用户发来信息的处理,
public function responseMsg()
{
//get post data, May be due to the different environments
$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
//extract post data
if (!empty($postStr)){
$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
$fromUsername = $postObj->FromUserName;
$toUsername = $postObj->ToUserName;
$keyword = trim($postObj->Content);
$time = time();
$textTpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[%s]]></MsgType>
<Content><![CDATA[%s]]></Content>
<FuncFlag>0</FuncFlag>
</xml>";
if(!empty( $keyword ))
{
$msgType = "text";
$wel = "百度查正在为你服务,暂时只支持单词翻译及IP查询,支持日语,韩语译成中文。(以后会增加手机,身份证等查询。)";
$format = "查ip 请用英文 ,+ip ;"."\n"."翻译单词请直接发送单词。"."\n"."查手机号归属地请用英文 .+手机号"."\n"."身份证查询:用英文'+ID号码"."(例如: ,58.243.79.221 방귀 .15850781443 '330327199305087236)";
$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_ID($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{
echo "Input something...";
}
}else {
echo "";
exit;
}
}
效果在前面帖子中有截图了 ,这里就不贴了。。。
出自于新手之手,,有错误勿喷!!!!
原帖:http://www.austgl.com/b/thread-312-1-1.html