首页 > Windows开发 > 详细

C# 开发AliYun(阿里云) 小蜜调用接口代码

时间:2019-04-29 01:19:13      阅读:388      评论:0      收藏:0      [点我收藏+]
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);
            }

        }
    }
}

 

C# 开发AliYun(阿里云) 小蜜调用接口代码

原文:https://www.cnblogs.com/0to9/p/10788029.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!