using System; using System.Net; using System.Net.Sockets; using Cysharp.Threading.Tasks; using UnityEngine; using UnityEngine.UI; public class HomeView : MonoBehaviour { [SerializeField] private Button PayButton; [HideInInspector] public string phonenum = ""; // Start is called before the first frame update void Start() { PayButton.onClick.AddListener(ClickPayButton); } private void ClickPayButton() { ClickPayButton_Task().Forget(); } private async UniTask ClickPayButton_Task() { string localIP = GetLocalIP(); Debug.Log("Local IP Address: " + localIP); PayResponse payResponse = await HttpManager.Instance.RequestPost("payment/pay", new PayRequest(){phone = phonenum, money = 600, clientIp = localIP}); if (payResponse.code == 0) { // 解码 URL string decodedUrl = Uri.UnescapeDataString(payResponse.data); Application.OpenURL(decodedUrl); } // else // { // ErrorText.text = loginResponse.message; // } } string GetLocalIP() { string localIP = string.Empty; try { var host = Dns.GetHostEntry(Dns.GetHostName()); foreach (var ip in host.AddressList) { // 检查是否是 IPv4 地址,并且排除回环地址 if (ip.AddressFamily == AddressFamily.InterNetwork) { localIP = ip.ToString(); break; } } } catch (System.Exception ex) { Debug.LogError("Error getting local IP: " + ex.Message); } return string.IsNullOrEmpty(localIP) ? "Unable to determine local IP" : localIP; } public void Show(){ gameObject.SetActive(true); } // Update is called once per frame void Update() { } }