/// <summary> /// 获取扫码支付信息 /// </summary> /// <param name="context"></param> private void paypcGetCode(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"); if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(pay_type) || price <= 0f || string.IsNullOrWhiteSpace(order_id) || string.IsNullOrWhiteSpace(notify_url)) { context.Response.Write(JsonHelper.ObjectToJSON(new JsonData <string> { status = 0, msg = "参数信息获取失败" })); return; } string qr = ""; string errormsg = ""; if (Orders.Exists(order_id)) { qr = Orders.GetQR(order_id); if (!string.IsNullOrWhiteSpace(qr)) { context.Response.Write(JsonHelper.ObjectToJSON(new JsonData <string> { status = 1, msg = "订单已存在", data = qr })); return; } } 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 }; string jsonStr = PayCore.GetPayInfo(payRequest); if (!string.IsNullOrWhiteSpace(jsonStr)) { 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); } } } else { errormsg = "请求失败,请检查aid与app_secret是否正确配置,以及XorPay后台是否正常"; } if (!string.IsNullOrWhiteSpace(errormsg)) { context.Response.Write(JsonHelper.ObjectToJSON(new JsonData <string> { status = 0, msg = errormsg })); return; } } 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 = qr })); }
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); } }