如何在Unity Google Store中正确安装IAB?

时间:2017-08-28 07:37:33

标签: c# android unity3d in-app-purchase in-app-billing

请帮助。

有没有人使用开放式iab来统一安卓游戏?如果是,请与我分享您的知识。

我尝试在我的游戏中使用统一引擎集成开放式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 up是否正确?如果没有,那么正确设置的解决方案是什么?

1 个答案:

答案 0 :(得分:0)

最后,我在一周的实验中找到了一个解决方案。我试过 sdkbox iap openiab SDKBOX iap 无效,但打开iab 有效。

下面介绍如何为google商店设置更多详细信息open 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"/>

就是这样。