Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 

83 řádky
2.1 KiB

  1. using System;
  2. using System.Net;
  3. using System.Net.Sockets;
  4. using Cysharp.Threading.Tasks;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. public class HomeView : MonoBehaviour
  8. {
  9. [SerializeField]
  10. private UniWebView m_UniWebView;
  11. [SerializeField]
  12. private Button PayButton;
  13. [HideInInspector]
  14. public string phonenum = "";
  15. // Start is called before the first frame update
  16. void Start()
  17. {
  18. m_UniWebView.SetBackButtonEnabled(false);// 回退钮 物理按键
  19. PayButton.onClick.AddListener(ClickPayButton);
  20. }
  21. private void ClickPayButton()
  22. {
  23. ClickPayButton_Task().Forget();
  24. }
  25. private async UniTask ClickPayButton_Task()
  26. {
  27. string localIP = GetLocalIP();
  28. Debug.Log("Local IP Address: " + localIP);
  29. PayResponse payResponse = await HttpManager.Instance.RequestPost<PayRequest, PayResponse>("payment/pay", new PayRequest(){phone = phonenum, money = 600, clientIp = localIP});
  30. if (payResponse.code == 0)
  31. {
  32. // 解码 URL
  33. string decodedUrl = Uri.UnescapeDataString(payResponse.data);
  34. Application.OpenURL(decodedUrl);
  35. }
  36. // else
  37. // {
  38. // ErrorText.text = loginResponse.message;
  39. // }
  40. }
  41. string GetLocalIP()
  42. {
  43. string localIP = string.Empty;
  44. try
  45. {
  46. var host = Dns.GetHostEntry(Dns.GetHostName());
  47. foreach (var ip in host.AddressList)
  48. {
  49. // 检查是否是 IPv4 地址,并且排除回环地址
  50. if (ip.AddressFamily == AddressFamily.InterNetwork)
  51. {
  52. localIP = ip.ToString();
  53. break;
  54. }
  55. }
  56. }
  57. catch (System.Exception ex)
  58. {
  59. Debug.LogError("Error getting local IP: " + ex.Message);
  60. }
  61. return string.IsNullOrEmpty(localIP) ? "Unable to determine local IP" : localIP;
  62. }
  63. public void Show(){
  64. gameObject.SetActive(true);
  65. m_UniWebView.Show();
  66. }
  67. // Update is called once per frame
  68. void Update()
  69. {
  70. }
  71. }