-
苹果内购支付对接
- 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();
- }
-
相关阅读:
深入理解javascript函数进阶系列第三篇——函数节流和函数防抖
深入理解javascript函数进阶系列第二篇——函数柯里化
深入理解javascript函数进阶系列第一篇——高阶函数
javascript面向对象系列第四篇——OOP中的常见概念
CSS以图换字的9种方法
javascript面向对象系列第三篇——实现继承的3种形式
使用gitbook
linux云服务器常用设置
Git要点
Linux环境下安装NodeJS和mongoDB
-
原文地址:https://www.cnblogs.com/morpheusliu/p/8042763.html
Copyright © 2020-2023
润新知