Apple Internal purchase Payment docking

Source: Internet
Author: User

  1. public bool Validateapplepay ()
  2. {
  3. Parameters that the client post comes in
  4. String applereceipt = request.form["Applereceipt"]; Verification receipt for Apple internal purchase
  5. String orderId = Payhelper.getorderidbyprefix ("AP"); Order number
  6. String amount = request.form["Amount"]; Amount
  7. string userid = request.form["UserId"]; User UserID
  8. Validation parameters
  9. if (Applereceipt.length < 20)
  10. {
  11. return false;
  12. }
  13. String strjosn = String. Format ("{{\" receipt-data\ ": \" {0}\ "}}", Applereceipt);
  14. Request validation
  15. String strresult = Createposthttpresponse (Strjosn, Issandbox);
  16. Jobject obj = Jobject.parse (strresult);//using Newtonsoft.Json.Linq;
  17. Determine if the purchase was successful
  18. if (obj["status"). ToString () = = "0")
  19. {
  20. return true;
  21. }
  22. Else
  23. {
  24. return false;
  25. }
  26. }
  27. public string Createposthttpresponse (string datas, bool Issandbox = False)
  28. {
  29. Official purchase address sandbox purchase address
  30. String url_buy = "Https://buy.itunes.apple.com/verifyReceipt";
  31. String url_sandbox = "Https://sandbox.itunes.apple.com/verifyReceipt";
  32. String url = issandbox? Url_sandbox:url_buy;
  33. HttpWebRequest request = webrequest.create (URL) as HttpWebRequest;
  34. Request. ProtocolVersion = Httpversion.version10;
  35. Request. Method = "POST";
  36. Request. ContentType = "application/x-www-form-urlencoded";
  37. byte[] data = encoding.getencoding ("UTF-8"). GetBytes (datas. ToString ());
  38. using (Stream stream = Request. GetRequestStream ())
  39. {
  40. Stream. Write (data, 0, data. Length);
  41. }
  42. HttpWebResponse response = Request. GetResponse () as HttpWebResponse;
  43. Stream Responsestream = Response.   GetResponseStream (); Gets the string stream of the response
  44. StreamReader sr = new StreamReader (responsestream); Create a stream to read the stream
  45. var str = Sr. ReadToEnd ();
  46. Sr. Close ();
  47. Responsestream.close ();
  48. Return str. ToString ();
  49. }

Apple Internal purchase Payment docking

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.