android图灵机器人教程,简单的调用图灵机器人

publicTuLingTest()

{

InitializeComponent();

}private ActionShowMsg;private void TuLingTest_Load(objectsender, EventArgs e)

{

ShowMsg= new Action((string msg) =>{if (Txt_Msg.TextLength > 30000) Txt_Msg.Clear();

Txt_Msg.AppendText("\r\n-------当前时间" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "---------------------------------"

+ "\r\n图灵机器人回复:" + msg + "\r\n");

Txt_Msg.ScrollToCaret();

});

}private async void Btn_start_Click(objectsender, EventArgs e)

{

RequestInfo request= newRequestInfo();

UserInfo userInfo= newUserInfo();

userInfo.apiKey= "你的apikey";Perception perception= newPerception();

InputText inputText= newInputText();

inputText.text=Txt_Reust.Text.Trim();

perception.inputText=inputText;

request.perception=perception;

request.userInfo=userInfo;var result = await HttpRequestHelper.PostAsync("http://openapi.tuling123.com/openapi/api/v2", JsonConvert.SerializeObject(request));

ResponseInfo response= JsonConvert.DeserializeObject(result);

Txt_Msg.BeginInvoke(ShowMsg, response.results[0].values.text);

}#region 请求消息

public classRequestInfo

{public int reqType { get; set; }public Perception perception { get; set; }public UserInfo userInfo { get; set; }

}public classUserInfo

{public string apiKey { get; set; }public string userId { get; set; }

}public classPerception

{public InputText inputText { get; set; }public InputImage inputImage { get; set; }public List selfInfo { get; set; }

}public classLocation

{public string city { get; set; }public string province { get; set; }public string street { get; set; }

}public classInputText

{public string text { get; set; }

}public classInputImage

{public string url { get; set; }

}#endregion

#region 返回消息

public classResponseInfo

{public Intent intent { get; set; }public List results { get; set; }

}public classIntent

{public string code { get; set; }

}public classResults

{public int groupType { get; set; }public string resultType { get; set; }public Values values { get; set; }

}public classValues

{public string text { get; set; }

}#endregion

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值