Esempio n. 1
0
        public override bool TakeAction()
        {
            TraceLog.ReleaseWriteFatal(_orderInfo);
            //string AppUrl = ConfigUtils.GetSetting("AppStoreUrl");
            if (AppUrl == string.Empty || _orderInfo.IndexOf("Sandbox") > 0)
            {
                AppUrl = "https://sandbox.itunes.apple.com/verifyReceipt";
            }
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(AppUrl);
            req.Method = "POST";
            byte[] ReceiptData = Encoding.UTF8.GetBytes(_orderInfo);
            Dictionary<string, string> dict = new Dictionary<string, string>();
            dict.Add("receipt-data", Convert.ToBase64String(ReceiptData));
            byte[] content = Encoding.UTF8.GetBytes(JsonUtils.Serialize(dict));
            req.ContentLength = content.Length;
            Stream stream = req.GetRequestStream();
            stream.Write(content, 0, content.Length);
            stream.Close();
            WebResponse resp = req.GetResponse();
            stream = resp.GetResponseStream();

            StreamReader reader = new StreamReader(stream);
            string response = reader.ReadToEnd();
            req.Abort();
            resp.Close();
            TraceLog.ReleaseWriteFatal(response);

            AppStoreInfo appStoreInfo = new AppStoreInfo();
            try
            {
                appStoreInfo = JsonUtils.Deserialize<AppStoreInfo>(response);
            }
            catch (Exception ex)
            {
                this.SaveLog(ex);
                ErrorCode = LanguageManager.GetLang().ErrorCode;
                ErrorInfo = LanguageManager.GetLang().LoadDataError;
                return false;
            }
            if (appStoreInfo.status != 0)
            {
                ErrorCode = LanguageManager.GetLang().ErrorCode;
                ErrorInfo = LanguageManager.GetLang().St1066_PayError;
                return false;
            }
           //int silver = AppStoreHelper.GetSilverPiece(appStoreInfo.receipt.product_id, _gameID);
            //PaymentService.GetAppStore(_gameID, _serviceID, _passportId, silver, appStoreInfo.receipt.transaction_id, _deviceId);

            AppStoreHelper appStore = AppStoreHelper.GetSilverPiece(appStoreInfo.receipt.product_id, _gameID);
            PaymentService.GetAppStore(_gameID, _serviceID, _passportId, appStore.SilverPiece, appStore.RMB, appStoreInfo.receipt.transaction_id, _deviceId);
           // TraceLog.ReleaseWriteFatal("appstore完成");
            //TraceLog.ReleaseWriteFatal("GameID" + _gameID + "ServerID" + _serviceID);

            //int silver = 10;
            //string test = "1234567894561111111";
            //PaymentService.GetAppStore(_gameID, _serviceID, _passportId, silver, test, _deviceId);
            return true;
        }
Esempio n. 2
0
        public override bool TakeAction()
        {
            TraceLog.ReleaseWriteFatal(_orderInfo);
            //string AppUrl = ConfigUtils.GetSetting("AppStoreUrl");
            if (AppUrl == string.Empty || _orderInfo.IndexOf("Sandbox") > 0)
            {
                AppUrl = "https://sandbox.itunes.apple.com/verifyReceipt";
            }
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(AppUrl);

            req.Method = "POST";
            byte[] ReceiptData = Encoding.UTF8.GetBytes(_orderInfo);
            Dictionary <string, string> dict = new Dictionary <string, string>();

            dict.Add("receipt-data", Convert.ToBase64String(ReceiptData));
            byte[] content = Encoding.UTF8.GetBytes(JsonUtils.Serialize(dict));
            req.ContentLength = content.Length;
            Stream stream = req.GetRequestStream();

            stream.Write(content, 0, content.Length);
            stream.Close();
            WebResponse resp = req.GetResponse();

            stream = resp.GetResponseStream();

            StreamReader reader   = new StreamReader(stream);
            string       response = reader.ReadToEnd();

            req.Abort();
            resp.Close();
            TraceLog.ReleaseWriteFatal(response);

            AppStoreInfo appStoreInfo = new AppStoreInfo();

            try
            {
                appStoreInfo = JsonUtils.Deserialize <AppStoreInfo>(response);
            }
            catch (Exception ex)
            {
                this.SaveLog(ex);
                ErrorCode = LanguageManager.GetLang().ErrorCode;
                ErrorInfo = LanguageManager.GetLang().LoadDataError;
                return(false);
            }
            if (appStoreInfo.status != 0)
            {
                ErrorCode = LanguageManager.GetLang().ErrorCode;
                ErrorInfo = LanguageManager.GetLang().St1066_PayError;
                return(false);
            }
            //int silver = AppStoreHelper.GetSilverPiece(appStoreInfo.receipt.product_id, _gameID);
            //PaymentService.GetAppStore(_gameID, _serviceID, _passportId, silver, appStoreInfo.receipt.transaction_id, _deviceId);

            AppStoreHelper appStore = AppStoreHelper.GetSilverPiece(appStoreInfo.receipt.product_id, _gameID);

            PaymentService.GetAppStore(_gameID, _serviceID, _passportId, appStore.SilverPiece, appStore.RMB, appStoreInfo.receipt.transaction_id, _deviceId);
            // TraceLog.ReleaseWriteFatal("appstore完成");
            //TraceLog.ReleaseWriteFatal("GameID" + _gameID + "ServerID" + _serviceID);

            //int silver = 10;
            //string test = "1234567894561111111";
            //PaymentService.GetAppStore(_gameID, _serviceID, _passportId, silver, test, _deviceId);
            return(true);
        }