如何在Unity Store中正确打开IAB?

问题描述:

需要帮助。如何在Unity Store中正确打开IAB?

有没有人使用开放的iab计费Android游戏统一?如果是,请分享我的知识。

我尝试在统一引擎中集成开放iab在我的游戏中。但我没有找到任何解释更清楚的教程。我在YouTube上找到这个教程:open iab tutorial但它不是英文的。我不明白他说什么。

如果我把它设置为correclty,有人可以看看我的代码吗? 下面是我的链接代码示例:

My Sample Code // 注:如果不存在了,示例代码只看到剧本后我正确的答案。

以上链接在14天内到期。如果仍然没有回答,我会更新。

我的问题

这里下面正确与否?

const string SKU1 = "com.games.games1"; 
const string SKU2 = "com.games.games1"; 
const string SKU3 = "com.games.games1"; 
const string SKU4 = "com.games.games1"; 
const string SKU5 = "com.games.games1"; 
const string SKU6 = "com.games.games1"; 

这里下面正确与否?

OpenIAB.mapSku(SKU1, OpenIAB_Android.STORE_GOOGLE, "pack1gt"); 
    OpenIAB.mapSku(SKU2, OpenIAB_Android.STORE_GOOGLE, "pack2gt"); 
    OpenIAB.mapSku(SKU3, OpenIAB_Android.STORE_GOOGLE, "pack3gt"); 
    OpenIAB.mapSku(SKU4, OpenIAB_Android.STORE_GOOGLE, "estateagenbundle"); 
    OpenIAB.mapSku(SKU5, OpenIAB_Android.STORE_GOOGLE, "landlordbundle"); 
    OpenIAB.mapSku(SKU6, OpenIAB_Android.STORE_GOOGLE, "miraclebundle"); 

这里下面正确与否?

public void pack1gt() { 
    OpenIAB.purchaseProduct(SKU1); 
} 

public void pack2gt() { 
    OpenIAB.purchaseProduct(SKU2); 
} 

public void pack3gt() { 
    OpenIAB.purchaseProduct(SKU3); 
} 

这里如何识别每个产品时的成功?

private void purchaseSucceededEvent(Purchase purchase) 
{ 
    Debug.Log("purchaseSucceededEvent: " + purchase); 
    Debug.Log ("purchasesuccess: " + purchase.AppstoreName); 
    Debug.Log ("purchasesuccess: " + purchase.Sku); 
    _label = _label + "\n" + "PURCHASED:" + purchase.ToString(); 
    OpenIAB.consumeProduct(purchase); 
    Debug.Log (_label); 
    if (purchase.Sku == "pack1gt") { 
     sp.pack1gt(); 
    } else if (purchase.Sku == "pack2gt") { 
     sp.pack2gt(); 
    } else if (purchase.Sku == "pack3gt") { 
     sp.pack3gt(); 
    } else if (purchase.Sku == "estateagenbundle") { 
     sp.EstateAgentBundle(); 
    } else if (purchase.Sku == "landlordbundle") { 
     sp.LandLordBundle(); 
    } else if (purchase.Sku == "miraclebundle") { 
     sp.MiracleBundle(); 
    } 

} 

我的问题上面如何设置IP了正确与否?如果不是,那么解决方案是否正确设置?

最后,我在一个星期的实验中发现了一个解决方案,关于在应用程序购买统一。我已尝试sdkbox iapopeniabSDKBOX iap不工作,但打开iab工作。

下面如何设置更多的细节打开谷歌商店iab。

下面是正确的完整脚本。我已经评论过线索。

using UnityEngine; 
using OnePF; 
using System.Collections.Generic; 

public class IAPScript : MonoBehaviour { 

    //Start Product Name Mapping ---- This your mapping product, recommend use a name as the product id at google store 

    const string SKU1 = "pack1gt"; 
    const string SKU2 = "pack2gt"; 
    const string SKU3 = "pack3gt"; 
    const string SKU4 = "estateagenbundle"; 
    const string SKU5 = "landlordbundle"; 
    const string SKU6 = "miraclebundle"; 

    //End Product Name Mapping ----- 

    // Start Leave As It ----- 

    string _label = ""; 
    bool _isInitialized = false; 
    Inventory _inventory = null; 

    void Awake() { 
     OpenIABEventManager.billingSupportedEvent += billingSupportedEvent; 
     OpenIABEventManager.billingNotSupportedEvent += billingNotSupportedEvent; 
     OpenIABEventManager.queryInventorySucceededEvent += queryInventorySucceededEvent; 
     OpenIABEventManager.queryInventoryFailedEvent += queryInventoryFailedEvent; 
     OpenIABEventManager.purchaseSucceededEvent += purchaseSucceededEvent; 
     OpenIABEventManager.purchaseFailedEvent += purchaseFailedEvent; 
     OpenIABEventManager.consumePurchaseSucceededEvent += consumePurchaseSucceededEvent; 
     OpenIABEventManager.consumePurchaseFailedEvent += consumePurchaseFailedEvent; 
    } 

    // End Leave As It ----- 

    private void Start() 
    { 
     // Map skus for different stores  
     OpenIAB.mapSku(SKU1, OpenIAB_Android.STORE_GOOGLE, "pack1gt"); 
     OpenIAB.mapSku(SKU2, OpenIAB_Android.STORE_GOOGLE, "pack2gt"); 
     OpenIAB.mapSku(SKU3, OpenIAB_Android.STORE_GOOGLE, "pack3gt"); 
     OpenIAB.mapSku(SKU4, OpenIAB_Android.STORE_GOOGLE, "estateagenbundle"); 
     OpenIAB.mapSku(SKU5, OpenIAB_Android.STORE_GOOGLE, "landlordbundle"); 
     OpenIAB.mapSku(SKU6, OpenIAB_Android.STORE_GOOGLE, "miraclebundle"); 

     Initialized(); 
    } 

    //Start Initialized Method ---- 
    void Initialized() { 

     // Application public key (Find it at google console Service and API) 
     var googlePublicKey = "your current public key"; 

     var options = new Options(); 
     options.checkInventoryTimeoutMs = Options.INVENTORY_CHECK_TIMEOUT_MS * 2; 
     options.discoveryTimeoutMs = Options.DISCOVER_TIMEOUT_MS * 2; 
     options.checkInventory = false; 
     options.verifyMode = OptionsVerifyMode.VERIFY_SKIP; 
     options.prefferedStoreNames = new string[] { OpenIAB_Android.STORE_GOOGLE }; 
     options.availableStoreNames = new string[] { OpenIAB_Android.STORE_GOOGLE }; 
     options.storeKeys = new Dictionary<string, string> { {OpenIAB_Android.STORE_GOOGLE, googlePublicKey} }; 
    options.storeSearchStrategy = SearchStrategy.INSTALLER_THEN_BEST_FIT; 

     // Transmit options and start the service 
     OpenIAB.init(options); 

     if (!_isInitialized) 
      return; 

    } 
    //End Initialized Method ---- 


    public void Query_Inventory() { 
     OpenIAB.queryInventory(new string[] { SKU1,SKU2,SKU3,SKU4,SKU5,SKU6 }); 
    } 

    //Start Each Call Product Method ---- 

    public void pack1gt() { 
    // Buy Product SKU1 (pack1gt) 
     OpenIAB.purchaseProduct(SKU1); 
    } 

    public void pack2gt() { 
    // Buy Product SKU2 (pack2gt) 
     OpenIAB.purchaseProduct(SKU2); 
    } 

    public void pack3gt() { 
    // Buy Product SKU3 (pack3gt) 
     OpenIAB.purchaseProduct(SKU3); 
    } 

    public void estateagenbundle() { 
    // Buy Product SKU4 (estateagenbundle) 
     OpenIAB.purchaseProduct(SKU4); 
    } 

    public void landlordbundle() { 
    // Buy Product SKU5 (landlordbundle) 
     OpenIAB.purchaseProduct(SKU5); 
    } 

    public void miraclebundle() { 
    // Buy Product SKU6 (miraclebundle) 
     OpenIAB.purchaseProduct(SKU6); 
    } 

    //End Each Call Product Method ---- 


    // Start Leave As It Except you Know what you have modified --- 
    private void billingSupportedEvent() 
    { 
     _isInitialized = true; 
     Debug.Log("billingSupportedEvent"); 
     _label = _label + "\n" + "billingSupportedEvent"; 
    } 

    private void billingNotSupportedEvent(string error) 
    { 
     Debug.Log("billingNotSupportedEvent: " + error); 
     _label = _label + "\n" + "billingNotSupportedEvent"; 
    } 

    private void queryInventorySucceededEvent(Inventory inventory) 
    { 
     Debug.Log("queryInventorySucceededEvent: " + inventory); 
     if (inventory != null) 
     { 
      _label = inventory.ToString(); 
      _inventory = inventory; 
      List<Purchase> prods = inventory.GetAllPurchases(); 

      foreach(Purchase p in prods) OpenIAB.consumeProduct(p); 
      Debug.Log (_label); 
     } 
    } 

    private void queryInventoryFailedEvent(string error) 
    { 
     Debug.Log("queryInventoryFailedEvent: " + error); 
     _label = error; 
     Debug.Log (_label); 
    } 

    // End Leave As It Except you Know what you have modified --- 

    //Start Success When Purchased ---- 

    private void purchaseSucceededEvent(Purchase purchase) 
    { 
     Debug.Log("purchaseSucceededEvent: " + purchase); 
     Debug.Log ("purchasesuccess: " + purchase.AppstoreName); 
     Debug.Log ("purchasesuccess: " + purchase.Sku); 
     _label = _label + "\n" + "PURCHASED:" + purchase.ToString(); 

    // Here Consume The Product ---- 
    OpenIAB.consumeProduct(purchase); 
     Debug.Log (_label); 

    // Here How to check product your buy at google store 
    // Give a case and call the method or make your one 
     if (purchase.Sku == "pack1gt") { 
      sp.pack1gt(); 
     } else if (purchase.Sku == "pack2gt") { 
      sp.pack2gt(); 
     } else if (purchase.Sku == "pack3gt") { 
      sp.pack3gt(); 
     } else if (purchase.Sku == "estateagenbundle") { 
      sp.EstateAgentBundle(); 
     } else if (purchase.Sku == "landlordbundle") { 
      sp.LandLordBundle(); 
     } else if (purchase.Sku == "miraclebundle") { 
      sp.MiracleBundle(); 
     } 

    } 

    //End Success When Purchased ---- 

    //Start Failed When Purchased ---- 

    private void purchaseFailedEvent(int errorCode, string errorMessage) 
    { 
     Debug.Log("purchaseFailedEvent: " + errorMessage); 
     _label = _label + "\n" + "Purchase Failed: " + errorMessage; 

     Debug.Log (_label); 
     sp.FailedPurchase(); 
    } 

    //End Failed When Purchased ----- 

    // Start Leave As It Except you Know what you have modified --- 

    private void consumePurchaseSucceededEvent(Purchase purchase) 
    { 
     Debug.Log("consumePurchaseSucceededEvent: " + purchase); 
     _label = _label + "\n" + "CONSUMED: " + purchase.ToString(); 
     Debug.Log (_label); 
    } 

    private void consumePurchaseFailedEvent(string error) 
    { 
     Debug.Log("consumePurchaseFailedEvent: " + error); 
     _label = _label + "\n" + "Consume Failed: " + error; 
     Debug.Log (_label); 
    } 

    // End Leave As It Except you Know what you have modified --- 
} 

修改的AndroidManifest.xml。

地址:

<uses-permission android:name="android.permission.INTERNET" /> 
<application ... > 
     <activity android:name="org.onepf.openiab.UnityProxyActivity" 
       android:launchMode="singleTask" 
       android:label="@string/app_name" 
       android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"> 
    </activity> 
</application> 
<uses-feature android:name="android.hardware.telephony" android:required="false" /> 
<uses-permission android:name="com.android.vending.BILLING" /> 
<uses-permission android:name="org.onepf.openiab.permission.BILLING" /> 
<permission android:name="com.tmoney.vending.INBILLING"/> 

这就是全部。