- public bool ValidateApplePay()
- {
- //客户端post过来的参数
- string appleReceipt = Request.Form["appleReceipt"]; //苹果内购的验证收据
- string orderId = PayHelper.GetOrderIDByPrefix("AP"); //订单编号
- string amount = Request.Form["amount"]; //金额
- string userId = Request.Form["userId"]; //用户UserID
- // 验证参数
- if (appleReceipt.Length < 20)
- {
- return false;
- }
- string strJosn = string.Format("{{\"receipt-data\":\"{0}\"}}", appleReceipt);
- // 请求验证
- string strResult = CreatePostHttpResponse(strJosn, isSandbox);
- JObject obj = JObject.Parse(strResult);//using Newtonsoft.Json.Linq;
- // 判断是否购买成功
- if (obj["status"].ToString() == "0")
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public string CreatePostHttpResponse(string datas, bool isSandbox = false)
- {
- //正式购买地址 沙盒购买地址
- string url_buy = "https://buy.itunes.apple.com/verifyReceipt";
- string url_sandbox = "https://sandbox.itunes.apple.com/verifyReceipt";
- string url = isSandbox ? url_sandbox : url_buy;
- HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
- request.ProtocolVersion = HttpVersion.Version10;
- request.Method = "POST";
- request.ContentType = "application/x-www-form-urlencoded";
- byte[] data = Encoding.GetEncoding("UTF-8").GetBytes(datas.ToString());
- using (Stream stream = request.GetRequestStream())
- {
- stream.Write(data, 0, data.Length);
- }
- HttpWebResponse response = request.GetResponse() as HttpWebResponse;
- Stream responseStream = response.GetResponseStream(); //获取响应的字符串流
- StreamReader sr = new StreamReader(responseStream); //创建一个stream读取流
- var str = sr.ReadToEnd();
- sr.Close();
- responseStream.Close();
- return str.ToString();
- }
苹果内购支付对接
Posted 剑舞江南
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了苹果内购支付对接相关的知识,希望对你有一定的参考价值。
以上是关于苹果内购支付对接的主要内容,如果未能解决你的问题,请参考以下文章