/// <summary> /// 成功后请求接口 /// </summary> /// <param name="model"></param> public void SuccessParseData(AlipayModel model) { /*判断数据库不存在,是新的数据就执行新数据事件*/ if (!sqldb.IsExist("ecpay_transfer", new KeyValuePair <string, string>("order_id", model.Order_id))) { String vfit = HttpHelper.MD5PHP(model.Order_id + "|" + model.Order_time + "|" + this.PostKey).ToUpper(); //签名,订单号,交易备注,订单时间,对方,客服id,钱,交易状态 String data = String.Format(Ecpay.Common.HttpConfigLang.Alipay_Interface_Postdata_String, vfit, model.Order_id, model.Trade_name, model.Order_time, model.Order_name, model.Order_name, model.Money, model.Trade_state); HttpItem httpitemInter = new HttpItem() { ContentType = Common.HttpConfigLang.ContentType_Post_Setting_String, Method = "Post", URL = this.InterUrl, Encoding = Encoding.UTF8, Postdata = data, }; HttpResult httpres = httpInter.GetHtml(httpitemInter); /*请求成功!*/ if (httpres.StatusCode == HttpStatusCode.OK) { model.Is_http_request = true; if (httpres.Html.Length > 200) { model.Http_notify = httpres.Html.Substring(0, 190); } else { model.Http_notify = httpres.Html; } } /*解析json*/ Dictionary <String, String> dic = new Dictionary <string, string>(); dic.Add("order_id", model.Order_id); dic.Add("order_name", model.Order_name); dic.Add("order_time", model.Order_time); dic.Add("trade_name", model.Trade_name); dic.Add("order_type", model.Order_type); dic.Add("money", model.Money); dic.Add("trade_state", model.Trade_state); dic.Add("http_notify", model.Http_notify); dic.Add("is_http_request", model.Is_http_request.ToString()); if (sqldb.Insert("ecpay_transfer", dic)) { DataUpdateEvent.Invoke(null, null); } } }
/// <summary> /// 解析详细数据 /// </summary> /// <param name="html"></param> private void GetParse(String html) { List <AlipayModel> list = new List <AlipayModel>(); HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument(); document.LoadHtml(html); /*获取table 列表*/ HtmlNode parNode = document.GetElementbyId("tradeRecordsIndex"); if (parNode == null) { return; } /*重新加载*/ document.LoadHtml(parNode.InnerHtml); /*获取tbody 的子节点tr*/ HtmlNodeCollection collection; try { collection = document.DocumentNode.SelectSingleNode("tbody").ChildNodes; } catch (Exception ex) { return; } foreach (HtmlNode node in collection) { if (node.InnerText.Trim() == "") { continue; } /*获取Tr 的子节点td*/ HtmlNodeCollection tdcoll = node.ChildNodes; AlipayModel model = new AlipayModel(); foreach (HtmlNode itemnode in tdcoll) { String str = itemnode.InnerText.Replace("\r", "").Replace("\n", "").Replace("\t", "").Replace(" ", "").Trim(); if (str.Trim() == "") { continue; } HtmlAttributeCollection attvalue = itemnode.Attributes; #region 遍历属性 /*解析td的值*/ foreach (HtmlAttribute attitem in attvalue) { str = Regex.Unescape(str); switch (attitem.Value) { case "time": { String date = str.Substring(0, 10); String time = str.Substring(10, 5); DateTime dateTime = DateTime.Parse(date + " " + time); model.Order_time = dateTime.ToString().Replace("/", "-"); } break; case "memo": { } break; case "name": { //交易类型 model.Trade_name = str; } break; case "tradeNo ft-gray": { if (str.Contains(":")) { str = str.Substring(str.LastIndexOf(":") + 1, str.Length - str.LastIndexOf(":") - 1); } model.Order_id = str; } break; case "other": { model.Order_name = str; } break; case "amount": { model.Money = str; } break; case "detail": { } break; case "status": { model.Trade_state = str; } break; case "action": { } break; default: break; } } #endregion } /*解析成功,触发成功事件*/ model.Order_type = "支付宝"; model.Is_http_request = false; SuccessParseData(model); } }