Example #1
0
        /// <summary>
        /// 子类实现Action处理
        /// </summary>
        /// <returns></returns>
        public override bool TakeAction()
        {
            var paySection = AppStoreFactory.GetPaySection();
            var rates      = paySection.Rates;

            foreach (AppStorePayElement rate in rates)
            {
                if (rate.MobileType == MobileType.Normal || rate.MobileType == MobileType)
                {
                    appList.Add(rate);
                }
            }
            return(true);
        }
        /// <summary>
        /// 接收用户请求的参数,并根据相应类进行检测
        /// </summary>
        /// <returns></returns>
        public override bool GetUrlElement()
        {
            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 = Language.Instance.ErrorCode;
                ErrorInfo = Language.Instance.LoadDataError;
                return(false);
            }
            if (appStoreInfo.status != 0)
            {
                ErrorCode = Language.Instance.ErrorCode;
                ErrorInfo = Language.Instance.AppStorePayError;
                return(false);
            }
            var paySection = AppStoreFactory.GetPaySection();
            AppStorePayElement appStore = paySection.Rates[appStoreInfo.receipt.product_id];

            if (appStore == null)
            {
                throw new Exception(string.Format("Appstore productid:{0} payment is not configured.", appStoreInfo.receipt.product_id));
            }
            GetAppStore(_gameID, _serviceID, _passportId, appStore.SilverPiece, appStore.Currency, appStoreInfo.receipt.transaction_id, _RetailID, _deviceId);
            return(true);
        }