KangFuItem.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using LitJson;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using UnityEngine.Networking;
  7. using UnityEngine.UI;
  8. public class KangFuItem : MonoBehaviour
  9. {
  10. public InputField input;
  11. public Text lun;
  12. public Text ting;
  13. public Text zhen;
  14. public Text ji;
  15. public Text wo;
  16. public void setData(JsonData data,int index)
  17. {
  18. lun.text = data["time"].ToString();
  19. float max =(float)( int.Parse(data["fting"].ToString())/ (float)( int.Parse(data["sting"].ToString()) + int.Parse(data["fting"].ToString())));
  20. ting.text = "正确:"+ data["sting"].ToString()+ " 错误:" + data["fting"].ToString()+" 错误率:"+(max * 100) + "%";
  21. zhen.text = data["zhen"].ToString();
  22. float maxji = (float)(int.Parse(data["fji"].ToString()) / (float)(int.Parse(data["sji"].ToString()) + int.Parse(data["fji"].ToString())));
  23. ji.text = "正确:" + data["sji"].ToString() + " 错误:" + data["fji"].ToString() + " 错误率:" + (maxji*100)+"%";
  24. wo.text = data["wo"].ToString();
  25. }
  26. public void geturl()
  27. {
  28. StartCoroutine(SendHttp("cmcc-endustry/v1/report/dairyCattle/dataToDoc", (string str) =>
  29. {
  30. JsonData data = JsonMapper.ToObject(str);
  31. input.text = data["data"]["downloadUrl"].ToString();
  32. Debug.Log("str===>?"+str);
  33. }));
  34. }
  35. public IEnumerator SendHttp(string methodName, Action<string> CallBack)
  36. {
  37. string url = "https://api-fat2.ghz-tech.com/" + methodName + "?userName=" + KangFuOne.choosename+ "&fileName=" + KangFuOne.choosename;
  38. UnityWebRequest webRequest = UnityWebRequest.Get(url);
  39. string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjMxNTM2MDAxNzEyNzQ0NjUxLCJpYXQiOjE3MTI3NDQ2NTEsInVzZXIiOnsiaWQiOjExLCJlbWFpbCI6IiIsInBob25lIjoieWIzIiwibmFtZSI6InliMyIsInJvbGVJZCI6M319.WGpVJHfbTr4Bp2cySjjlgCIon8nF4sJxkl58wcIion8";
  40. //UnityWebRequest webRequest = new UnityWebRequest(url, "GET");
  41. JsonData data = new JsonData();
  42. data["userName"] = KangFuOne.choosename;
  43. data["fileName"] = KangFuOne.choosename+"_"+DateTime.Now.ToString();
  44. webRequest.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
  45. webRequest.SetRequestHeader("authorization", token);//请求头文件内容
  46. Debug.Log(url);
  47. yield return webRequest.SendWebRequest();
  48. if (webRequest.result == UnityWebRequest.Result.ConnectionError)
  49. {
  50. Debug.Log(webRequest.error);
  51. }
  52. else
  53. {
  54. Debug.LogError(webRequest.downloadHandler.text);
  55. CallBack.Invoke(webRequest.downloadHandler.text);
  56. }
  57. }
  58. }