zoukankan      html  css  js  c++  java
  • C# 开发AliYun(阿里云) 小蜜调用接口代码

    using System;
    using System.Collections.Generic;
    using Aliyun.Acs.Core;
    using Aliyun.Acs.Core.Exceptions;
    using Aliyun.Acs.Core.Profile;
    using Aliyun.Acs.Chatbot.Model.V20171011;
    using Newtonsoft.Json;
    
    namespace ChatbotDemo
    {
        class Program
        {
            static void Main(string[] args)
            {
                while (true)
                {
                    string txt = Console.ReadLine();
                    string msg = null;
    
                IClientProfile profile = DefaultProfile.GetProfile("cn-shanghai", "<accessKeyId>", "<accessSecret>");
                DefaultAcsClient client = new DefaultAcsClient(profile);
    
                    var request = new ChatRequest();
                    //request.SenderNick = "1";
                    //request.SenderId = "3";
                    //request.KnowledgeId = "2";
                    //request.SessionId = "1";
                    request.Utterance = txt;
                    request.InstanceId = "chatbot-cn-mp913ow5";//你的机器人id
                    try
                    {
                        var response = client.GetAcsResponse(request);
                        if (response == null)
                        {
                            msg = "请求失败:response不能为空";
                        }
                        else
                        {
                            msg = $"小蜜:{response.Messages[0].Text.Content}" +
                                $"{System.Environment.NewLine}";
                        }
    
                    }
                    catch (ServerException e)
                    {
                        msg = $"ServerException:{e}";
                    }
                    catch (ClientException e)
                    {
                        msg = $"ClientException:{e}";
                    }
    
                    Console.WriteLine(msg);
                }
    
            }
        }
    }
  • 相关阅读:
    Python IDLE快捷键一览
    面试题——中
    面试题——君
    面试题——太(下)
    面试题——2面常见问题
    MYSQL数据库设计规范与原则
    字符串操作
    集合
    java-数组
    java异常处理机制
  • 原文地址:https://www.cnblogs.com/0to9/p/10788029.html
Copyright © 2011-2022 走看看