protected void Page_Load(object sender, EventArgs e) { string type = Request.Form["querytype"]; if (type == "aliquery") { typeChannel = "Ali"; Response.Write("<span style='color:#00CD00;font-size:20px'>" + "Ali" + "</span><br/>"); BCPayQueryResult result = BCPay.BCPayQueryByCondition("ALI", null, null, null, null, 50); bills = result.bills; Response.Write("<span style='color:#00CD00;font-size:20px'>" + result.resultCode + "</span><br/>"); Response.Write("<span style='color:#00CD00;font-size:20px'>" + result.resultMsg + "</span><br/>"); Response.Write("<span style='color:#00CD00;font-size:20px'>" + result.errDetail + "</span><br/>"); } if (type == "wxquery") { typeChannel = "WX"; Response.Write("<span style='color:#00CD00;font-size:20px'>" + "WX" + "</span><br/>"); BCPayQueryResult result = BCPay.BCPayQueryByCondition("WX", null, null, null, null, 50); bills = result.bills; Response.Write("<span style='color:#00CD00;font-size:20px'>" + result.resultCode + "</span><br/>"); Response.Write("<span style='color:#00CD00;font-size:20px'>" + result.resultMsg + "</span><br/>"); Response.Write("<span style='color:#00CD00;font-size:20px'>" + result.errDetail + "</span><br/>"); } if (type == "unionquery") { typeChannel = "UN"; Response.Write("<span style='color:#00CD00;font-size:20px'>" + "UN" + "</span><br/>"); BCPayQueryResult result = BCPay.BCPayQueryByCondition("UN", null, null, null, null, 50); bills = result.bills; Response.Write("<span style='color:#00CD00;font-size:20px'>" + result.resultCode + "</span><br/>"); Response.Write("<span style='color:#00CD00;font-size:20px'>" + result.resultMsg + "</span><br/>"); Response.Write("<span style='color:#00CD00;font-size:20px'>" + result.errDetail + "</span><br/>"); } this.bind(); }
/// <summary> /// 支付订单查询 /// </summary> /// <param name="channel">渠道类型 /// 选填 /// 可以通过enum BCPay.QueryChannel获取 /// channel的参数值含义: /// WX: 微信所有类型支付 /// WX_APP: 微信手机APP支付 /// WX_NATIVE: 微信公众号二维码支付 /// WX_JSAPI: 微信公众号支付 /// ALI: 支付宝所有类型支付 /// ALI_APP: 支付宝APP支付 /// ALI_WEB: 支付宝网页支付 /// ALI_QRCODE: 支付宝内嵌二维码支付 /// UN: 银联所有类型支付 /// UN_APP: 银联APP支付 /// UN_WEB: 银联网页支付 /// 注意:不传channel也能查询的前提是保证所有渠道所有订单号不同,如果出现两个订单号重复,会报错提示传入channel进行区分 /// </param> /// <param name="billNo">商户订单号 /// </param> /// <param name="startTime">起始时间 /// 毫秒时间戳, 13位, 可以使用BCUtil.GetTimeStamp()方法获取 /// 选填 /// </param> /// <param name="endTime">结束时间 /// 毫秒时间戳, 13位, 可以使用BCUtil.GetTimeStamp()方法获取 /// 选填 /// </param> /// <param name="skip">查询起始位置 /// 默认为0。设置为10表示忽略满足条件的前10条数据 /// 选填 /// </param> /// <param name="limit">查询的条数 /// 默认为10,最大为50。设置为10表示只返回满足条件的10条数据 /// 选填 /// </param> /// <returns></returns> public static BCPayQueryResult BCPayQueryByCondition(string channel, string billNo, long?startTime, long?endTime, int?skip, int?limit) { Random random = new Random(); string payQueryUrl = BCPrivateUtil.mLocalDefaultHosts[random.Next(0, 4)] + BCConstants.version + BCConstants.billsURL; long timestamp = BCUtil.GetTimeStamp(DateTime.Now); JsonData data = new JsonData(); data["app_id"] = BCCache.Instance.appId; data["app_sign"] = BCPrivateUtil.getAppSignature(BCCache.Instance.appId, BCCache.Instance.appSecret, timestamp.ToString()); data["timestamp"] = timestamp; data["channel"] = channel; data["bill_no"] = billNo; data["start_time"] = startTime; data["end_time"] = endTime; data["skip"] = skip; data["limit"] = limit; string paraString = data.ToJson(); try { string url = payQueryUrl + "?para=" + HttpUtility.UrlEncode(paraString, Encoding.UTF8); HttpWebResponse response = BCPrivateUtil.CreateGetHttpResponse(url, BCCache.Instance.networkTimeout, null, null); string respString = BCPrivateUtil.GetResponseString(response); JsonData responseData = JsonMapper.ToObject(respString); BCPayQueryResult result = new BCPayQueryResult(); result.resultCode = int.Parse(responseData["result_code"].ToString()); result.resultMsg = responseData["result_msg"].ToString(); if (result.resultCode == 0) { result.count = int.Parse(responseData["count"].ToString()); if (responseData["bills"].IsArray) { List <BCBill> bills = new List <BCBill>(); foreach (JsonData billData in responseData["bills"]) { BCBill bill = new BCBill(); bill.title = billData["title"].ToString(); bill.totalFee = int.Parse(billData["total_fee"].ToString()); bill.createdTime = BCUtil.GetDateTime((long)billData["created_time"]); bill.billNo = billData["bill_no"].ToString(); bill.result = (bool)billData["spay_result"]; bill.channel = billData["channel"].ToString(); bills.Add(bill); } result.bills = bills; } } else { result.errDetail = responseData["err_detail"].ToString(); } return(result); } catch (Exception e) { BCPayQueryResult result = new BCPayQueryResult(); result.resultCode = 99; result.resultMsg = e.Message; return(result); } }
/// <summary> /// 支付订单查询 /// </summary> /// <param name="channel">渠道类型 /// 选填 /// 可以通过enum BCPay.QueryChannel获取 /// channel的参数值含义: /// WX_APP: 微信手机APP支付 /// WX_NATIVE: 微信公众号二维码支付 /// WX_JSAPI: 微信公众号支付 /// ALI_APP: 支付宝APP支付 /// ALI_WEB: 支付宝网页支付 /// ALI_QRCODE: 支付宝内嵌二维码支付 /// UN_APP: 银联APP支付 /// UN_WEB: 银联网页支付 /// JD_WAP: 京东wap支付 /// JD_WEB: 京东web支付 /// YEE_WAP: 易宝wap支付 /// YEE_WEB: 易宝web支付 /// KUAIQIAN_WAP: 快钱wap支付 /// KUAIQIAN_WEB: 快钱web支付 /// 注意:不传channel也能查询的前提是保证所有渠道所有订单号不同,如果出现两个订单号重复,会报错提示传入channel进行区分 /// </param> /// <param name="billNo">商户订单号 /// </param> /// <param name="startTime">起始时间 /// 毫秒时间戳, 13位, 可以使用BCUtil.GetTimeStamp()方法获取 /// 选填 /// </param> /// <param name="endTime">结束时间 /// 毫秒时间戳, 13位, 可以使用BCUtil.GetTimeStamp()方法获取 /// 选填 /// </param> /// <param name="skip">查询起始位置 /// 默认为0。设置为10表示忽略满足条件的前10条数据 /// 选填 /// </param> /// <param name="limit">查询的条数 /// 默认为10,最大为50。设置为10表示只返回满足条件的10条数据 /// 选填 /// </param> /// <returns></returns> public static BCPayQueryResult BCPayQueryByCondition(string channel, string billNo, long? startTime, long? endTime, int? skip, int? limit) { Random random = new Random(); string payQueryUrl = BCPrivateUtil.mLocalDefaultHosts[random.Next(0, 4)] + BCConstants.version + BCConstants.billsURL; long timestamp = BCUtil.GetTimeStamp(DateTime.Now); JsonData data = new JsonData(); data["app_id"] = BCCache.Instance.appId; data["app_sign"] = BCPrivateUtil.getAppSignature(BCCache.Instance.appId, BCCache.Instance.appSecret, timestamp.ToString()); data["timestamp"] = timestamp; data["channel"] = channel; data["bill_no"] = billNo; data["start_time"] = startTime; data["end_time"] = endTime; data["skip"] = skip; data["limit"] = limit; string paraString = data.ToJson(); try { string url = payQueryUrl + "?para=" + HttpUtility.UrlEncode(paraString, Encoding.UTF8); HttpWebResponse response = BCPrivateUtil.CreateGetHttpResponse(url, BCCache.Instance.networkTimeout, null, null); string respString = BCPrivateUtil.GetResponseString(response); JsonData responseData = JsonMapper.ToObject(respString); BCPayQueryResult result = new BCPayQueryResult(); result.resultCode = int.Parse(responseData["result_code"].ToString()); result.resultMsg = responseData["result_msg"].ToString(); if (result.resultCode == 0) { result.count = int.Parse(responseData["count"].ToString()); if (responseData["bills"].IsArray) { List<BCBill> bills = new List<BCBill>(); foreach (JsonData billData in responseData["bills"]) { BCBill bill = new BCBill(); bill.title = billData["title"].ToString(); bill.totalFee = int.Parse(billData["total_fee"].ToString()); bill.createdTime = BCUtil.GetDateTime((long)billData["created_time"]); bill.billNo = billData["bill_no"].ToString(); bill.result = (bool)billData["spay_result"]; bill.channel = billData["channel"].ToString(); bills.Add(bill); } result.bills = bills; } } else { result.errDetail = responseData["err_detail"].ToString(); } return result; } catch(Exception e) { BCPayQueryResult result = new BCPayQueryResult(); result.resultCode = 99; result.resultMsg = e.Message; return result; } }