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