protected void Page_Load(object sender, System.EventArgs e) { string text = base.Request.QueryString.Get("PayId"); if (string.IsNullOrEmpty(text)) { return; } MemberAmountDetailedInfo amountDetailByPayId = MemberAmountProcessor.GetAmountDetailByPayId(text); if (amountDetailByPayId == null) { return; } decimal tradeAmount = amountDetailByPayId.TradeAmount; PackageInfo packageInfo = new PackageInfo(); packageInfo.Body = text; packageInfo.NotifyUrl = string.Format("http://{0}/pay/wx_PayCharge.aspx", base.Request.Url.Host); packageInfo.OutTradeNo = text; packageInfo.TotalFee = (int)(tradeAmount * 100m); if (packageInfo.TotalFee < 1m) { packageInfo.TotalFee = 1m; } string openId = ""; MemberInfo currentMember = MemberProcessor.GetCurrentMember(); if (currentMember != null) { openId = currentMember.OpenId; } packageInfo.OpenId = openId; SiteSettings masterSettings = SettingsManager.GetMasterSettings(true); PayClient payClient; if (masterSettings.EnableSP) { payClient = new PayClient(masterSettings.Main_AppId, masterSettings.WeixinAppSecret, masterSettings.Main_Mch_ID, masterSettings.Main_PayKey, true, masterSettings.WeixinAppId, masterSettings.WeixinPartnerID); } else { payClient = new PayClient(masterSettings.WeixinAppId, masterSettings.WeixinAppSecret, masterSettings.WeixinPartnerID, masterSettings.WeixinPartnerKey, false, "", ""); } if (!payClient.checkSetParams(out this.CheckValue)) { return; } if (!payClient.checkPackage(packageInfo, out this.CheckValue)) { return; } PayRequestInfo payRequestInfo = payClient.BuildPayRequest(packageInfo); this.pay_json = this.ConvertPayJson(payRequestInfo); if (!payRequestInfo.package.ToLower().StartsWith("prepay_id=wx")) { this.CheckValue = payRequestInfo.package; } }
/// <summary> /// 查询支付请求记录 /// </summary> /// <param name="orderId"></param> /// <param name="payType"></param> /// <returns></returns> public static PayRequestInfo GetPayRequest(int sysNo) { string sql = @"SELECT * FROM Pay_Request WHERE SysNo=@sysNo"; PayRequestInfo requestInfo = DbHelper.QuerySingle <PayRequestInfo>(sql, new { sysNo = sysNo }); return(requestInfo); }
public string ConvertPayJson(string appId, string PartnerId, PayRequestInfo req) { SiteSettings siteSettings = HiContext.Current.SiteSettings; AppVersionRecordInfo latestAppVersionRecord = APPHelper.GetLatestAppVersionRecord("android"); string text = ""; if (latestAppVersionRecord == null || latestAppVersionRecord.Version.ToDecimal_MoreDot(0) > 3.3m) { text = "{"; text = text + "\"appid\":\"" + appId + "\","; text = text + "\"noncestr\":\"" + req.nonceStr + "\","; text += "\"package\":\"Sign=WXPay\","; text = text + "\"partnerid\":\"" + PartnerId + "\","; text = text + "\"prepayid\":\"" + req.prepayid + "\","; text = text + "\"timestamp\":" + req.timeStamp + ","; text = text + "\"sign\":\"" + req.paySign + "\""; return(text + "}"); } text = "{"; text = text + "\"partnerId\":\"" + PartnerId + "\","; text = text + "\"prepayId\":\"" + req.prepayid + "\","; text = text + "\"nonceStr\":\"" + req.nonceStr + "\","; text = text + "\"timeStamp\":\"" + req.timeStamp + "\","; text = text + "\"sign\":\"" + req.paySign + "\""; return(text + "}"); }
/// <summary> /// 更新支付结果记录并关联支付请求记录 /// </summary> /// <param name="resultInfo">支付结果记录</param> /// <returns></returns> public virtual PayRequestInfo RelateRequestInfo(PayResultInfo resultInfo) { //判断是否存在有效的支付结果记录,如果存在,则当前支付结果记录不执行 bool exist = PayResultDAL.ExistValidPayResult(resultInfo.OrderId, resultInfo.TradeNo, (AppEnum.PayType)resultInfo.PayType); if (exist) { resultInfo.ExecuteResult = (int)ResultStatus.Failure; resultInfo.ResultDesc = "已存在有效的支付结果记录"; } PayRequestInfo requestInfo = null; if (resultInfo.ExecuteResult == (int)ResultStatus.Success) { requestInfo = PayRequestDAL.GetValidPayRequest(resultInfo.OrderId, (AppEnum.PayType)resultInfo.PayType); if (requestInfo != null && requestInfo.SysNo > 0) { resultInfo.RequestSysNo = requestInfo.SysNo; } } //更新支付结果记录信息 PayResultDAL.Update(resultInfo); return(requestInfo); }
public PayRequestInfo BuildPayRequest(PackageInfo package) { PayRequestInfo payRequestInfo = new PayRequestInfo(); payRequestInfo.appId = this._payAccount.AppId; payRequestInfo.package = this.BuildPackage(package); payRequestInfo.timeStamp = Utils.GetCurrentTimeSeconds().ToString(); payRequestInfo.nonceStr = Utils.CreateNoncestr(); payRequestInfo.paySign = SignHelper.SignPay(new PayDictionary { { "appId", this._payAccount.AppId }, { "timeStamp", payRequestInfo.timeStamp }, { "package", payRequestInfo.package }, { "nonceStr", payRequestInfo.nonceStr }, { "signType", "MD5" } }, this._payAccount.PartnerKey); return(payRequestInfo); }
/// <summary> /// 根据订单编号和支付方式,查询有效的支付请求记录 /// </summary> /// <param name="orderId"></param> /// <param name="payType"></param> /// <returns></returns> public static PayRequestInfo GetValidPayRequest(string orderId, AppEnum.PayType payType) { string sql = @" SELECT SysNo, OrderId, PaymentAmt, PayType, NotifyUrl, ReturnUrl, ExecuteResult, ResultDesc, AppId, Status, CreateTime FROM Pay_Request WHERE OrderId=@orderId AND PayType=@payType AND Status=@status ORDER BY SysNo"; PayRequestInfo requestInfo = DbHelper.QuerySingle <PayRequestInfo>(sql, new { orderId = orderId, payType = (int)payType, status = (int)AppEnum.GlobalStatus.Valid }); return(requestInfo); }
public string ConvertPayUri(PayRequestInfo req) { string empty = string.Empty; string format = "weixin://wap/pay?appid%3D{0}%26noncestr%3D{1}%26package%3DWAP%26prepayid%3D{2}%26timestamp%3D{3}%26sign%3D{4}"; return(string.Format(format, req.appId, req.nonceStr, req.prepayid, req.timeStamp, req.paySign)); }
public PayRequestInfo BuildPayRequest(PackageInfo package) { PayRequestInfo info = new PayRequestInfo(); info.appId = this.m_payAccount.AppId; info.timeStamp = Utils.GetCurrentTimeSeconds().ToString(); info.package = this.BuildPackage(package);//生成prepay_id info.nonceStr = Utils.CreateNoncestr(); PayDictionary parameters = new PayDictionary(); parameters.Add("appId", info.appId); parameters.Add("timeStamp", info.timeStamp); parameters.Add("package", info.package); parameters.Add("nonceStr", info.nonceStr); parameters.Add("signType", info.signType); info.paySign = SignHelper.SignPay(parameters, this.m_payAccount.PartnerKey); return(info); }
/// <summary> /// 作废重复的支付请求记录 /// </summary> /// <returns></returns> public static bool InvalidateRepeatRequest(PayRequestInfo info) { string sql = "UPDATE Pay_Request SET Status=@status WHERE OrderId=@orderId AND PayType=@payType AND SysNo<@sysNo AND NOT EXISTS (SELECT 1 FROM Pay_Result WHERE RequestSysNo=Pay_Request.SysNo)"; var param = new { status = (int)AppEnum.GlobalStatus.Invalid, orderId = info.OrderId, payType = (int)info.PayType, sysNo = info.SysNo }; int count = DbHelper.Execute(sql, param); return(count > 0); }
/// <summary> /// 支付请求执行成功 /// </summary> /// <param name="requestInfo">支付请求记录</param> public virtual void ExecuteSuccess(PayRequestInfo requestInfo) { //更新支付请求记录的执行结果 requestInfo.ExecuteResult = (int)ResultStatus.Success; requestInfo.Status = (int)AppEnum.GlobalStatus.Valid; PayRequestDAL.Update(requestInfo); //作废重复的支付请求记录 PayRequestDAL.InvalidateRepeatRequest(requestInfo); }
public string ConvertPayJson(PayRequestInfo req) { string packageValue = "{"; packageValue = packageValue + " \"appId\": \"" + req.appId + "\", "; packageValue = packageValue + " \"timeStamp\": \"" + req.timeStamp + "\", "; packageValue = packageValue + " \"nonceStr\": \"" + req.nonceStr + "\", "; packageValue = packageValue + " \"package\": \"" + req.package + "\", "; packageValue += " \"signType\": \"MD5\", "; return(packageValue + " \"paySign\": \"" + req.paySign + "\"}"); }
/// <summary> /// 插入支付请求记录 /// </summary> /// <param name="info"></param> /// <returns></returns> public static int Insert(PayRequestInfo info) { string sql = @" INSERT INTO Pay_Request (OrderId,PaymentAmt,PayType,NotifyUrl,ReturnUrl,RequestData,ExecuteResult,ResultDesc,AppId,Status,CreateTime) VALUES (@OrderId,@PaymentAmt,@PayType,@NotifyUrl,@ReturnUrl,@RequestData,@ExecuteResult,@ResultDesc,@AppId,@Status,@CreateTime); SELECT LAST_INSERT_ID();"; //SELECT LAST_INSERT_ID() , sql=SCOPE_IDENTITY info.SysNo = DbHelper.QueryScalar <int>(sql, info); return(info.SysNo); }
public string ConvertPayJson(PayRequestInfo req) { string str = "{"; str = str + "\"appId\":\"" + req.appId + "\","; str = str + "\"timeStamp\":\"" + req.timeStamp + "\","; str = str + "\"nonceStr\":\"" + req.nonceStr + "\","; str = str + "\"package\":\"" + req.package + "\","; str = str + "\"signType\":\"" + req.signType + "\","; str = str + "\"paySign\":\"" + req.paySign + "\""; return(str + "}"); }
public PayRequestInfo BuildH5PayRequest(PackageInfo package) { string prepayid = ""; PayRequestInfo payRequestInfo = new PayRequestInfo(); payRequestInfo.appId = this._payAccount.AppId; payRequestInfo.mweb_url = this.BuildH5PayUrl(package, out prepayid); payRequestInfo.prepayid = prepayid; payRequestInfo.package = ""; payRequestInfo.timeStamp = Utils.GetCurrentTimeSeconds().ToString(); payRequestInfo.nonceStr = Utils.CreateNoncestr(); return(payRequestInfo); }
/// <summary> /// 获取返回链接 /// </summary> /// <param name="requestInfo">支付请求记录</param> /// <param name="notifyInfo">支付结果通知</param> /// <returns></returns> public virtual string GetReturnUrl(PayRequestInfo requestInfo, PayNotifyInfo notifyInfo) { if (requestInfo != null && !string.IsNullOrWhiteSpace(requestInfo.ReturnUrl)) { var setting = JsonHelper.GetDefaultSettings(); setting.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore; string data = JsonHelper.Serialize(notifyInfo, setting); string sign = SignManager.CreateSign(requestInfo.AppId, data).Data; string returnUrl = requestInfo.ReturnUrl + (requestInfo.ReturnUrl.IndexOf("?") > 0 ? "&" : "?"); returnUrl += string.Format("appId={0}&sign={1}&data={2}", requestInfo.AppId, sign, data); return(returnUrl); } return(null); }
protected void Page_Load(object sender, EventArgs e) { string text = base.Request.QueryString.Get("orderId"); if (!string.IsNullOrEmpty(text)) { InpourRequestInfo inpourBlance = MemberProcessor.GetInpourBlance(text); if (inpourBlance != null) { SiteSettings masterSettings = SettingsManager.GetMasterSettings(); PackageInfo packageInfo = new PackageInfo(); packageInfo.Body = inpourBlance.InpourId; packageInfo.NotifyUrl = Globals.GetProtocal(HttpContext.Current) + "://" + $"{base.Request.Url.Host}/pay/WeiXinInpourNotify"; packageInfo.OutTradeNo = inpourBlance.InpourId; packageInfo.TotalFee = (int)(inpourBlance.InpourBlance * 100m); if (packageInfo.TotalFee < decimal.One) { packageInfo.TotalFee = decimal.One; } string text2 = ""; if (string.IsNullOrEmpty(text2)) { PayConfig payConfig = new PayConfig(); payConfig.AppId = masterSettings.WeixinAppId; payConfig.Key = masterSettings.WeixinPartnerKey; payConfig.MchID = masterSettings.WeixinPartnerID; payConfig.AppSecret = masterSettings.WeixinAppSecret; JsApiPay jsApiPay = new JsApiPay(); NameValueCollection openidAndAccessToken = JsApiPay.GetOpenidAndAccessToken(this.Page, payConfig.AppId, payConfig.AppSecret, false); if (openidAndAccessToken.HasKeys()) { text2 = openidAndAccessToken["openId"]; } } if (!string.IsNullOrEmpty(masterSettings.Main_AppId) && !string.IsNullOrEmpty(masterSettings.Main_Mch_ID)) { packageInfo.sub_openid = text2; } else { packageInfo.OpenId = text2; } packageInfo.sub_mch_id = masterSettings.WeixinPartnerID; PayClient payClient = null; payClient = ((string.IsNullOrEmpty(masterSettings.Main_AppId) || string.IsNullOrEmpty(masterSettings.Main_Mch_ID)) ? new PayClient(masterSettings.WeixinAppId, masterSettings.WeixinAppSecret, masterSettings.WeixinPartnerID, masterSettings.WeixinPartnerKey, masterSettings.WeixinPaySignKey, "", "", "") : new PayClient(masterSettings.Main_AppId, masterSettings.WeixinAppSecret, masterSettings.Main_Mch_ID, masterSettings.WeixinPartnerKey, masterSettings.WeixinPaySignKey, masterSettings.WeixinPartnerID, masterSettings.WeixinAppId, "")); PayRequestInfo req = payClient.BuildPayRequest(packageInfo); this.pay_json = this.ConvertPayJson(req); } } }
protected void Page_Load(object sender, EventArgs e) { string str = base.Request.QueryString.Get("PayId"); if (!string.IsNullOrEmpty(str)) { MemberAmountDetailedInfo amountDetailByPayId = MemberAmountProcessor.GetAmountDetailByPayId(str); if (amountDetailByPayId != null) { PayClient client; decimal tradeAmount = amountDetailByPayId.TradeAmount; PackageInfo package = new PackageInfo { Body = str, NotifyUrl = string.Format("http://{0}/pay/wx_PayCharge.aspx", base.Request.Url.Host), OutTradeNo = str, TotalFee = (int)(tradeAmount * 100M) }; if (package.TotalFee < 1M) { package.TotalFee = 1M; } string openId = ""; MemberInfo currentMember = MemberProcessor.GetCurrentMember(); if (currentMember != null) { openId = currentMember.OpenId; } package.OpenId = openId; SiteSettings masterSettings = SettingsManager.GetMasterSettings(true); if (masterSettings.EnableSP) { client = new PayClient(masterSettings.Main_AppId, masterSettings.WeixinAppSecret, masterSettings.Main_Mch_ID, masterSettings.Main_PayKey, true, masterSettings.WeixinAppId, masterSettings.WeixinPartnerID); } else { client = new PayClient(masterSettings.WeixinAppId, masterSettings.WeixinAppSecret, masterSettings.WeixinPartnerID, masterSettings.WeixinPartnerKey, false, "", ""); } if (client.checkSetParams(out this.CheckValue) && client.checkPackage(package, out this.CheckValue)) { PayRequestInfo req = client.BuildPayRequest(package); this.pay_json = this.ConvertPayJson(req); if (!req.package.ToLower().StartsWith("prepay_id=wx")) { this.CheckValue = req.package; } } } } }
/// <summary> /// 保存支付请求记录 /// </summary> /// <param name="data"></param> /// <param name="payType"></param> /// <returns></returns> public static PayRequestInfo SavePayRequest(string data, AppEnum.PayType payType) { var payRequest = new PayRequestInfo() { PayType = (int)payType, RequestData = data, ExecuteResult = (int)ResultStatus.None, Status = (int)AppEnum.GlobalStatus.Invalid, CreateTime = DateTime.Now, }; payRequest.SysNo = PayRequestDAL.Insert(payRequest); return(payRequest); }
public string ConvertPayJson(PayRequestInfo req) { //string packageValue = ""; //packageValue += " \"appId\": \"" + req.appId + "\", "; //packageValue += " \"timeStamp\": \"" + req.timeStamp + "\", "; //packageValue += " \"nonceStr\": \"" + req.nonceStr + "\", "; //packageValue += " \"package\": \"" + req.package + "\", "; //packageValue += " \"signType\": \"MD5\", "; //packageValue += " \"paySign\": \"" + req.paySign + "\""; //return packageValue; string str = "{"; return(((((((str + "\"appId\":\"" + req.appId + "\",") + "\"timeStamp\":\"" + req.timeStamp + "\",") + "\"nonceStr\":\"" + req.nonceStr + "\",") + "\"package\":\"" + req.package + "\",") + "\"signType\":\"" + req.signType + "\",") + "\"paySign\":\"" + req.paySign + "\"") + "}"); }
/// <summary> /// 保存支付请求 /// </summary> /// <param name="appId">业务系统ID</param> /// <param name="data">业务数据报文</param> /// <param name="payType">支付方式</param> /// <returns></returns> public virtual PayRequestInfo SaveRequest(string appId, string data, AppEnum.PayType payType) { var requestInfo = new PayRequestInfo() { PayType = (int)payType, RequestData = data, ExecuteResult = (int)ResultStatus.None, AppId = appId, Status = (int)AppEnum.GlobalStatus.Invalid, CreateTime = DateTime.Now, }; requestInfo.SysNo = PayRequestDAL.Insert(requestInfo); return(requestInfo); }
/// <summary> /// 获取支付请求的基本信息 /// </summary> /// <param name="payRequest"></param> /// <param name="data"></param> /// <returns></returns> public static PayRequestInfo GetPayRequestInfo(PayRequestInfo payRequest, string data) { var info = JsonHelper.Deserialize <PayOrderInfo>(data); if (info != null) { payRequest.OrderId = info.OrderId; decimal paymentAmt = 0; decimal.TryParse(info.PaymentAmt, out paymentAmt); payRequest.PaymentAmt = paymentAmt; payRequest.NotifyUrl = info.NotifyUrl; payRequest.ReturnUrl = info.ReturnUrl; int systemId = 0; int.TryParse(info.SystemId, out systemId); payRequest.RequestSystemId = systemId; } return(payRequest); }
public PayRequestInfo BuildPayRequest(PackageInfo package) { PayRequestInfo payRequestInfo = new PayRequestInfo(); payRequestInfo.appId = this._payAccount.AppId; payRequestInfo.package = this.BuildPackage(package); payRequestInfo.prepayid = payRequestInfo.package.Replace("prepay_id=", ""); payRequestInfo.timeStamp = Utils.GetCurrentTimeSeconds().ToString(); payRequestInfo.nonceStr = Utils.CreateNoncestr(); PayDictionary payDictionary = new PayDictionary(); payDictionary.Add("appId", this._payAccount.AppId); payDictionary.Add("timeStamp", payRequestInfo.timeStamp); payDictionary.Add("package", payRequestInfo.package); payDictionary.Add("nonceStr", payRequestInfo.nonceStr); payDictionary.Add("signType", "MD5"); payRequestInfo.paySign = SignHelper.SignPay(payDictionary, this._payAccount.PartnerKey); return(payRequestInfo); }
/// <summary> /// 更新支付请求记录(不更新PayType、RequestData、AppId字段) /// </summary> /// <param name="info"></param> /// <returns></returns> public static bool Update(PayRequestInfo info) { if (info == null || info.SysNo <= 0) { return(false); } string sql = @" UPDATE Pay_Request SET OrderId=@OrderId, PaymentAmt=@PaymentAmt, NotifyUrl=@NotifyUrl, ReturnUrl=@ReturnUrl, ExecuteResult=@ExecuteResult, ResultDesc=@ResultDesc, Status=@Status WHERE SysNo=@SysNo"; int count = DbHelper.Execute(sql, info); return(count > 0); }
/// <summary> /// 解析支付请求 /// </summary> /// <param name="data">业务数据报文</param> /// <param name="requestInfo">支付请求记录</param> /// <returns></returns> public virtual ExecuteResult ResolveRequest(string data, PayRequestInfo requestInfo) { var result = new ExecuteResult(); var info = JsonHelper.Deserialize <PayOrderInfo>(data); if (info != null) { requestInfo.OrderId = info.OrderId; decimal paymentAmt = 0; decimal.TryParse(info.PaymentAmt, out paymentAmt); requestInfo.PaymentAmt = paymentAmt; requestInfo.NotifyUrl = info.NotifyUrl; requestInfo.ReturnUrl = info.ReturnUrl; PayRequestDAL.Update(requestInfo); result.Status = ResultStatus.Success; } else { result.Status = ResultStatus.Failure; result.Message = "解析支付请求参数失败"; } return(result); }
protected void Page_Load(object sender, System.EventArgs e) { string text = base.Request.QueryString.Get("orderId"); if (string.IsNullOrEmpty(text)) { return; } System.Collections.Generic.List <OrderInfo> orderMarkingOrderInfo = ShoppingProcessor.GetOrderMarkingOrderInfo(text); if (orderMarkingOrderInfo.Count == 0) { return; } decimal d = 0m; foreach (OrderInfo current in orderMarkingOrderInfo) { if (current.BargainDetialId > 0) { string text2 = BargainHelper.IsCanBuyByBarginDetailId(current.BargainDetialId); if (text2 != "1") { current.OrderStatus = OrderStatus.Closed; current.CloseReason = text2; OrderHelper.UpdateOrder(current); base.Response.Write("<script>alert('" + text2 + ",订单自动关闭!');location.href='/Vshop/MemberOrders.aspx'</script>"); base.Response.End(); return; } } else { foreach (LineItemInfo current2 in current.LineItems.Values) { if (!ProductHelper.GetProductHasSku(current2.SkuId, current2.Quantity)) { current.OrderStatus = OrderStatus.Closed; current.CloseReason = "库存不足"; OrderHelper.UpdateOrder(current); base.Response.Write("<script>alert('库存不足,订单自动关闭!');location.href='/Vshop/MemberOrders.aspx'</script>"); base.Response.End(); return; } } } d += current.GetTotal(); } PackageInfo packageInfo = new PackageInfo(); packageInfo.Body = text; packageInfo.NotifyUrl = string.Format("http://{0}/pay/wx_Pay.aspx", base.Request.Url.Host); packageInfo.OutTradeNo = text; packageInfo.TotalFee = (int)(d * 100m); if (packageInfo.TotalFee < 1m) { packageInfo.TotalFee = 1m; } string openId = ""; MemberInfo currentMember = MemberProcessor.GetCurrentMember(); if (currentMember != null) { openId = currentMember.OpenId; } packageInfo.OpenId = openId; SiteSettings masterSettings = SettingsManager.GetMasterSettings(true); PayClient payClient; if (masterSettings.EnableSP) { payClient = new PayClient(masterSettings.Main_AppId, masterSettings.WeixinAppSecret, masterSettings.Main_Mch_ID, masterSettings.Main_PayKey, true, masterSettings.WeixinAppId, masterSettings.WeixinPartnerID); } else { payClient = new PayClient(masterSettings.WeixinAppId, masterSettings.WeixinAppSecret, masterSettings.WeixinPartnerID, masterSettings.WeixinPartnerKey, false, "", ""); } if (payClient.checkSetParams(out this.CheckValue)) { if (!payClient.checkPackage(packageInfo, out this.CheckValue)) { return; } PayRequestInfo payRequestInfo = payClient.BuildPayRequest(packageInfo); this.pay_json = this.ConvertPayJson(payRequestInfo); if (!payRequestInfo.package.ToLower().StartsWith("prepay_id=wx")) { this.CheckValue = payRequestInfo.package; } System.Data.DataTable shareActivity = ShareActHelper.GetShareActivity(); int num = 0; decimal d2 = 0m; if (shareActivity.Rows.Count > 0) { for (int i = 0; i < shareActivity.Rows.Count; i++) { if (d != 0m && d >= decimal.Parse(shareActivity.Rows[shareActivity.Rows.Count - 1]["MeetValue"].ToString())) { num = int.Parse(shareActivity.Rows[shareActivity.Rows.Count - 1]["Id"].ToString()); d2 = decimal.Parse(shareActivity.Rows[shareActivity.Rows.Count - 1]["MeetValue"].ToString()); break; } if (d != 0m && d <= decimal.Parse(shareActivity.Rows[0]["MeetValue"].ToString())) { num = int.Parse(shareActivity.Rows[0]["Id"].ToString()); d2 = decimal.Parse(shareActivity.Rows[0]["MeetValue"].ToString()); break; } if (d != 0m && d >= decimal.Parse(shareActivity.Rows[i]["MeetValue"].ToString())) { num = int.Parse(shareActivity.Rows[i]["Id"].ToString()); d2 = decimal.Parse(shareActivity.Rows[i]["MeetValue"].ToString()); } } if (d >= d2) { this.shareid = num; } } return; } }
protected void Page_Load(object sender, System.EventArgs e) { string text = base.Request.QueryString.Get("orderId"); if (string.IsNullOrEmpty(text)) { this.pay_json = "{\"msg\":\"订单参数错误!\"}"; return; } OneyuanTaoParticipantInfo addParticipant = OneyuanTaoHelp.GetAddParticipant(0, text, ""); if (addParticipant == null) { this.pay_json = "{\"msg\":\"订单不存在了!\"}"; return; } OneyuanTaoInfo oneyuanTaoInfoById = OneyuanTaoHelp.GetOneyuanTaoInfoById(addParticipant.ActivityId); if (oneyuanTaoInfoById == null) { this.pay_json = "{\"msg\":\"活动已取消,禁止参与!\"}"; return; } OneTaoState oneTaoState = OneyuanTaoHelp.getOneTaoState(oneyuanTaoInfoById); if (oneTaoState != OneTaoState.进行中) { this.pay_json = "{\"msg\":\"您来晚了,活动已结束!\"}"; return; } if (oneTaoState != OneTaoState.进行中) { this.pay_json = "{\"msg\":\"您来晚了,活动已结束!\"}"; return; } if (oneyuanTaoInfoById.ReachType == 1 && oneyuanTaoInfoById.FinishedNum + addParticipant.BuyNum > oneyuanTaoInfoById.ReachNum) { this.pay_json = "{\"msg\":\"活动已满员,您来晚了!\"}"; return; } decimal totalPrice = addParticipant.TotalPrice; PackageInfo packageInfo = new PackageInfo(); packageInfo.Body = "一元夺宝。当前活动编号:" + addParticipant.ActivityId; packageInfo.NotifyUrl = string.Format("http://{0}/pay/wx_Pay.aspx", base.Request.Url.Host); packageInfo.OutTradeNo = text; packageInfo.TotalFee = (int)(totalPrice * 100m); if (packageInfo.TotalFee < 1m) { packageInfo.TotalFee = 1m; } string openId = ""; MemberInfo currentMember = MemberProcessor.GetCurrentMember(); if (currentMember != null) { openId = currentMember.OpenId; } else { this.pay_json = "{\"msg\":\"用户OPENID不存在,无法支付!\"}"; } packageInfo.OpenId = openId; SiteSettings masterSettings = SettingsManager.GetMasterSettings(true); PayClient payClient; if (masterSettings.EnableSP) { payClient = new PayClient(masterSettings.Main_AppId, masterSettings.WeixinAppSecret, masterSettings.Main_Mch_ID, masterSettings.Main_PayKey, true, masterSettings.WeixinAppId, masterSettings.WeixinPartnerID); } else { payClient = new PayClient(masterSettings.WeixinAppId, masterSettings.WeixinAppSecret, masterSettings.WeixinPartnerID, masterSettings.WeixinPartnerKey, false, "", ""); } if (!payClient.checkSetParams(out this.CheckValue)) { return; } if (!payClient.checkPackage(packageInfo, out this.CheckValue)) { return; } PayRequestInfo payRequestInfo = payClient.BuildPayRequest(packageInfo); this.pay_json = this.ConvertPayJson(payRequestInfo); if (!payRequestInfo.package.ToLower().StartsWith("prepay_id=wx")) { this.CheckValue = payRequestInfo.package; } }
protected void Page_Load(object sender, EventArgs e) { string str = base.Request.QueryString.Get("orderId"); if (!string.IsNullOrEmpty(str)) { List <OrderInfo> orderMarkingOrderInfo = ShoppingProcessor.GetOrderMarkingOrderInfo(str, true); if (orderMarkingOrderInfo.Count != 0) { PayClient client; decimal num = 0M; if (orderMarkingOrderInfo[0].UserId != 0) { foreach (OrderInfo info in orderMarkingOrderInfo) { if (info.BargainDetialId > 0) { string str2 = BargainHelper.IsCanBuyByBarginDetailId(info.BargainDetialId); if (str2 != "1") { info.OrderStatus = OrderStatus.Closed; info.CloseReason = str2; OrderHelper.UpdateOrder(info); base.Response.Write("<script>alert('" + str2 + ",订单自动关闭!');location.href='/Vshop/MemberOrders.aspx'</script>"); base.Response.End(); return; } } else { foreach (LineItemInfo info2 in info.LineItems.Values) { if (!ProductHelper.GetProductHasSku(info2.SkuId, info2.Quantity)) { info.OrderStatus = OrderStatus.Closed; info.CloseReason = "库存不足"; OrderHelper.UpdateOrder(info); base.Response.Write("<script>alert('库存不足,订单自动关闭!');location.href='/Vshop/MemberOrders.aspx'</script>"); base.Response.End(); return; } } } num += info.GetCashPayMoney(); } } else { num = orderMarkingOrderInfo[0].Amount; } PackageInfo package = new PackageInfo { Body = str, NotifyUrl = string.Format("http://{0}/pay/wx_Pay.aspx", base.Request.Url.Host), OutTradeNo = str, TotalFee = (int)(num * 100M) }; if (package.TotalFee < 1M) { package.TotalFee = 1M; } string openId = ""; MemberInfo currentMember = MemberProcessor.GetCurrentMember(); if (currentMember != null) { openId = currentMember.OpenId; } package.OpenId = openId; SiteSettings masterSettings = SettingsManager.GetMasterSettings(true); if (masterSettings.EnableSP) { client = new PayClient(masterSettings.Main_AppId, masterSettings.WeixinAppSecret, masterSettings.Main_Mch_ID, masterSettings.Main_PayKey, true, masterSettings.WeixinAppId, masterSettings.WeixinPartnerID); } else { client = new PayClient(masterSettings.WeixinAppId, masterSettings.WeixinAppSecret, masterSettings.WeixinPartnerID, masterSettings.WeixinPartnerKey, false, "", ""); } if (client.checkSetParams(out this.CheckValue) && client.checkPackage(package, out this.CheckValue)) { PayRequestInfo req = client.BuildPayRequest(package); this.pay_json = this.ConvertPayJson(req); if (!req.package.ToLower().StartsWith("prepay_id=wx")) { this.CheckValue = req.package; } DataTable shareActivity = ShareActHelper.GetShareActivity(); int num2 = 0; decimal num3 = 0M; if (shareActivity.Rows.Count > 0) { for (int i = 0; i < shareActivity.Rows.Count; i++) { if ((num != 0M) && (num >= decimal.Parse(shareActivity.Rows[shareActivity.Rows.Count - 1]["MeetValue"].ToString()))) { num2 = int.Parse(shareActivity.Rows[shareActivity.Rows.Count - 1]["Id"].ToString()); num3 = decimal.Parse(shareActivity.Rows[shareActivity.Rows.Count - 1]["MeetValue"].ToString()); break; } if ((num != 0M) && (num <= decimal.Parse(shareActivity.Rows[0]["MeetValue"].ToString()))) { num2 = int.Parse(shareActivity.Rows[0]["Id"].ToString()); num3 = decimal.Parse(shareActivity.Rows[0]["MeetValue"].ToString()); break; } if ((num != 0M) && (num >= decimal.Parse(shareActivity.Rows[i]["MeetValue"].ToString()))) { num2 = int.Parse(shareActivity.Rows[i]["Id"].ToString()); num3 = decimal.Parse(shareActivity.Rows[i]["MeetValue"].ToString()); } } if (num >= num3) { this.shareid = num2; } } } } } }
protected void Page_Load(object sender, System.EventArgs e) { string text = base.Request.QueryString.Get("orderId"); if (string.IsNullOrEmpty(text)) { return; } OrderInfo orderInfo = OrderHelper.GetOrderInfo(text); OrderHelper.SetOrderPayStatus(orderInfo.OrderId, 1); if (orderInfo == null) { return; } PackageInfo packageInfo = new PackageInfo(); packageInfo.Body = orderInfo.OrderId; packageInfo.NotifyUrl = string.Format("http://{0}/pay/wx_Pay.aspx", base.Request.Url.Host); packageInfo.OutTradeNo = orderInfo.OrderId; packageInfo.TotalFee = (int)(orderInfo.GetTotal() * 100m); if (packageInfo.TotalFee < 1m) { packageInfo.TotalFee = 1m; } string openId = ""; SiteSettings masterSettings = SettingsManager.GetMasterSettings(false); if (HiContext.Current.User != null) { openId = HiContext.Current.User.OpenId; } //openId = "oUBLTvixVJV6q0FtN7kpKW7f9Ur8"; if (string.IsNullOrEmpty(openId)) { string code = Request.QueryString["code"]; if (string.IsNullOrEmpty(code)) { string text2 = string.Format( "https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri={1}&response_type=code&scope=snsapi_base&state=123#wechat_redirect", masterSettings.WeixinAppId, Globals.UrlEncode(Request.Url.ToString())); this.Page.Response.Redirect(text2); } else { Ecdev.Weixin.MP.Domain.Token token = Ecdev.Weixin.MP.Api.TokenApi.GetToken(masterSettings.WeixinAppId, masterSettings.WeixinAppSecret, code, "authorization_code"); openId = token.openid; } } if (string.IsNullOrEmpty(openId)) { Response.Write("<script>alert('无法获取登录信息,建议退出并重新登录或注册新帐号。');location.href = '/Vshop/logout.aspx';</script>"); Response.End(); } packageInfo.OpenId = openId; PayClient payClient = new PayClient(masterSettings.WeixinAppId, masterSettings.WeixinAppSecret, masterSettings.WeixinPartnerID, masterSettings.WeixinPartnerKey, masterSettings.WeixinPaySignKey); PayRequestInfo req = null; int loop = 0; do { req = payClient.BuildPayRequest(packageInfo); if (!req.package.Equals("prepay_id=FAIL")) { break; } loop++; System.Threading.Thread.Sleep(500); } while (loop < 5); this.pay_json = this.ConvertPayJson(req); ErrorLog.Write("开始请求支付:" + this.pay_json); }
/// <summary> /// 通知业务系统支付结果 /// </summary> /// <param name="resultInfo">支付结果记录</param> /// <param name="requestInfo">支付请求记录</param> /// <returns></returns> public virtual ExecuteResult NotifyBack(PayResultInfo resultInfo, PayRequestInfo requestInfo) { var result = new ExecuteResult() { Status = ResultStatus.Failure }; //支付结果记录对象无效,则不执行 if (resultInfo == null || resultInfo.SysNo <= 0) { result.Message = "支付结果记录对象无效"; return(result); } //支付请求记录对象无效,则不执行 if (requestInfo == null || requestInfo.SysNo <= 0) { result.Message = "支付请求记录对象无效"; return(result); } //支付结果记录与支付请求记录不对应,则不执行 if (requestInfo.SysNo != resultInfo.RequestSysNo) { result.Message = "支付结果记录与支付请求记录不对应"; return(result); } //支付结果记录未成功执行,或者已通知,则不执行 if (resultInfo.ExecuteResult != (int)ResultStatus.Success || resultInfo.NotifyStatus == (int)AppEnum.NotifyStatus.Finished) { result.Message = "支付结果记录未成功执行或已通知成功"; return(result); } //支付请求记录中不存在有效的通知地址,则不执行 if (!requestInfo.NotifyUrl.IsUrl()) { result.Message = "支付请求记录中不存在有效的通知地址"; return(result); } var notifyInfo = this.GetPayNotifyInfo(resultInfo); var setting = JsonHelper.GetDefaultSettings(); setting.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore; string data = JsonHelper.Serialize(notifyInfo, setting); string sign = SignManager.CreateSign(requestInfo.AppId, data).Data; string param = string.Format("appId={0}&sign={1}&data={2}", requestInfo.AppId, sign, data); var response = HttpHelper.HttpRequest("POST", requestInfo.NotifyUrl, param, 10000); string status = JsonHelper.GetJsonNode(response, "status"); string msg = JsonHelper.GetJsonNode(response, "msg"); result.Message = msg; var backInfo = new NotifyBackInfo() { ResultSysNo = resultInfo.SysNo, Status = (int)AppEnum.GlobalStatus.Invalid, Msg = msg, CreateTime = DateTime.Now, ResponseData = response, }; if (status == "1") { backInfo.Status = (int)AppEnum.GlobalStatus.Valid; resultInfo.NotifyStatus = (int)AppEnum.NotifyStatus.Finished; PayResultDAL.Update(resultInfo); result.Status = ResultStatus.Success; } PayResultDAL.InsertNotifyBack(backInfo); return(result); }
protected void Page_Load(object sender, EventArgs e) { string str = base.Request.QueryString.Get("orderId"); if (string.IsNullOrEmpty(str)) { this.pay_json = "{\"msg\":\"订单参数错误!\"}"; } else { OneyuanTaoParticipantInfo info = OneyuanTaoHelp.GetAddParticipant(0, str, ""); if (info == null) { this.pay_json = "{\"msg\":\"订单不存在了!\"}"; } else { OneyuanTaoInfo oneyuanTaoInfoById = OneyuanTaoHelp.GetOneyuanTaoInfoById(info.ActivityId); if (oneyuanTaoInfoById == null) { this.pay_json = "{\"msg\":\"活动已取消,禁止参与!\"}"; } else { OneTaoState state = OneyuanTaoHelp.getOneTaoState(oneyuanTaoInfoById); if (state != OneTaoState.进行中) { this.pay_json = "{\"msg\":\"您来晚了,活动已结束!\"}"; } else if (state != OneTaoState.进行中) { this.pay_json = "{\"msg\":\"您来晚了,活动已结束!\"}"; } else if ((oneyuanTaoInfoById.ReachType == 1) && ((oneyuanTaoInfoById.FinishedNum + info.BuyNum) > oneyuanTaoInfoById.ReachNum)) { this.pay_json = "{\"msg\":\"活动已满员,您来晚了!\"}"; } else { PayClient client; decimal totalPrice = info.TotalPrice; PackageInfo package = new PackageInfo { Body = Globals.SubStr(oneyuanTaoInfoById.ProductTitle, 0x24, "...") + "。活动编号:" + info.ActivityId, NotifyUrl = string.Format("http://{0}/pay/wx_Pay.aspx", base.Request.Url.Host), OutTradeNo = str, TotalFee = (int)(totalPrice * 100M) }; if (package.TotalFee < 1M) { package.TotalFee = 1M; } string openId = ""; MemberInfo currentMember = MemberProcessor.GetCurrentMember(); if (currentMember != null) { openId = currentMember.OpenId; } else { this.pay_json = "{\"msg\":\"用户OPENID不存在,无法支付!\"}"; } package.OpenId = openId; SiteSettings masterSettings = SettingsManager.GetMasterSettings(true); if (masterSettings.EnableSP) { client = new PayClient(masterSettings.Main_AppId, masterSettings.WeixinAppSecret, masterSettings.Main_Mch_ID, masterSettings.Main_PayKey, true, masterSettings.WeixinAppId, masterSettings.WeixinPartnerID); } else { client = new PayClient(masterSettings.WeixinAppId, masterSettings.WeixinAppSecret, masterSettings.WeixinPartnerID, masterSettings.WeixinPartnerKey, false, "", ""); } if (client.checkSetParams(out this.CheckValue) && client.checkPackage(package, out this.CheckValue)) { PayRequestInfo req = client.BuildPayRequest(package); this.pay_json = this.ConvertPayJson(req); if (!req.package.ToLower().StartsWith("prepay_id=wx")) { this.CheckValue = req.package; } } } } } } }