• 大小: 3.38MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-11-15
  • 语言: 其他
  • 标签:

资源简介

unity3d中问题内容通过WWW或者Httprequest进行POST请求返回图灵机器人的回答

资源截图

代码片段和文件信息

using UnityEngine;
using System.Collections;
using System.Net;
using System.IO;
using System.Text;
using System;
using LitJson;
using UnityEngine.UI;
using System.Collections.Generic;

public class TuLing : MonoBehaviour {

    public Text showText;
    public InputField inputField;
// Use this for initialization
void Start () {

        
    }

    public void OnEnter()
    {
        string txt = inputField.text;
        if (string.IsNullOrEmpty(txt))
            return;
        showText.text += “我“ + “:“ + txt + “\n“;

        CallTuring(txtdelegate(string v_result)
        {
            showText.text += “我的机器人:“ + v_result + “\n“;
        });
        
    }

    private void CallTuring(string txtAction ResultCall)
    {
       

        string v_result = “出错!!!“;

        Turing2_0CallHead callhead;

        callhead.reqType = 0;

        callhead.apiKey = “apiKey“;
        callhead.userId = “userId“;
        callhead.groupId = null;
        callhead.userIdName = null;


        callhead.locationCity = null;
        callhead.locationProvince = null;
        callhead.locationStreet = null;

        callhead.inputText = txt;
        callhead.inputImage = null;
        callhead.inputMedia = null;

        Action wwwPostCall = delegate (string content)
        {
            Turing2_0ReturnResult Turingresults = CallTuringWeb2_0(content);

            if (Turingresults != null)
            {
                v_result = Turingresults.intent.code.ToString();
                if (Turingresults.results != null)
                {
                    v_result = ““;
                    for (int i = 0; i < Turingresults.results.Length; i++)
                    {
                        Turing2_0results result = Turingresults.results[i];
                        foreach (var rs in result.values)
                        {
                            v_result += rs.Value + “\n“;
                        }
                    }
                }
            }
            if (ResultCall != null)
            {
                ResultCall(v_result);
            }
        };

        StartCoroutine(WWWPOST(“http://openapi.tuling123.com/openapi/api/v2“ GetConfigParam(callhead) wwwPostCall));
    }

    public static IEnumerator WWWPOST(string url string paramAction ResultCall)
    {
        Dictionary headers = new Dictionary();
        headers[“Content-Type“] = “application/json;charset=UTF-8“;

        string m_info = null;

        //将文本转为byte数组    
        byte[] bs = Encoding.UTF8.GetBytes(param);

        //向HTTP服务器提交Post数据    
        WWW www = new WWW(url bs headers);

        //等待服务器的响应    
        yield return www;

        if (string.IsNullOrEmpty(www.error))
        {
            m_info = www.text;
        }        

        if (ResultCall != null)
        {
            ResultCall(m_info);
 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-04-08 13:40  .vs\
     目录           0  2018-04-08 13:40  .vs\TulingProject\
     目录           0  2018-04-08 15:04  .vs\TulingProject\v15\
     文件       54784  2018-04-12 10:32  .vs\TulingProject\v15\.suo
     目录           0  2018-04-08 13:40  .vs\TulingProject\v15\Server\
     目录           0  2018-04-12 10:32  .vs\TulingProject\v15\Server\sqlite3\
     文件           0  2018-04-08 13:40  .vs\TulingProject\v15\Server\sqlite3\db.lock
     文件      544768  2018-04-12 10:32  .vs\TulingProject\v15\Server\sqlite3\storage.ide
     目录           0  2018-04-12 10:32  Assets\
     目录           0  2018-04-08 11:51  Assets\Plugins\
     文件       54272  2016-05-20 11:12  Assets\Plugins\LitJson.dll
     文件         467  2018-04-04 10:47  Assets\Plugins\LitJson.dll.meta
     文件         191  2018-04-04 10:47  Assets\Plugins.meta
     文件       12394  2018-04-12 10:32  Assets\TuLing.cs
     文件         262  2018-04-04 10:08  Assets\TuLing.cs.meta
     文件       50804  2018-04-12 10:31  Assets\Turing.unity
     文件         174  2018-04-04 15:03  Assets\Turing.unity.meta
     目录           0  2018-04-12 10:31  Library\
     文件        4116  2018-04-08 11:51  Library\AnnotationManager
     文件     2923624  2018-04-12 10:31  Library\assetDatabase3
     文件          24  2018-04-08 11:52  Library\AssetImportState
     文件        4756  2018-04-12 10:31  Library\AssetServerCacheV3
     文件           0  2018-04-08 11:51  Library\BuildPlayer.prefs
     文件        4152  2018-04-08 11:51  Library\BuildSettings.asset
     文件       19071  2018-04-12 10:31  Library\CurrentLayout.dwlt
     文件        4384  2018-04-08 15:05  Library\EditorUserBuildSettings.asset
     文件        4152  2018-04-08 11:51  Library\EditorUserSettings.asset
     文件        4164  2018-04-12 10:31  Library\expandedItems
     文件        4104  2018-04-08 11:51  Library\InspectorExpandedItems.asset
     文件       24312  2018-04-08 15:06  Library\LastBuild.buildreport
     文件          69  2018-04-12 10:31  Library\LastSceneManagerSetup.txt
............此处省略3027个文件信息

评论

共有 条评论