如何给网站设置一个机器人客服

``博主在鼎食城设计时突发奇想在软件中加如一个机器人客服,于是便百度了一下相关接口,找到了一个叫做图灵机器人的网站,申请创建即可:
这是网站:图灵机器人

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>聊天窗口</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0" />
    <link rel="stylesheet" href="./css/style.css" media="screen" type="text/css" />
    <link rel="stylesheet" href="./css/bootstrap.min.css">
    <script src="./js/jquery-1.9.1.min.js"></script>
    <script src="./js/bootstrap.min.js"></script>
</head>

<body>
    <div id="convo" data-from="Sonu Joshi">
        <ul class="chat-thread">
            <li class="left">找我干啥呢?亲</li>
        </ul>
        <div class="formstyle">
            <form class="bs-example bs-example-form" role="form">
                <div class="input-group input-group-lg">
                    <input type="text" class="form-control" placeholder="点击输入">
                    <span id="button" class="input-group-addon">发送</span>
                </div>
                <br>
                <input type="text" style="display:none;">
            </form>
        </div>
    </div>
    <div style="text-align:center;margin:50px 0; font:normal 14px/24px 'MicroSoft YaHei';">
    </div>
</body>

</html>
<script>
$('#button').click(function() {
    var form_val = $('.form-control').val();
    $('.chat-thread').append('<li class="right">' + form_val + '</li>');
    $('.form-control').val('');

    $.post("./api.php", { info: form_val }, function(data) {
        $('.chat-thread').append('<li class="left">' + data + '</li>');
        $('.chat-thread').scrollTop($('.chat-thread')[0].scrollHeight);
    });

    $('.chat-thread').scrollTop($('.chat-thread')[0].scrollHeight);
});

var height = $(window).height() * 0.8;
$('.chat-thread').css('height', height);
</script>

在这里插入图片描述

<?php  
date_default_timezone_set("PRC"); 
$info = $_POST['info'];
$userid = '546975';
$apiKey="5a5d2163a26f4a43a73e43ae946304cc"; //你的appkey 换成你自己图灵api的key
$apiURL="http://www.tuling123.com/openapi/api?key=$apiKey&info=$info&userid=$userid";
$res=file_get_contents($apiURL);

$res_list=json_decode($res,true);

echo $res_list['text'];


//写入文件
$myfile = fopen("note.txt", "a+") or die("Unable to open file!");
$txt = $info.' '.date("Y-m-d H:i:s",time())."\r\n";
fwrite($myfile, $txt);

fclose($myfile);

?> 

发布了61 篇原创文章 · 获赞 149 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/pengxiang1998/article/details/103950375