/// <summary> /// 本示例只介绍如何请求支付凭据(charge 对象),以及如何查询指定 charge 对象和 charge 列表, /// 至于如何将 charge 对象传递给客户端需要接入者自行处理 /// </summary> public static Charge Example(string appId) { //交易请求参数,这里只列出必填参数,可选参数请参考 https://pingxx.com/document/api#api-c-new var chParams = new Dictionary <string, object> { { "order_no", new Random().Next(1, 999999999) }, { "amount", 1 }, { "channel", "wx" }, { "currency", "cny" }, { "subject", "Your Subject" }, { "body", "Your Body" }, { "client_ip", "127.0.0.1" }, { "app", new Dictionary <string, string> { { "id", appId } } } }; var ch = Charge.Create(chParams); Console.WriteLine("****发起交易请求创建 charge 对象****"); Console.WriteLine(ch); Console.WriteLine(); Console.WriteLine("****查询指定 charge 对象****"); Console.WriteLine(Charge.Retrieve(ch.Id)); Console.WriteLine(); Console.WriteLine("****查询 charge 列表****"); Console.WriteLine(Charge.List(new Dictionary <string, object> { { "limit", 3 } })); Console.WriteLine(); return(ch); }
/// <summary> /// 本示例只介绍如何请求支付凭据(charge 对象),以及如何查询指定 charge 对象和 charge 列表, /// 至于如何将 charge 对象传递给客户端需要接入者自行处理 /// </summary> public static void Example(string appId) { //交易请求参数,这里之列出必填参数,可选参数请参考 https://pingxx.com/document/api#api-c-new var chargeParam = new Dictionary <string, object> { { "order_no", new Random().Next(1, 999999999) }, { "amount", 1 }, { "channel", "cnp_u" }, { "currency", "cny" }, { "subject", "Your Subject" }, { "body", "Your Body" }, { "client_ip", "127.0.0.1" }, { "app", new Dictionary <string, object> { { "id", appId } } }, { "extra", new Dictionary <string, object> { { "sms_code", new Dictionary <string, object> { { "code", "123456" }, { "id", "123456" } } }, { "source", "tok_Ca1GS4Ha9aL01i5ubHHC8CaP" } } } }; var ch = Charge.Create(chargeParam); Console.WriteLine("****发起交易请求创建 charge 对象****"); Console.WriteLine(ch); Console.WriteLine(); Console.WriteLine("****查询指定 charge 对象****"); Console.WriteLine(Charge.Retrieve(ch.Id)); Console.WriteLine(); Console.WriteLine("****查询 charge 列表****"); Dictionary <string, object> listParams = new Dictionary <string, object> { { "app", new Dictionary <string, string> { { "id", appId } } }, { "limit", 3 }, { "paid", true } }; Console.WriteLine(); }
public async Task <Charge> Index([FromBody] ChargeModel input) { Pingpp.Pingpp.SetApiKey("sk_test_ibbTe5jLGCi5rzfH4OqPW9KC"); const string appId = "app_1Gqj58ynP0mHeX1q"; var extra = new Dictionary <string, object>(); if (input.Channel.Equals("alipay_wap")) { extra.Add("success_url", "http://www.yourdomain.com/success"); extra.Add("cancel_url", "http://www.yourdomain.com/cancel"); } else if (input.Channel.Equals("wx_pub")) { extra.Add("open_id", "asdfasdfsadfasdf"); } else if (input.Channel.Equals("upacp_wap")) { extra.Add("result_url", "http://www.yourdomain.com/result"); } else if (input.Channel.Equals("upmp_wap")) { extra.Add("result_url", "http://www.yourdomain.com/result?code="); } else if (input.Channel.Equals("bfb_wap")) { extra.Add("result_url", "http://www.yourdomain.com/result"); extra.Add("bfb_login", true); } else if (input.Channel.Equals("wx_pub_qr")) { extra.Add("product_id", "asdfsadfadsf"); } else if (input.Channel.Equals("yeepay_wap")) { extra.Add("product_category", "1"); extra.Add("identity_id", "sadfsdaf"); extra.Add("identity_type", 1); extra.Add("terminal_type", 1); extra.Add("terminal_id", "sadfsadf"); extra.Add("user_ua", "sadfsdaf"); extra.Add("result_url", "http://www.yourdomain.com/result"); } else if (input.Channel.Equals("jdpay_wap")) { extra.Add("success_url", "http://www.yourdomain.com/success"); extra.Add("fail_url", "http://www.yourdomain.com/fail"); extra.Add("token", "fjdilkkydoqlpiunchdysiqkanczxude"); //32 位字符串,京东支付成功后会返回 } var param = new Dictionary <string, object> { { "order_no", input.Order_no }, { "amount", input.Amount }, { "channel", input.Channel }, { "currency", "cny" }, { "subject", "test" }, { "body", "tests" }, { "client_ip", "127.0.0.1" }, { "app", new Dictionary <string, string> { { "id", appId } } }, { "extra", extra } }; var charge = await Charge.Create(param); return(charge); }
public Charge CreateCharges(string apiKey, string appId, string channel, string orderno, decimal amount, string subject, string body, string type) { //Pingpp.apiKey = Config.ApiKey; Pingpp.Pingpp.SetApiKey(apiKey); ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; Dictionary <string, object> extra = new Dictionary <string, object>(); if (channel.ToString().Equals("alipay_wap")) { //extra.Add("success_url", ConfigurationManager.AppSettings["Alipay_url"]); //支付宝支付成功回调地址 //extra.Add("cancel_url", "http://www.yourdomain.com/cancel"); } else if (channel.ToString().Equals("wx_pub")) { extra.Add("open_id", ConfigurationManager.AppSettings["Open_id"]); } else if (channel.ToString().Equals("upacp_wap")) { extra.Add("result_url", "http://www.yourdomain.com/result"); } else if (channel.ToString().Equals("upmp_wap")) { extra.Add("result_url", "http://www.yourdomain.com/result?code="); } else if (channel.ToString().Equals("bfb_wap")) { extra.Add("result_url", "http://www.yourdomain.com/result"); extra.Add("bfb_login", true); } else if (channel.ToString().Equals("wx_pub_qr")) { extra.Add("product_id", "asdfsadfadsf"); } else if (channel.ToString().Equals("yeepay_wap")) { extra.Add("product_category", "1"); extra.Add("identity_id", "sadfsdaf"); extra.Add("identity_type", 1); extra.Add("terminal_type", 1); extra.Add("terminal_id", "sadfsadf"); extra.Add("user_ua", "sadfsdaf"); extra.Add("result_url", "http://www.yourdomain.com/result"); } else if (channel.ToString().Equals("jdpay_wap")) { extra.Add("success_url", "http://www.yourdomain.com/success"); extra.Add("fail_url", "http://www.yourdomain.com/fail"); extra.Add("token", "fjdilkkydoqlpiunchdysiqkanczxude");//32 位字符串 } Dictionary <string, string> app = new Dictionary <string, string>(); //app.Add("id", Config.AppId); app.Add("id", appId); Dictionary <string, object> param = new Dictionary <string, object>(); param.Add("order_no", orderno); param.Add("amount", amount * 100); param.Add("channel", channel); param.Add("currency", "cny"); param.Add("subject", subject); param.Add("body", body); IPHostEntry myEntry = Dns.GetHostEntry(Dns.GetHostName()); string ipaddress = myEntry.AddressList.FirstOrDefault <IPAddress>(c => c.AddressFamily.ToString().Equals("InterNetwork")).ToString(); param.Add("client_ip", ipaddress); param.Add("app", app); param.Add("extra", extra); Dictionary <string, string> metadata = new Dictionary <string, string>(); metadata.Add("type", type); param.Add("metadata", metadata); try { Charge charge = Charge.Create(param); log.Info("---------------Charge对象----------------"); log.Info(charge.ToString()); log.Info("------------------Ping++日志END---------------------------"); //return JsonConvert.SerializeObject(model); return(charge); } catch (Exception) { return(null); //return JsonConvert.SerializeObject(model); } }
protected void Page_Load(object sender, EventArgs e) { Pingpp.Pingpp.SetApiKey("sk_test_ibbTe5jLGCi5rzfH4OqPW9KC"); const string appId = "app_1Gqj58ynP0mHeX1q"; if (Request.RequestType.ToUpper().Equals("POST")) { //获取 post 的 data var jObject = JObject.Parse(ReadStream(Request.InputStream)); var amount = jObject.SelectToken("amount"); var channel = jObject.SelectToken("channel"); var orderNo = jObject.SelectToken("order_no"); var extra = new Dictionary <string, object>(); if (channel.ToString().Equals("alipay_wap")) { extra.Add("success_url", "http://www.yourdomain.com/success"); extra.Add("cancel_url", "http://www.yourdomain.com/cancel"); } else if (channel.ToString().Equals("wx_pub")) { extra.Add("open_id", "asdfasdfsadfasdf"); } else if (channel.ToString().Equals("upacp_wap")) { extra.Add("result_url", "http://www.yourdomain.com/result"); } else if (channel.ToString().Equals("upmp_wap")) { extra.Add("result_url", "http://www.yourdomain.com/result?code="); } else if (channel.ToString().Equals("bfb_wap")) { extra.Add("result_url", "http://www.yourdomain.com/result"); extra.Add("bfb_login", true); } else if (channel.ToString().Equals("wx_pub_qr")) { extra.Add("product_id", "asdfsadfadsf"); } else if (channel.ToString().Equals("yeepay_wap")) { extra.Add("product_category", "1"); extra.Add("identity_id", "sadfsdaf"); extra.Add("identity_type", 1); extra.Add("terminal_type", 1); extra.Add("terminal_id", "sadfsadf"); extra.Add("user_ua", "sadfsdaf"); extra.Add("result_url", "http://www.yourdomain.com/result"); } else if (channel.ToString().Equals("jdpay_wap")) { extra.Add("success_url", "http://www.yourdomain.com/success"); extra.Add("fail_url", "http://www.yourdomain.com/fail"); extra.Add("token", "fjdilkkydoqlpiunchdysiqkanczxude");//32 位字符串,京东支付成功后会返回 } var param = new Dictionary <string, object> { { "order_no", orderNo }, { "amount", amount }, { "channel", channel }, { "currency", "cny" }, { "subject", "test" }, { "body", "tests" }, { "client_ip", "127.0.0.1" }, { "app", new Dictionary <string, string> { { "id", appId } } }, { "extra", extra } }; try { var charge = Charge.Create(param); Response.Write(charge); } catch (Exception ex) { Response.Write(ex.Message); } } }
/// <summary> /// 获取支付凭据 /// </summary> /// <param name="transactionId">交易Id</param> /// <param name="paymentChannel">支付渠道</param> /// <param name="userAgent">客户端的UserAgent</param> /// <param name="ipAddress">客户端的Ip地址</param> /// <param name="charge">返回的支付凭据</param> /// <param name="realResultUrl">返回的结果Url</param /// <param name="waitResultUrl">等待返回的结果Url</param>> public virtual void GetCharge( Guid transactionId, string paymentChannel, string userAgent, string ipAddress, out Charge charge, out string realResultUrl, out string waitResultUrl) { var transactionManager = Application.Ioc.Resolve <PaymentTransactionManager>(); PaymentTransaction transaction; PaymentApi api; ApiData apiData; using (UnitOfWork.Scope()) { // 获取交易和支付接口 transaction = transactionManager.Get(transactionId); api = transaction == null ? null : transaction.Api; // 检查交易和接口是否存在 if (transaction == null) { throw new BadRequestException(new T("Payment transaction not found")); } else if (api == null) { throw new BadRequestException(new T("Payment api not exist")); } // 检查当前登录用户是否可以支付 var result = transaction.Check(c => c.IsPayerLoggedIn); if (!result.First) { throw new BadRequestException(result.Second); } result = transaction.Check(c => c.IsPayable); if (!result.First) { throw new BadRequestException(result.Second); } apiData = transaction.Api.ExtraData.GetOrDefault <ApiData>("ApiData") ?? new ApiData(); } // 检查货币,虽然Ping++有提供货币参数但是支付渠道里面都只能支付人民币 if (transaction.CurrencyType != "CNY") { throw new BadRequestException(new T("Ping++ only support cny payment")); } // 获取Ping++的支付凭据 // 注意这里非线程安全,如果添加多个Ping++接口可能会出问题 Pingpp.SetApiKey(apiData.TradeSecretKey); Pingpp.SetPrivateKey(apiData.PartnerRsaPrivateKey); var configManager = Application.Ioc.Resolve <GenericConfigManager>(); var websiteSettings = configManager.GetData <WebsiteSettings>(); var extra = new Dictionary <string, object>(); realResultUrl = PaymentUtils.GetReturnOrNotifyUrl( apiData.ReturnDomain, transactionManager.GetResultUrl(transactionId)); waitResultUrl = PaymentUtils.GetReturnOrNotifyUrl( apiData.ReturnDomain, GetWaitResultUrl(transactionId)); if (paymentChannel == "alipay_wap" || paymentChannel == "alipay_pc_direct") { // 支付宝支付 extra["success_url"] = waitResultUrl; } else if (paymentChannel == "bfb_wap") { // 百度钱包支付 extra["result_url"] = waitResultUrl; extra["bfb_login"] = apiData.BfbRequireLogin; } else if (paymentChannel == "upacp_wap" || paymentChannel == "upacp_pc") { // 银联支付 extra["result_url"] = waitResultUrl; } else if (paymentChannel == "wx" || paymentChannel == "wx_pub" || paymentChannel == "wx_pub_qr" || paymentChannel == "wx_wap") { // 微信支付 if (apiData.WeChatNoCredit) { extra["limit_pay"] = "no_credit"; } if (paymentChannel == "wx_pub") { extra["open_id"] = apiData.WeChatOpenId; } else if (paymentChannel == "wx_pub_qr") { extra["product_id"] = transaction.ExtraData .GetOrDefault <string>("WeChatProductId") ?? "0"; } else if (paymentChannel == "wx_wap") { extra["result_url"] = waitResultUrl; } } else if (paymentChannel == "jdpay_wap") { // 京东支付 extra["success_url"] = waitResultUrl; extra["fail_url"] = realResultUrl; } else if (paymentChannel == "fqlpay_wap") { // 分期乐支付 extra["c_merch_id"] = apiData.FqlChildMerchantId; extra["return_url"] = waitResultUrl; } else if (paymentChannel == "qgbc_wap") { // 量化派支付 extra["phone"] = transaction.ExtraData .GetOrDefault <string>("QgbcBuyerMobile") ?? "0"; extra["return_url"] = waitResultUrl; } else if (paymentChannel == "qpay") { // QQ钱包 var isIOS = userAgent.Contains("iphone") || userAgent.Contains("ipad"); extra["device"] = isIOS ? "ios" : "android"; } var chargeParams = new Dictionary <string, object> { { "order_no", transaction.Serial }, { "amount", checked ((int)(transaction.Amount * 100)) }, { "channel", paymentChannel }, { "currency", "cny" }, { "subject", $"{new T(websiteSettings.WebsiteName)} {transaction.Serial}" }, { "body", transaction.Description }, { "client_ip", ipAddress }, { "app", new Dictionary <string, string> { { "id", apiData.PingppAppId } } }, { "extra", extra } }; charge = Charge.Create(chargeParams); }