public List <OrderInfo> statusNotify(MainForm mainForm) { OrderInfoDao dao = new OrderInfoDao(); List <OrderInfo> orderInfoList = dao.statusNotify(); if (orderInfoList != null && orderInfoList.Count > 0) { foreach (OrderInfo orderInfo in orderInfoList) { try { StringBuilder sb = new StringBuilder(); sb.Append("venderId=").Append(orderInfo.vender_id).Append("&orderId=").Append(orderInfo.order_id).Append("&venderOrderId=").Append(orderInfo.vender_order_no).Append("&orderStatus=").Append(orderInfo.order_status); String sign = Share.MD5(sb.ToString() + "&key=" + Config.md5Key).ToLower(); log.Debug("statusNotify start:" + Config.notifyUrl + sb.ToString() + "&sign=" + sign); View.write("回调通知:" + Config.notifyUrl + "?" + sb.ToString() + "&sign=" + sign); String result = Share.getPageInterFace(Config.notifyUrl, sb.ToString() + "&sign=" + sign); log.Debug("statusNotify result:" + result); View.write("回调结果:" + result); if ("success".Equals(result)) { orderInfo.notify_status = "8"; } else { if (orderInfo.notify_count >= 4) { orderInfo.notify_status = "4"; } } } catch (Exception ex) { if (orderInfo.notify_count >= 4) { orderInfo.notify_status = "4"; } } int updateCount = dao.updateNotify(orderInfo); log.Debug("回调更新结果:" + updateCount); } } return(orderInfoList); }
private void loop(HttpListener httpListenner) { while (startMark) { HttpListenerRequest request = null; HttpListenerResponse response = null; StreamWriter writer = null; try { HttpListenerContext context = httpListenner.GetContext(); request = context.Request; //分析插入订单 StateHandle handle = new StateHandle(); OrderInfo phoneInfo = new OrderInfo(); phoneInfo.vender_id = request.QueryString["venderId"]; phoneInfo.order_id = request.QueryString["orderId"]; phoneInfo.face_price = request.QueryString["facePrice"]; phoneInfo.phone_no = request.QueryString["phoneNo"]; phoneInfo.provider = request.QueryString["provider"]; phoneInfo.province_code = request.QueryString["provinceCode"]; phoneInfo.city_code = request.QueryString["cityCode"]; phoneInfo.order_status = "0"; String inTime = request.QueryString["inTime"]; String sign = request.QueryString["sign"]; StringBuilder sb = new StringBuilder(); sb.Append("venderId=").Append(phoneInfo.vender_id) .Append("&orderId=").Append(phoneInfo.order_id) .Append("&phoneNo=").Append(phoneInfo.phone_no) .Append("&facePrice=").Append(phoneInfo.face_price) .Append("&provider=").Append(phoneInfo.provider) .Append("&provinceCode=").Append(phoneInfo.province_code) .Append("&cityCode=").Append(phoneInfo.city_code) .Append("&inTime=").Append(inTime) .Append("&key=").Append(Config.md5Key); String _sign = Share.MD5(sb.ToString()).ToLower(); String res = ""; if (phoneInfo.vender_id == null || "".Equals(phoneInfo.vender_id) || phoneInfo.order_id == null || "".Equals(phoneInfo.order_id) || phoneInfo.face_price == null || "".Equals(phoneInfo.face_price) || phoneInfo.phone_no == null || "".Equals(phoneInfo.phone_no) || inTime == null || "".Equals(inTime) || sign == null || "".Equals(sign) ) { res = "000001"; } else if (!_sign.Equals(sign)) { res = "000005"; } else { //验证时间戳(略) //验证订单号 int count = handle.selectCountByOrderId(phoneInfo); if (count <= 0) { int insertCount = handle.insertOrderService(phoneInfo); if (insertCount > 0) { res = "000000"; } else { res = "000003"; } } else { res = "000004"; } } response = context.Response; response.StatusCode = 200; writer = new StreamWriter(response.OutputStream); writer.Write(res); writer.Close(); response.Close(); View.write("收单接口orderId:" + phoneInfo.order_id + ",录入结果:" + res); log.Debug("收单接口orderId:" + phoneInfo.order_id + ",录入结果:" + res); } catch (Exception ex) { log.Debug("收单接口异常:" + ex); } finally { try { if (writer != null) { writer.Close(); } if (response != null) { response.Close(); } } catch (Exception ex) { log.Debug("收单接口异常:" + ex); View.write("收单接口异常:" + ex); } } } }