<?php
header("Content-type: text/html; charset=utf-8");
//图灵的API_KEY 请自己去图灵机器人官方网站去注册申请一个账号,获取属于你自己的API_KEY替换进去吧。
define(KEY, "bad38ba658622caef62828496c662135");
$getMessage = $_GET["message"];
$userId = $_GET["userId"];
if ($userId == "") {//用户ID 不能为空
$userId = 0;
}
//图灵接口
$tulingApiUrl = 'http://www.tuling123.com/openapi/api?key=' . KEY . '&userid=' . $userId . '&info=';
$html = '额~ ';
//发送get请求
try {
$text = file_get_contents($tulingApiUrl . urlencode($getMessage));
$result = json_decode($text);
switch ($result->code) {
case 100000 :
//文字类型数据
$html = $result -> text;
break;
case 200000 :
//链接类型数据
$html = $result -> text . ": </br> " . "<a style=\"color='#000000';\" href=\"" . $result -> url . "\"> ---点击进入---</a>";
break;
default :
//其他类型数据 暂不解析
$html = "你这么问我,我也不知道怎么回答哦~";
break;
}
} catch(Exception $e) {
//返回数据
$html = '哎呀!我不知道!我什么也不知道~ ';
}
echo $html;
?>
网页智能聊天机器人(基础版)源代码
5星 · 超过95%的资源 需积分: 37 192 浏览量
2014-11-19
21:37:37
上传
评论 22
收藏 4KB ZIP 举报
大大花猫
- 粉丝: 41
- 资源: 10
- 1
- 2
- 3
- 4
- 5
前往页