/// <summary> /// 获取众筹订单详情 /// </summary> /// <returns></returns> private string Get(HttpContext context) { string recordID = context.Request["order_id"]; CrowdFundRecord crowdFundRecord = bll.Get <CrowdFundRecord>(string.Format(" RecordID={0}", recordID)); CrowdFundInfo crowdFundInfo = bll.Get <CrowdFundInfo>(string.Format(" CrowdFundID={0}", crowdFundRecord.CrowdFundID)); var item = bll.Get <CrowdFundItem>(string.Format("ItemId={0}", crowdFundRecord.ItemId)); var data = new { receiver_name = crowdFundRecord.Name, receiver_phone = crowdFundRecord.Phone, receiver_address = crowdFundRecord.ReceiveAddress, crowdfund_img_url = bll.GetImgUrl(crowdFundInfo.CoverImage), crowdfund_title = crowdFundInfo.Title, order_amount = crowdFundRecord.Amount, order_id = crowdFundRecord.RecordID, order_status = crowdFundRecord.OrderStatus, crowdfund_originator = crowdFundInfo.Originator, order_time = crowdFundRecord.InsertDate != null?bll.GetTimeStamp((DateTime)crowdFundRecord.InsertDate) : 0, order_pay_time = crowdFundRecord.PayTime != null?bll.GetTimeStamp((DateTime)crowdFundRecord.PayTime) : 0, order_delivery_time = crowdFundRecord.DeliveryTime != null?bll.GetTimeStamp((DateTime)crowdFundRecord.DeliveryTime) : 0, express_company_name = crowdFundRecord.ExpressCompanyName, express_number = crowdFundRecord.ExpressNumber, express_company_code = crowdFundRecord.ExpressCompanyCode, item_productname = item.ProductName }; return(ZentCloud.Common.JSONHelper.ObjectToJson(data)); }
/// <summary> /// 确认收货 /// </summary> /// <param name="context"></param> /// <returns></returns> private string ReceiptConfirm(HttpContext context) { string orderId = context.Request["order_id"]; if (string.IsNullOrEmpty(orderId)) { resp.errmsg = "订单号错误"; resp.errcode = 1; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } CrowdFundRecord orderInfo = bll.Get <CrowdFundRecord>(string.Format(" RecordID={0} AND UserID='{1}' AND WebsiteOwner='{2}'", orderId, currentUserInfo.UserID, bll.WebsiteOwner)); if (orderInfo == null) { resp.errmsg = "订单不存在"; resp.errcode = 1; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } orderInfo.OrderStatus = "确认收货"; if (bll.Update(orderInfo)) { resp.errmsg = "ok"; resp.errcode = 0; } else { resp.errcode = -1; resp.errmsg = "确认收货出错"; } return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); }
/// <summary> /// 添加付款记录 /// </summary> /// <param name="context"></param> /// <returns></returns> private string AddCrowdFundRecord(HttpContext context) { CrowdFundRecord model = bllBase.ConvertRequestToModel <CrowdFundRecord>(new CrowdFundRecord()); model.UserID = bllBase.GetCurrUserID(); model.RecordID = int.Parse(bllBase.GetGUID(ZentCloud.BLLJIMP.TransacType.CommAdd)); model.InsertDate = DateTime.Now; if (model.Amount <= 0) { resp.Msg = "金额需大于0"; goto outoff; } if (bllBase.Add(model)) { resp.Status = 1; resp.ExInt = model.RecordID; } else { resp.Status = 0; resp.Msg = "付款失败"; } outoff: return(Common.JSONHelper.ObjectToJson(resp)); }
protected void Page_Load(object sender, EventArgs e) { try { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(Request.InputStream); xmlDoc.Save(string.Format("C:\\WXPay\\NotifyCrowdFund{0}.xml", DateTime.Now.ToString("yyyyMMddHHmmssfff")));//写入日志 //全部参数 Dictionary <string, string> parametersAll = new Dictionary <string, string>(); foreach (XmlElement item in xmlDoc.DocumentElement.ChildNodes) { string key = item.Name; string value = item.InnerText; if ((!string.IsNullOrEmpty(key)) && (!string.IsNullOrEmpty(value))) { parametersAll.Add(key, value); } } parametersAll = (from entry in parametersAll orderby entry.Key ascending select entry).ToDictionary(pair => pair.Key, pair => pair.Value);//全部参数排序 //验签参数 不包括 sign 参数 Dictionary <string, string> parametersSign = (from entry in parametersAll where !entry.Key.Equals("sign") orderby entry.Key ascending select entry).ToDictionary(pair => pair.Key, pair => pair.Value); CrowdFundRecord record = bllPay.Get <CrowdFundRecord>(string.Format(" RecordID={0}", parametersAll["out_trade_no"])); var payConfig = bllPay.GetPayConfig(); string strSign = Payment.WeiXin.CommonUtil.FormatBizQueryParaMap(parametersSign, false); if (!MD5SignUtil.VerifySignature(strSign, parametersAll["sign"], payConfig.WXPartnerKey))//验证签名 { Response.Write("<xml><return_code><![CDATA[FAIL]]></return_code></xml>"); return; } if (record == null) { Response.Write("<xml><return_code><![CDATA[FAIL]]></return_code></xml>"); return; } if (record.Status.Equals(1)) { Response.Write("<xml><return_code><![CDATA[SUCCESS]]></return_code></xml>"); return; } if (record.Status.Equals(0))//只有未付款状态 { ZentCloud.ZCBLLEngine.BLLTransaction tran = new ZCBLLEngine.BLLTransaction(); try { record.Status = 1; if (!bllPay.Update(record, tran)) { tran.Rollback(); Response.Write("<xml><return_code><![CDATA[FAIL]]></return_code></xml>"); } tran.Commit(); Response.Write("<xml><return_code><![CDATA[SUCCESS]]></return_code></xml>"); return; } catch { tran.Rollback(); Response.Write("<xml><return_code><![CDATA[FAIL]]></return_code></xml>"); } } Response.Write("<xml><return_code><![CDATA[SUCCESS]]></return_code></xml>"); } catch (Exception) { Response.Write("<xml><return_code><![CDATA[FAIL]]></return_code></xml>"); } }
/// <summary> /// 下单 /// </summary> /// <param name="context"></param> /// <returns></returns> private string Add(HttpContext context) { RequestModel requestModel; try { requestModel = ZentCloud.Common.JSONHelper.JsonToModel <RequestModel>(context.Request["data"]); CrowdFundItem itemInfo = bll.Get <CrowdFundItem>(string.Format(" ItemId={0} And Websiteowner='{1}' And CrowdFundID={2}", requestModel.crowdfund_item_id, bll.WebsiteOwner, requestModel.crowdfund_id)); if (itemInfo == null) { resp.errcode = 1; resp.errmsg = " crowdfund_item_id,crowdfund_id 不存在,请检查"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } CrowdFundRecord model = new CrowdFundRecord(); model.UserID = currentUserInfo.UserID; model.Amount = itemInfo.Amount; model.CrowdFundID = itemInfo.CrowdFundID; model.InsertDate = DateTime.Now; model.ItemId = itemInfo.ItemId; model.Name = requestModel.receiver_name; model.Phone = requestModel.receiver_phone; model.ReceiveAddress = requestModel.receiver_address; model.RecordID = int.Parse(bll.GetGUID(BLLJIMP.TransacType.CommAdd)); model.WebsiteOwner = bll.WebsiteOwner; model.CrowdFundID = itemInfo.CrowdFundID; model.OrderStatus = "待付款"; model.BuyerMemo = requestModel.buyer_memo; CrowdFundInfo crowdFundInfo = bll.Get <CrowdFundInfo>(string.Format(" CrowdFundID={0} ", requestModel.crowdfund_id)); if (crowdFundInfo == null) { resp.errcode = 1; resp.errmsg = " 众筹不存在"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } if (crowdFundInfo.Status == 0) { resp.errcode = 1; resp.errmsg = " 众筹已停止"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } if (DateTime.Now >= crowdFundInfo.StopTime) { resp.errcode = 1; resp.errmsg = " 众筹已到截止时间"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } //检查必填项 if (string.IsNullOrEmpty(model.Name)) { resp.errcode = 1; resp.errmsg = " 收货人姓名不能为空"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } if (string.IsNullOrEmpty(model.Phone)) { resp.errcode = 1; resp.errmsg = " 收货人电话不能为空"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } if (string.IsNullOrEmpty(model.ReceiveAddress)) { resp.errcode = 1; resp.errmsg = " 收货地址不能为空"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } if (!bll.Add(model)) { resp.errcode = 1; resp.errmsg = "下单失败"; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } return(ZentCloud.Common.JSONHelper.ObjectToJson(new { errcode = 0, errmsg = "ok", order_id = model.RecordID })); } catch (Exception ex) { resp.errcode = 1; resp.errmsg = "JSON格式错误,请检查。错误信息:" + ex.Message; return(ZentCloud.Common.JSONHelper.ObjectToJson(resp)); } }
protected void Page_Load(object sender, EventArgs e) { try { #region 检查订单是否可以支付 int recordId = int.Parse(Request["recordid"]); CrowdFundRecord model = bllBase.Get <CrowdFundRecord>(string.Format(" RecordID={0}", recordId)); if (model == null) { Response.Write("订单无效"); Response.End(); } if (model.Status.Equals(1)) { Response.Write("订单已经付款"); Response.End(); } #endregion #region 获取预支付ID PayConfig payConfig = bllPay.GetPayConfig(); var nonStr = Payment.WeiXin.CommonUtil.CreateNoncestr();//随机串 // Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("appid", payConfig.WXAppId); dic.Add("body", "订单号" + model.RecordID); dic.Add("mch_id", payConfig.WXMCH_ID); dic.Add("nonce_str", nonStr); dic.Add("out_trade_no", model.RecordID.ToString()); dic.Add("openid", DataLoadTool.GetCurrUserModel().WXOpenId); dic.Add("spbill_create_ip", Request.UserHostAddress); dic.Add("total_fee", (model.Amount * 100).ToString("F0")); dic.Add("notify_url", string.Format("http://{0}/WxPayNotify/NotifyCrowdFund.aspx", Request.Url.Host)); dic.Add("trade_type", "JSAPI"); string strtemp = Payment.WeiXin.CommonUtil.FormatBizQueryParaMap(dic, false); string sign = MD5SignUtil.Sign(strtemp, payConfig.WXPartnerKey); dic = (from entry in dic orderby entry.Key ascending select entry).ToDictionary(pair => pair.Key, pair => pair.Value); dic.Add("sign", sign); string postData = Payment.WeiXin.CommonUtil.ArrayToXml(dic); string url = "https://api.mch.weixin.qq.com/pay/unifiedorder"; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); byte[] requestBytes = System.Text.Encoding.UTF8.GetBytes(postData); req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; req.ContentLength = requestBytes.Length; Stream requestStream = req.GetRequestStream(); requestStream.Write(requestBytes, 0, requestBytes.Length); requestStream.Close(); HttpWebResponse res = (HttpWebResponse)req.GetResponse(); StreamReader sr = new StreamReader(res.GetResponseStream(), System.Text.Encoding.UTF8); string backStr = sr.ReadToEnd(); sr.Close(); res.Close(); var result = XDocument.Parse(backStr); var returnCode = result.Element("xml").Element("return_code").Value; var prepayId = ""; var rusultCode = result.Element("xml").Element("result_code").Value; if (returnCode.ToUpper().Equals("SUCCESS") && (rusultCode.ToUpper().Equals("SUCCESS"))) { prepayId = result.Element("xml").Element("prepay_id").Value; } #endregion #region 生成支付请求 WXPayReq reqwx = new WXPayReq(); string timeStamp = ((DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000).ToString(); reqwx.appId = payConfig.WXAppId; reqwx.nonceStr = nonStr; reqwx.package = "prepay_id=" + prepayId; reqwx.signType = "MD5"; reqwx.timeStamp = timeStamp; Dictionary <string, string> dicNew = new Dictionary <string, string>(); dicNew.Add("appId", reqwx.appId); dicNew.Add("timeStamp", reqwx.timeStamp); dicNew.Add("nonceStr", reqwx.nonceStr); dicNew.Add("package", reqwx.package); dicNew.Add("signType", "MD5"); string strTemp1 = Payment.WeiXin.CommonUtil.FormatQueryParaMap(dicNew); string paySign = MD5SignUtil.Sign(strTemp1, payConfig.WXPartnerKey); reqwx.paySign = paySign; WxPayReq = ZentCloud.Common.JSONHelper.ObjectToJson(reqwx); #endregion // } catch (Exception ex) { Response.Write(ex.Message); Response.End(); } }