/// <summary> /// 支付回调 /// </summary> /// <returns></returns> public ActionResult GetPayResult() { string resultFromWx = getPostStr(); if (string.IsNullOrEmpty(resultFromWx)) { return(View()); } //string path = Path.Combine(Server.MapPath("~/data"), "data" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt"); //FileInfo f = new FileInfo(path); //if (!Directory.Exists(f.DirectoryName)) // Directory.CreateDirectory(f.DirectoryName); //using (StreamWriter writer = new StreamWriter(path)) //{ // writer.Write(resultFromWx); //} var res = XDocument.Parse(resultFromWx); //通信成功 try { if (res.Element("xml").Element("return_code").Value == "SUCCESS") { if (res.Element("xml").Element("result_code").Value == "SUCCESS") { //交易成功 string transaction_id = res.Element("xml").Element("transaction_id").Value; //微信订单号 string trade_no = res.Element("xml").Element("out_trade_no").Value; //商户订单号 //查询订单是否存在 OrderViewModel model = BOrder.SearchByTradeNo(trade_no); if (model != null) { //存在 BOrder.Update("update Orders set LocalStatus='已付款' where Id=" + model.Id); } return(Content(CallWxSuccess())); } else { return(Content("支付出现问题,请返回重试")); } } } catch (Exception e) { } return(Content("failed")); }
public ActionResult KaMiList() { //查询卡密,并显示 string tNo = Request.QueryString["tNo"]; OrderViewModel order = BOrder.SearchByTradeNo(tNo); if (order == null) { return(View()); } Dictionary <int, string> kamis = BKaMi.SearchKamiByTrade(order); #region 更新卡密状态为已使用 List <KaMiViewModel> models = new List <KaMiViewModel>(); foreach (var item in kamis) { KaMiViewModel ka = new KaMiViewModel(); ka.Id = item.Key; ka.Remark = order.Remark; ka.Trade_No = tNo; models.Add(ka); } BKaMi.UpdateBySql(models); #endregion string dir = Server.MapPath("~/Files"); string path = dir + "/" + tNo + ".csv"; using (StreamWriter writer = new StreamWriter(path, true, Encoding.UTF8)) { string title = "订单号,卡密内容,联系方式\r\n"; writer.Write(title); string content = ""; foreach (var item in kamis) { content += tNo + "," + item.Value + "," + order.Remark + "\r\n"; } writer.Write(content); } ViewBag.tNo = tNo; return(View(kamis)); }
public JsonResult CheckPayResult() { string tradeNo = Request["trade_no"]; string payType = Request["payway"]; OrderViewModel model = BOrder.SearchByTradeNo(tradeNo); if (model == null) { var result = new { code = "-2", msg = "not exists" }; return(Json(LitJson.JsonMapper.ToJson(result))); } if (model.LocalStatus != "已付款") { var result = new { code = "-1", msg = "wait for pay" }; return(Json(LitJson.JsonMapper.ToJson(result))); } else { var result = new { code = "1", msg = "success" }; return(Json(LitJson.JsonMapper.ToJson(result))); } }
protected void Page_Load(object sender, EventArgs e) { SortedDictionary <string, string> sPara = GetRequestPost(); if (sPara.Count > 0)//判断是否有带返回参数 { //Notify aliNotify = new Notify(); Notify aliNotify = new Notify(Config.charset, Config.sign_type, Config.pid, Config.mapiUrl, Config.alipay_public_key); //对异步通知进行验签 bool verifyResult = aliNotify.Verify(sPara, Request.Form["notify_id"], Request.Form["sign"]); //对验签结果 //bool isSign = Aop.Api.Util.AlipaySignature.RSACheckV2(sPara, Config.alipay_public_key ,Config.charset,Config.sign_type,false ); if (verifyResult && CheckParams()) //验签成功 && 关键业务参数校验成功 { ///////////////////////////////////////////////////////////////////////////////////////////////////////////// //请在这里加上商户的业务逻辑程序代码 //——请根据您的业务逻辑来编写程序(以下代码仅作参考)—— //获取支付宝的通知返回参数,可参考技术文档中服务器异步通知参数列表 //商户订单号 string out_trade_no = Request.Form["out_trade_no"]; //支付宝交易号 string trade_no = Request.Form["trade_no"]; //交易状态 //在支付宝的业务通知中,只有交易通知状态为TRADE_SUCCESS或TRADE_FINISHED时,才是买家付款成功。 string trade_status = Request.Form["trade_status"]; if (trade_status.ToUpper() == "TRADE_SUCCESS" || trade_status.ToUpper() == "TRADE_FINISHED") { //查询订单是否存在 OrderViewModel model = BOrder.SearchByTradeNo(out_trade_no); if (model != null) { //存在 BOrder.Update("update Orders set LocalStatus='已付款' where Id=" + model.Id); } } //判断是否在商户网站中已经做过了这次通知返回的处理 //如果没有做过处理,那么执行商户的业务程序 //如果有做过处理,那么不执行商户的业务程序 Response.Write("success"); //请不要修改或删除 //——请根据您的业务逻辑来编写程序(以上代码仅作参考)—— ///////////////////////////////////////////////////////////////////////////////////////////////////////////// } else//验证失败 { Response.Write("fail"); } } else { Response.Write("无通知参数"); } }
/// <summary> /// 构造支付请求数据 /// </summary> /// <returns>请求数据集</returns> private AlipayTradePrecreateContentBuilder BuildPrecreateContent() { //线上联调时,请输入真实的外部订单号。 string out_trade_no = System.DateTime.Now.ToString("yyyyMMddHHmmss") + "0000" + (new Random()).Next(1, 10000).ToString(); string total_fee = "1"; string subject = "test"; if (!string.IsNullOrEmpty(Request.QueryString["tid"])) { out_trade_no = Request.QueryString["tid"]; } OrderViewModel order = BOrder.SearchByTradeNo(out_trade_no); if (order != null) { subject = BProduct.ExecuteSql("select Name from Products where Id=" + order.Product_Id).ToString(); total_fee = (order.Price * order.Count).ToString(); } //if (String.IsNullOrEmpty(WIDout_request_no.Text.Trim())) //{ // out_trade_no = System.DateTime.Now.ToString("yyyyMMddHHmmss") + "0000" + (new Random()).Next(1, 10000).ToString(); //} //else //{ //out_trade_no = "WF87212910290"; //} AlipayTradePrecreateContentBuilder builder = new AlipayTradePrecreateContentBuilder(); //收款账号 builder.seller_id = Config.pid; //订单编号 builder.out_trade_no = out_trade_no; //订单总金额 builder.total_amount = total_fee; //参与优惠计算的金额 //builder.discountable_amount = ""; //不参与优惠计算的金额 //builder.undiscountable_amount = ""; //订单名称 builder.subject = subject; //自定义超时时间 builder.timeout_express = "5m"; //订单描述 builder.body = ""; //门店编号,很重要的参数,可以用作之后的营销 builder.store_id = "test store id"; //操作员编号,很重要的参数,可以用作之后的营销 builder.operator_id = "test"; //传入商品信息详情 List <GoodsInfo> gList = new List <GoodsInfo>(); if (order != null) { GoodsInfo goods = new GoodsInfo(); goods.goods_id = order.Product_Id.ToString(); goods.goods_name = subject; goods.price = order.Price.ToString(); goods.quantity = order.Count.ToString();; gList.Add(goods); } else { GoodsInfo goods = new GoodsInfo(); goods.goods_id = "520"; goods.goods_name = "捐助"; goods.price = "0.1"; goods.quantity = "1"; gList.Add(goods); } builder.goods_detail = gList; //系统商接入可以填此参数用作返佣 //ExtendParams exParam = new ExtendParams(); //exParam.sysServiceProviderId = "20880000000000"; //builder.extendParams = exParam; return(builder); }