void onInterstitialEvent(string eventName, string msg) { LoadingBlockCtrl.Hide(); Debug.Log("handler onAdmobEvent---" + eventName + " " + msg); switch (eventName) { case "onAdFailedToLoad": if (showInterstitialLoading) { if (reloadTimes-- > 0) { LoadingBlockCtrl.Show(); ad.loadInterstitial(); } else { ConfirmCtrl.Show("没有找到可以播放的广告,是否继续看广告?", () => { reloadTimes = 1; LoadingBlockCtrl.Show(); ad.loadInterstitial(); }, null, "要看", "不看"); } } break; case "onAdLoaded": ad.showInterstitial(); SendEvent("InterstitialLoaded", DbManager.Instance.HostData.Lv.ToString()); break; } }
/// <summary> /// 发送Http请求 /// </summary> /// <param name="url">URL.</param> /// <param name="param">Parameter.</param> /// <param name="callback">Callback.</param> /// <param name="errorCallback">Error callback.</param> public static void Post(string url, JObject param, System.Action <string> callback = null, System.Action errorCallback = null) { try { // var json = "{ 'receipt-data': '" + receiptData + "'}"; var json = param.ToString(); #if UNITY_EDITOR Debug.LogWarning("Http 上行: url = " + url + ", " + JsonManager.GetInstance().SerializeObject(json)); #endif System.Text.ASCIIEncoding ascii = new System.Text.ASCIIEncoding(); byte[] postBytes = System.Text.Encoding.UTF8.GetBytes(json); System.Net.ServicePointManager.ServerCertificateValidationCallback = myRemoteCertificateValidationCallback; // HttpWebRequest request; var request = System.Net.HttpWebRequest.Create(url); request.Method = "POST"; request.ContentType = "application/json"; request.ContentLength = postBytes.Length; //Stream postStream = request.GetRequestStream(); //postStream.Write(postBytes, 0, postBytes.Length); //postStream.Close(); using (var stream = request.GetRequestStream()) { stream.Write(postBytes, 0, postBytes.Length); stream.Flush(); } // var sendresponse = (HttpWebResponse)request.GetResponse(); var sendresponse = request.GetResponse(); string sendresponsetext = ""; using (var streamReader = new System.IO.StreamReader(sendresponse.GetResponseStream())) { sendresponsetext = streamReader.ReadToEnd().Trim(); streamReader.Close(); streamReader.Dispose(); } #if UNITY_EDITOR Debug.LogWarning("Http 下行: url = " + url + ", " + sendresponsetext); #endif if (callback != null) { callback(sendresponsetext); } } catch (System.Exception ex) { LoadingBlockCtrl.Hide(); AlertCtrl.Show(ex.Message.ToString()); if (errorCallback != null) { errorCallback(); } SendEvent("HttpErro", ex.Message.ToString(), DbManager.Instance.HostData.Name); } }
private static void OnTransactionComplete(IOSStoreKitResult result) { // Debug.Log("OnTransactionComplete: " + result.ProductIdentifier); // Debug.Log("OnTransactionComplete: state: " + result.State); // Debug.Log("-----------------------------start"); // Debug.Log("OnTransactionComplete: Receipt: " + result.Receipt); switch (result.State) { case InAppPurchaseState.Purchased: case InAppPurchaseState.Restored: //Our product been succsesly purchased or restored //So we need to provide content to our user depends on productIdentifier _mai_ProductId = result.ProductIdentifier; _mai_Receipt = result.Receipt; PlayerPrefs.SetString("LatestReceipt", _mai_Receipt); //标记receipt,用于补单 VerificationReceipt(_mai_Receipt); // Debug.Log("=========================, 新 OnTransactionComplete"); // Debug.Log("=========================, 新 result.ProductIdentifier = " + result.ProductIdentifier); // Debug.Log("=========================, 新 result.State = " + result.State); // Debug.Log("=========================, 新 result.TransactionIdentifier = " + result.TransactionIdentifier); // Debug.Log("=========================, 新 result.Receipt = " + result.Receipt); break; case InAppPurchaseState.Deferred: //iOS 8 introduces Ask to Buy, which lets parents approve any purchases initiated by children //You should update your UI to reflect this deferred state, and expect another Transaction Complete to be called again with a new transaction state //reflecting the parent’s decision or after the transaction times out. Avoid blocking your UI or gameplay while waiting for the transaction to be updated. IOSNativePopUpManager.showMessage("提示", "充值超时"); LoadingBlockCtrl.Hide(); clearIAPCache(); break; case InAppPurchaseState.Failed: //Our purchase flow is failed. //We can unlock intrefase and repor user that the purchase is failed. // Debug.Log("Transaction failed with error, code: " + result.Error.Code); // Debug.Log("Transaction failed with error, description: " + result.Error.Description); IOSNativePopUpManager.showMessage("提示", "充值未完成"); LoadingBlockCtrl.Hide(); clearIAPCache(); break; } }
public static void VerificationReceipt(string receipt) { byte[] rec = Convert.FromBase64String(receipt); string jsonStr = System.Text.Encoding.UTF8.GetString(rec); Post(jsonStr.IndexOf("\"Sandbox\";") >= 0 ? "https://sandbox.itunes.apple.com/verifyReceipt" : "https://buy.itunes.apple.com/verifyReceipt", new JObject(new JProperty("receipt-data", _mai_Receipt)), (text) => { JObject json = JObject.Parse(text); int status = (int)json["status"]; if (status == 0) { JObject receiptObj = JObject.Parse(json["receipt"].ToString()); if (receiptObj["bid"].ToString() == "com.courage2017.mywuxia") { if (string.IsNullOrEmpty(PlayerPrefs.GetString(receiptObj["original_transaction_id"].ToString()))) { UnlockProducts(receiptObj["product_id"].ToString()); PlayerPrefs.SetString(receiptObj["original_transaction_id"].ToString(), "true"); } else { IOSNativePopUpManager.showMessage("提示", "已使用过的内购通知"); SendEvent("ReceiptUsed", receiptObj["original_transaction_id"].ToString(), DbManager.Instance.HostData.Name); } } else { IOSNativePopUpManager.showMessage("提示", "不属于本游戏的内购项目"); SendEvent("NotMyReceipt", receiptObj["bid"].ToString(), DbManager.Instance.HostData.Name); } } else { IOSNativePopUpManager.showMessage("提示", "付费服务器验证未通过"); SendEvent("ReceiptError", status.ToString(), DbManager.Instance.HostData.Name); } PlayerPrefs.SetString("LatestReceipt", ""); //标记receipt为已经处理完毕 LoadingBlockCtrl.Hide(); }, null); }
void onRewardedVideoEvent(string eventName, string msg) { LoadingBlockCtrl.Hide(); Debug.Log("handler onRewardedVideoEvent---" + eventName + " rewarded: " + msg); switch (eventName) { case "onAdFailedToLoad": if (showRewardedVideoLoading) { if (reloadTimes-- > 0) { LoadingBlockCtrl.Show(); ad.loadRewardedVideo("ca-app-pub-4618478478287634/9895676018"); } else { ConfirmCtrl.Show("没有找到可以播放的广告,是否继续看广告?\n(Wifi不行可以切换4G试试)\n(也可以尝试断开重连下Wifi)", () => { reloadTimes = 1; LoadingBlockCtrl.Show(); ad.loadRewardedVideo("ca-app-pub-4618478478287634/9895676018"); }, null, "要看", "不看"); } } break; case "onAdLoaded": ad.showRewardedVideo(); SendEvent("RewardedVideoLoaded", DbManager.Instance.HostData.Lv.ToString()); break; case "onRewarded": if (rewardedVideoCallback != null) { rewardedVideoCallback(); SendEvent("EndRewardedVideo", DbManager.Instance.HostData.Lv.ToString()); } break; } }