/// <summary> /// 订单退款 /// </summary> /// <param name="context"></param> private void refund(HttpContext context) { string aoid = PayRequest.GetFormString("aoid"); string errorMsg = ""; if (string.IsNullOrWhiteSpace(aoid)) { errorMsg = "XorPay平台订单号不能为空"; } float price = PayRequest.GetFormFloat("price", 0f); if (price <= 0f) { errorMsg = "退款金额必须大于0"; } if (!string.IsNullOrWhiteSpace(errorMsg)) { context.Response.Write(JsonHelper.ObjectToJSON(new JsonData <string> { status = 0, msg = errorMsg })); return; } string data_info = ""; try { string strInfo = PayCore.Refund(aoid, price); if (!string.IsNullOrWhiteSpace(strInfo)) { statusInfo info = JsonHelper.JSONToObject <statusInfo>(strInfo); if (info != null) { data_info = PayCore.GetDictValue(PayModel.refundStatusDict, info.status); } } } catch (Exception ex) { LogHelper.Error(ex.Message); context.Response.Write(JsonHelper.ObjectToJSON(new JsonData <string> { status = 0, msg = ex.Message })); return; } context.Response.Write(JsonHelper.ObjectToJSON(new JsonData <string> { status = 1, msg = "请求成功", data = data_info })); }
/// <summary> /// 订单查询 /// </summary> /// <param name="context"></param> private void query(HttpContext context) { string aoid = PayRequest.GetFormString("aoid"); if (string.IsNullOrWhiteSpace(aoid)) { context.Response.Write(JsonHelper.ObjectToJSON(new JsonData <string> { status = 0, msg = "XorPay平台订单号不能为空" })); return; } string data_info = ""; try { string strInfo = PayRequest.SendRequest($"https://xorpay.com/api/query/{aoid}", "", "GET", "UTF-8"); if (!string.IsNullOrWhiteSpace(strInfo)) { statusInfo info = JsonHelper.JSONToObject <statusInfo>(strInfo); if (info != null) { data_info = PayCore.GetDictValue(PayModel.queryStatusDict, info.status); } } } catch (Exception ex) { LogHelper.Error(ex.Message); context.Response.Write(JsonHelper.ObjectToJSON(new JsonData <string> { status = 0, msg = ex.Message })); return; } context.Response.Write(JsonHelper.ObjectToJSON(new JsonData <string> { status = 1, msg = "请求成功", data = data_info })); }
/// <summary> /// 获取jsapi支付参数 /// </summary> /// <param name="context"></param> private void payjsGetInfo(HttpContext context) { string name = PayRequest.GetFormString("name"); string pay_type = PayRequest.GetFormString("pay_type"); float price = PayRequest.GetFormFloat("price", 0f); string order_id = PayRequest.GetFormString("order_id"); string notify_url = PayRequest.GetFormString("notify_url"); string order_uid = PayRequest.GetFormString("order_uid"); string more = PayRequest.GetFormString("more"); string open_id = PayRequest.GetFormString("openid"); if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(pay_type) || price <= 0f || string.IsNullOrWhiteSpace(order_id) || string.IsNullOrWhiteSpace(notify_url) || string.IsNullOrWhiteSpace(open_id)) { context.Response.Write(JsonHelper.ObjectToJSON(new JsonData <string> { status = 0, msg = "参数信息获取失败" })); return; } if (Orders.Exists(order_id)) { string jsApiInfo = Orders.GetJsApiInfo(order_id); if (!string.IsNullOrWhiteSpace(jsApiInfo)) { context.Response.Write(JsonHelper.ObjectToJSON(new JsonData <string> { status = 1, msg = "订单已存在", data = order_id })); return; } } string errormsg = "请求失败"; try { PayRequestModel payRequest = new PayRequestModel { name = name, pay_type = pay_type, price = price, order_id = order_id, notify_url = notify_url, order_uid = order_uid, more = more, openid = open_id }; string jsonStr = PayCore.GetPayInfo(payRequest); if (!string.IsNullOrWhiteSpace(jsonStr)) { JsPayResponse model = JsonHelper.JSONToObject <JsPayResponse>(jsonStr); if (model != null) { if (model.status == "ok") { if (model.info != null) { var jsapiInfo = JsonHelper.ObjectToJSON(model.info); if (Orders.Add(payRequest, model.aoid, "", jsapiInfo)) { context.Response.Write(JsonHelper.ObjectToJSON(new JsonData <string> { status = 1, msg = "请求成功", data = order_id })); return; } } } else { errormsg = PayCore.GetDictValue(PayModel.payStatusDict, model.status); } } } else { errormsg = "请求失败,请检查aid与app_secret是否正确配置,以及XorPay后台是否正常"; } } catch (Exception ex) { LogHelper.Error(ex.Message); context.Response.Write(JsonHelper.ObjectToJSON(new JsonData <string> { status = 0, msg = ex.Message })); return; } context.Response.Write(JsonHelper.ObjectToJSON(new JsonData <string> { status = 0, msg = errormsg })); }
protected void Page_Load(object sender, EventArgs e) { string userAgent = Request.UserAgent; string order_no = "B" + DateTime.Now.ToString("yyyyMMddHHmmss") + new Random().Next(10, 99); float amount = PayRequest.GetQueryFloat("amount", 1f); PayConfig payConfig = new PayConfig(); string jsapi_callback = $"https://xorpay.com/api/openid/{PayConfig.aid}?callback={HttpUtility.UrlEncode(payConfig.protocol + "/unionurl.aspx?pay_type=jsapi&amount=" + amount)}"; string open_id = PayRequest.GetQueryString("openid"); if (Orders.Exists(order_no)) { qr = Orders.GetQR(order_no); if (!string.IsNullOrWhiteSpace(qr)) { return; } } string pay_type = "alipay"; if (userAgent.ToLower().Contains("alipayclient")) { pay_type = "alipay"; } else { pay_type = "native"; if (string.IsNullOrWhiteSpace(open_id)) { Response.Redirect(jsapi_callback); return; } } PayRequestModel payRequest = new PayRequestModel { name = "统一支付", pay_type = pay_type, price = 1f, order_id = order_no, notify_url = payConfig.notify_url, order_uid = "union_test", more = "统一支付test", openid = open_id }; try { if (pay_type == "native")//微信支付 { string wxUrl = PayCore.GetWXPayUrl(payRequest); if (!string.IsNullOrWhiteSpace(wxUrl)) { qr = wxUrl; } } else//默认支付宝 { string jsonStr = PayCore.GetPayInfo(payRequest); CodePayResponse model = JsonHelper.JSONToObject <CodePayResponse>(jsonStr); if (model != null) { if (model.status == "ok") { qr = ((model.info != null) ? model.info.qr : ""); Orders.Add(payRequest, model.aoid, qr); } else { errormsg = PayCore.GetDictValue(PayModel.payStatusDict, model.status); } } } } catch (Exception ex) { errormsg = "系统繁忙..."; LogHelper.Error(ex.Message); } if (!string.IsNullOrWhiteSpace(errormsg)) { Response.Write(errormsg); } }