Kaynağa Gözat

支付代码

master
LuanShi 4 ay önce
ebeveyn
işleme
68a311f260
10 değiştirilmiş dosya ile 253 ekleme ve 50 silme
  1. +45
    -0
      Assets/HttpManager.prefab
  2. +7
    -0
      Assets/HttpManager.prefab.meta
  3. +1
    -1
      Assets/Material/weather-overlay-dark.mat
  4. +1
    -1
      Assets/Material/weather-overlay-lightning.mat
  5. +69
    -44
      Assets/Scenes/Init.unity
  6. +2
    -2
      Assets/Scripts/LoginAndPay/HomeView.cs
  7. +1
    -0
      Assets/Scripts/LoginAndPay/LoginView.cs
  8. +7
    -0
      Assets/Scripts/LoginAndPay/http/HttpManager.cs
  9. +22
    -1
      Assets/Scripts/LoginAndPay/http/LoginRequest.cs
  10. +98
    -1
      Assets/Scripts/ShopPopupState.cs

+ 45
- 0
Assets/HttpManager.prefab Dosyayı Görüntüle

@@ -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:

+ 7
- 0
Assets/HttpManager.prefab.meta Dosyayı Görüntüle

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 8c93a5d1e4ba1c342a2d48ef005466fe
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

+ 1
- 1
Assets/Material/weather-overlay-dark.mat Dosyayı Görüntüle

@@ -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}

+ 1
- 1
Assets/Material/weather-overlay-lightning.mat Dosyayı Görüntüle

@@ -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}

+ 69
- 44
Assets/Scenes/Init.unity Dosyayı Görüntüle

@@ -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}

+ 2
- 2
Assets/Scripts/LoginAndPay/HomeView.cs Dosyayı Görüntüle

@@ -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
// {


+ 1
- 0
Assets/Scripts/LoginAndPay/LoginView.cs Dosyayı Görüntüle

@@ -69,6 +69,7 @@ public class LoginView : MonoBehaviour
{
//ShowHomeView(phonenum);
//SceneManager.LoadSceneAsync("LoadingScreen");
HttpManager.Instance.phoneNum = phonenum;
SceneManager.LoadScene("LoadingScreen");
}
else


+ 7
- 0
Assets/Scripts/LoginAndPay/http/HttpManager.cs Dosyayı Görüntüle

@@ -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()
{
// 实现单例模式


+ 22
- 1
Assets/Scripts/LoginAndPay/http/LoginRequest.cs Dosyayı Görüntüle

@@ -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;
}
}

+ 98
- 1
Assets/Scripts/ShopPopupState.cs Dosyayı Görüntüle

@@ -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<CIGStoreManager>.Instance.PurchaseHandler.InitiatePurchase(product, new Action(this.RefreshTab));
//SingletonMonobehaviour<CIGStoreManager>.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<PayRequest, PayResponse>("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<PaymentStatusRequest, PaymentStatusResponse>("payment/status", new PaymentStatusRequest() { orderno = lastOrderNo });
if (statusResponse.code == 0)
{
// 支付成功,清除本地存储的 orderNo
//PlayerPrefs.DeleteKey("LastOrderNo");
//PlayerPrefs.Save();
SingletonMonobehaviour<CIGStoreManager>.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)


Yükleniyor…
İptal
Kaydet