verifying iOS in app purchase receipt with C#

后端 未结 4 842
误落风尘
误落风尘 2021-01-31 21:31

I am verifying my ios in app purchase receipt on my server using C# web service

I got receipt as string by doing below in Xcode:



        
4条回答
  •  感情败类
    2021-01-31 21:52

    Here's an alternative asynchronous implementation using HTTPClient:

    public static async Task CheckReceiptWithAppStore()
        {
            string responseStr = null;
    
            string uri = "https://sandbox.itunes.apple.com/verifyReceipt";
    
            string receiptData = // Get your receipt from wherever you store it
    
            var json = new JObject(new JProperty("receipt-data", receiptData), 
                new JProperty("password", "paste-your-shared-secret-here")).ToString();
    
            using (var httpClient = new HttpClient())
            {        
    
                if (receiptData != null)
                {
                    HttpContent content = new StringContent(json);
    
                    try
                    {
                        Task getResponse = httpClient.PostAsync(uri, content);
                        HttpResponseMessage response = await getResponse;
                        responseStr = await response.Content.ReadAsStringAsync();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Error verifying receipt: " + e.Message);
                    }
                }
            }
    
            return responseStr;
        }
    

    The shared secret is not required for non-subscription based purchases.

提交回复
热议问题