$sim = new Simsimi(array('sid' => $sid, 'datapath' => $dir . 'sim_', 'proxy' => 'http://173.193.200.199:3128')); function rjson($msg, $status = 0) { $r = array('info' => $msg, 'status' => $status); die(json_encode($r)); } if (isset($_POST['content'])) { $content = trim($_POST['content']); if (!$content) { rjson('请输入正确的内容'); } $result = $sim->talk($content); if ($result) { rjson($result, 1); } else { rjson('我不知道你想表达什么', 1); } } $simready = $sim->init(); ?> <!DOCTYPE html> <html> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link href="http://dodgepudding.github.io/webex/example/css/bootstrap.css" rel="stylesheet"> <link href="http://dodgepudding.github.io/webex/example/css/bootstrap-responsive.css" rel="stylesheet"> <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script> <script src="http://code.jquery.com/jquery-migrate-1.1.1.min.js"></script> <script src="http://dodgepudding.github.io/webex/compile.min.js"></script> <title>聊天机器人</title>
<?php include "../simsimi.class.php"; $sid = $_REQUEST['sid'] ? trim($_REQUEST['sid']) : getenv('REMOTE_ADDR'); $sid = md5($sid); $content = $_REQUEST['msg'] ? trim($_REQUEST['msg']) : ''; $dir = '../data/' . substr($sid, -1) . '/'; @mkdir($dir, 0777, true); $sim = new Simsimi(array('sid' => $sid, 'datapath' => $dir . 'sim_', 'proxy' => 'http://173.193.200.199:3128')); function rjson($msg, $status = 0) { $r = array('info' => $msg, 'status' => $status); die(json_encode($r)); } if (!$content) { rjson('error'); } $result = $sim->talk($content); if ($result) { rjson($result, 1); } else { rjson('failed'); }