diff --git a/Assets/HttpManager.prefab b/Assets/HttpManager.prefab new file mode 100644 index 0000000..39467af --- /dev/null +++ b/Assets/HttpManager.prefab @@ -0,0 +1,45 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &9222194806482827490 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 9222194806482827492} + - component: {fileID: 9222194806482827493} + m_Layer: 0 + m_Name: HttpManager + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &9222194806482827492 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 9222194806482827490} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0.42503217, y: -0.26534736, z: 1.0504321} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &9222194806482827493 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 9222194806482827490} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9b63d4ab21503f34abf8355f926f5914, type: 3} + m_Name: + m_EditorClassIdentifier: diff --git a/Assets/HttpManager.prefab.meta b/Assets/HttpManager.prefab.meta new file mode 100644 index 0000000..486cc1e --- /dev/null +++ b/Assets/HttpManager.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 8c93a5d1e4ba1c342a2d48ef005466fe +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Material/weather-overlay-dark.mat b/Assets/Material/weather-overlay-dark.mat index 6ca1cdc..bd6f556 100644 --- a/Assets/Material/weather-overlay-dark.mat +++ b/Assets/Material/weather-overlay-dark.mat @@ -25,5 +25,5 @@ Material: m_Offset: {x: 0, y: 0} m_Floats: [] m_Colors: - - _Color: {r: 0, g: 0, b: 0, a: 0.00067318155} + - _Color: {r: 0, g: 0, b: 0, a: 0.2} - _MainColor: {r: 1, g: 1, b: 1, a: 0.4941176} diff --git a/Assets/Material/weather-overlay-lightning.mat b/Assets/Material/weather-overlay-lightning.mat index 5cafa44..85c1f23 100644 --- a/Assets/Material/weather-overlay-lightning.mat +++ b/Assets/Material/weather-overlay-lightning.mat @@ -25,4 +25,4 @@ Material: m_Offset: {x: 0, y: 0} m_Floats: [] m_Colors: - - _Color: {r: 1, g: 1, b: 1, a: 0.0033268183} + - _Color: {r: 1, g: 1, b: 1, a: 0.0061856927} diff --git a/Assets/Scenes/Init.unity b/Assets/Scenes/Init.unity index 64ed2f4..81beeb0 100644 --- a/Assets/Scenes/Init.unity +++ b/Assets/Scenes/Init.unity @@ -1177,49 +1177,6 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 983980998} m_CullTransparentMesh: 0 ---- !u!1 &1022991851 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 1022991853} - - component: {fileID: 1022991852} - m_Layer: 0 - m_Name: HttpManager - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!114 &1022991852 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1022991851} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 9b63d4ab21503f34abf8355f926f5914, type: 3} - m_Name: - m_EditorClassIdentifier: ---- !u!4 &1022991853 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1022991851} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0.42503217, y: -0.26534736, z: 1.0504321} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 2 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1165168744 GameObject: m_ObjectHideFlags: 0 @@ -1537,7 +1494,6 @@ MonoBehaviour: SendCodeButton: {fileID: 0} SendCodeButtonText: {fileID: 0} LoginButton: {fileID: 0} - homeView: {fileID: 0} --- !u!1 &1622434996 GameObject: m_ObjectHideFlags: 0 @@ -1872,3 +1828,72 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1957083327} m_CullTransparentMesh: 0 +--- !u!1001 &9222194805866882313 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 9222194806482827490, guid: 8c93a5d1e4ba1c342a2d48ef005466fe, + type: 3} + propertyPath: m_Name + value: HttpManager + objectReference: {fileID: 0} + - target: {fileID: 9222194806482827492, guid: 8c93a5d1e4ba1c342a2d48ef005466fe, + type: 3} + propertyPath: m_LocalPosition.x + value: 0.42503217 + objectReference: {fileID: 0} + - target: {fileID: 9222194806482827492, guid: 8c93a5d1e4ba1c342a2d48ef005466fe, + type: 3} + propertyPath: m_LocalPosition.y + value: -0.26534736 + objectReference: {fileID: 0} + - target: {fileID: 9222194806482827492, guid: 8c93a5d1e4ba1c342a2d48ef005466fe, + type: 3} + propertyPath: m_LocalPosition.z + value: 1.0504321 + objectReference: {fileID: 0} + - target: {fileID: 9222194806482827492, guid: 8c93a5d1e4ba1c342a2d48ef005466fe, + type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 9222194806482827492, guid: 8c93a5d1e4ba1c342a2d48ef005466fe, + type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 9222194806482827492, guid: 8c93a5d1e4ba1c342a2d48ef005466fe, + type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 9222194806482827492, guid: 8c93a5d1e4ba1c342a2d48ef005466fe, + type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 9222194806482827492, guid: 8c93a5d1e4ba1c342a2d48ef005466fe, + type: 3} + propertyPath: m_RootOrder + value: 2 + objectReference: {fileID: 0} + - target: {fileID: 9222194806482827492, guid: 8c93a5d1e4ba1c342a2d48ef005466fe, + type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 9222194806482827492, guid: 8c93a5d1e4ba1c342a2d48ef005466fe, + type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 9222194806482827492, guid: 8c93a5d1e4ba1c342a2d48ef005466fe, + type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: 8c93a5d1e4ba1c342a2d48ef005466fe, type: 3} diff --git a/Assets/Scripts/LoginAndPay/HomeView.cs b/Assets/Scripts/LoginAndPay/HomeView.cs index 132ed1a..4651b96 100644 --- a/Assets/Scripts/LoginAndPay/HomeView.cs +++ b/Assets/Scripts/LoginAndPay/HomeView.cs @@ -33,8 +33,8 @@ public class HomeView : MonoBehaviour if (payResponse.code == 0) { // 解码 URL - string decodedUrl = Uri.UnescapeDataString(payResponse.data); - Application.OpenURL(decodedUrl); + //string decodedUrl = Uri.UnescapeDataString(payResponse.data); + //Application.OpenURL(decodedUrl); } // else // { diff --git a/Assets/Scripts/LoginAndPay/LoginView.cs b/Assets/Scripts/LoginAndPay/LoginView.cs index 29b5243..b8ba945 100644 --- a/Assets/Scripts/LoginAndPay/LoginView.cs +++ b/Assets/Scripts/LoginAndPay/LoginView.cs @@ -69,6 +69,7 @@ public class LoginView : MonoBehaviour { //ShowHomeView(phonenum); //SceneManager.LoadSceneAsync("LoadingScreen"); + HttpManager.Instance.phoneNum = phonenum; SceneManager.LoadScene("LoadingScreen"); } else diff --git a/Assets/Scripts/LoginAndPay/http/HttpManager.cs b/Assets/Scripts/LoginAndPay/http/HttpManager.cs index 486eb0b..12fdc0f 100644 --- a/Assets/Scripts/LoginAndPay/http/HttpManager.cs +++ b/Assets/Scripts/LoginAndPay/http/HttpManager.cs @@ -1,3 +1,4 @@ +using CIG; using Cysharp.Threading.Tasks; using System; using System.Text; @@ -6,9 +7,14 @@ using UnityEngine.Networking; public class HttpManager : MonoBehaviour { + + static public int isZhengShi = 3; string urlHead = GetUrlHead(isZhengShi); + public string phoneNum = "13212713350"; + public string LastOrderNo; + public CIG3StoreProduct LastProduct; static string GetUrlHead(int _isZhengShi) { @@ -37,6 +43,7 @@ public class HttpManager : MonoBehaviour // 单例模式 public static HttpManager Instance { get; private set; } + private void Awake() { // 实现单例模式 diff --git a/Assets/Scripts/LoginAndPay/http/LoginRequest.cs b/Assets/Scripts/LoginAndPay/http/LoginRequest.cs index 647157b..5055713 100644 --- a/Assets/Scripts/LoginAndPay/http/LoginRequest.cs +++ b/Assets/Scripts/LoginAndPay/http/LoginRequest.cs @@ -39,8 +39,29 @@ public class PayRequest: WWWRequest [Serializable] public class PayResponse : WWWResponse +{ + public int code; + public PayResponseData data; + public string message; +} + +[Serializable] +public class PayResponseData +{ + public string orderno; + public string pay_url; +} + +[Serializable] +public class PaymentStatusRequest : WWWRequest +{ + public string orderno; +} + +[Serializable] +public class PaymentStatusResponse : WWWResponse { public int code; public string data; public string message; -} \ No newline at end of file +} diff --git a/Assets/Scripts/ShopPopupState.cs b/Assets/Scripts/ShopPopupState.cs index f6dfece..806acf9 100644 --- a/Assets/Scripts/ShopPopupState.cs +++ b/Assets/Scripts/ShopPopupState.cs @@ -1,12 +1,17 @@ using System; using System.Collections.Generic; +using System.Net.Sockets; +using System.Net; using CIG; using CIG.Extensions; using CIG.Translation; using CIG3.ExtensionMethods; using CIGEnums; +using Cysharp.Threading.Tasks; using SUISS.Core; using SUISSEngine; +using UnityEngine; +using UnityEngine.Purchasing; public class ShopPopupState : PopupBaseState { @@ -155,7 +160,99 @@ public class ShopPopupState : PopupBaseState public void OnIAPShopItemClicked(CIG3StoreProduct product) { - SingletonMonobehaviour.Instance.PurchaseHandler.InitiatePurchase(product, new Action(this.RefreshTab)); + //SingletonMonobehaviour.Instance.PurchaseHandler.InitiatePurchase(product, new Action(this.RefreshTab)); + ClickPayButton_Task(product).Forget(); + } + + private async UniTask ClickPayButton_Task(CIG3StoreProduct product) + { + string localIP = GetLocalIP(); + Debug.Log("Local IP Address: " + localIP); + int money = (int)(product.DollarPrice * 100); // DollarPrice 100 + PayResponse payResponse = await HttpManager.Instance.RequestPost("payment/pay", new PayRequest() { phone = HttpManager.Instance.phoneNum, money = money, clientIp = localIP }); + if (payResponse.code == 0) + { + PayResponseData payResponseData = payResponse.data; + + string orderNo = payResponseData.orderno; + HttpManager.Instance.LastOrderNo = orderNo; + HttpManager.Instance.LastProduct = product; + //// 洢 orderNo + //PlayerPrefs.SetString("LastOrderNo", orderNo); + //PlayerPrefs.Save(); + // URL + string decodedUrl = Uri.UnescapeDataString(payResponseData.pay_url); + Application.OpenURL(decodedUrl); + } + // else + // { + // ErrorText.text = loginResponse.message; + // } + } + + void OnApplicationFocus(bool hasFocus) + { + if (hasFocus && !isCheckingPaymentStatus) + { + CheckPaymentStatus().Forget(); + } + } + + private bool isCheckingPaymentStatus = false; + private async UniTaskVoid CheckPaymentStatus() + { + if (isCheckingPaymentStatus) + { + return; + } + isCheckingPaymentStatus = true; + + //string lastOrderNo = PlayerPrefs.GetString("LastOrderNo", string.Empty); + string lastOrderNo = HttpManager.Instance.LastOrderNo; + if (!string.IsNullOrEmpty(lastOrderNo)) + { + // ѯ֧״̬ + PaymentStatusResponse statusResponse = await HttpManager.Instance.RequestPost("payment/status", new PaymentStatusRequest() { orderno = lastOrderNo }); + if (statusResponse.code == 0) + { + // ֧ɹش洢 orderNo + //PlayerPrefs.DeleteKey("LastOrderNo"); + //PlayerPrefs.Save(); + SingletonMonobehaviour.Instance.PurchaseHandler.InitiatePurchase(HttpManager.Instance.LastProduct, new Action(this.RefreshTab)); + HttpManager.Instance.LastOrderNo = ""; + HttpManager.Instance.LastProduct = null; + Debug.Log("Payment successful for orderNo: " + lastOrderNo); + } + else + { + Debug.Log("Payment not successful for orderNo: " + lastOrderNo); + } + } + isCheckingPaymentStatus = false; + } + + 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 OnCraneShopItemClicked(decimal goldCost)