public ActionResult AddUserInfo(tb_userinfo model) { try { if (db.tb_userinfos.Any(s => s.UserID == model.UserID)) { return(Json(Comm.ToJsonResult("Error", "用户已存在"), JsonRequestBehavior.AllowGet)); } else { model.Balance = 0; model.FirstCharge = Enums.Enums.YesOrNo.No; model.RewardMoney = 0; model.Integral = 0; model.UserGrade = UserGrade.Primary; model.ParentID = 0; model.Siteid = AliPayConfig.MediaID; model.Memberid = AliPayConfig.Memberid; model.ThisMonthSettlementMoney = 0; model.ThisMonthEstimateIncome = 0; model.LastMonthEstimateIncome = 0; model.LastMonthSettlementMoney = 0; model.AliAccount = string.Empty; model.AliUserName = string.Empty; db.tb_userinfos.Add(model); int row = db.SaveChanges(); if (row > 0) { string tempazoneid = ""; tb_TKInfo tk = db.tb_TKInfo.FirstOrDefault(s => s.PIDState == YesOrNo.No); if (tk != null) { tempazoneid = tk.Adzoneid; } tk.PIDState = YesOrNo.Yes; tk.UID = model.ID; string uscode = Comm.GetCreateUserCode(model.Phone, model.ID); var usmodel = db.tb_userinfos.Find(model.ID); usmodel.UserCode = uscode; usmodel.Adzoneid = tempazoneid; usmodel.PID = "mm_" + AliPayConfig.Memberid + "_" + AliPayConfig.MediaID + "_" + tempazoneid; db.SaveChanges(); } return(Json(Comm.ToJsonResult("Success", "成功"), JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { return(Json(Comm.ToJsonResult("Error", ex.Message), JsonRequestBehavior.AllowGet)); } }
public ActionResult UpdatePwd(string phone, string newpwd) { try { tb_userinfo model = db.tb_userinfos.FirstOrDefault(s => s.Phone == phone); if (model != null) { model.UsPwd = Unite.ToMD5New(newpwd); db.SaveChanges(); return(Json(Comm.ToJsonResult("Success", "成功"), JsonRequestBehavior.AllowGet)); } else { return(Json(Comm.ToJsonResult("notfind", "用户不存在"), JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { return(Json(Comm.ToJsonResult("Error", ex.Message), JsonRequestBehavior.AllowGet)); } }
public ActionResult UpdateInfo(string fields, string values, string usid) { try { tb_userinfo model = db.tb_userinfos.FirstOrDefault(s => s.UserID == usid); if (model != null) { //修改用户名 if (fields.Equals("1")) { model.UserName = values; } //性别 else if (fields.Equals("2")) { model.sex = values; } //生日 else if (fields.Equals("3")) { model.birthday = values; } //居住地 else if (fields.Equals("4")) { model.residence = values; } //家乡 else if (fields.Equals("5")) { model.hometown = values; } //签名 else if (fields.Equals("6")) { model.signature = values; } //签名 else if (fields.Equals("7")) { string temppath = "/Upload/"; string st = DateTime.Now.ToString("yyyyMMddHHmmss"); string filename = temppath + st.Trim() + ".jpg"; string ststr = Comm.GenerateQRCode(model.UserID, filename, model.UserImage); QinQiuApi qiniu = new QinQiuApi(); string qiniupath = qiniu.UploadFile(ststr, true); model.UserPath = qiniupath; } var returndata = new { uspath = model.UserPath }; db.SaveChanges(); return(Json(Comm.ToJsonResult("Success", "成功", returndata), JsonRequestBehavior.AllowGet)); } else { return(Json(Comm.ToJsonResult("notfind", "用户不存在"), JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { return(Json(Comm.ToJsonResult("Error", ex.Message), JsonRequestBehavior.AllowGet)); } }
public ActionResult Register(tb_userinfo model, int usertype) { try { var user = db.tb_userinfos.FirstOrDefault(s => s.Phone == model.Phone); var wxusermodel = db.tb_userinfos.FirstOrDefault(s => s.WXOpenid == model.WXOpenid && s.Phone == model.Phone); var tbusermodel = db.tb_userinfos.FirstOrDefault(s => s.OpenID == model.OpenID && s.Phone == model.Phone); if (wxusermodel != null && tbusermodel != null) { return(Json(Comm.ToJsonResult("Exist", "手机号已被注册"), JsonRequestBehavior.AllowGet)); } else if (user != null) { //微信用户 if (usertype == 0 && string.IsNullOrWhiteSpace(user.WXOpenid)) { user.WXOpenid = model.WXOpenid; user.UserImage = model.UserImage; user.UserName = model.UserName; db.SaveChanges(); var returnstr = new { usid = user.UserID }; return(Json(Comm.ToJsonResult("Success", "成功", returnstr), JsonRequestBehavior.AllowGet)); } //淘宝用户 else if (usertype == 1 && string.IsNullOrWhiteSpace(user.OpenID)) { user.OpenID = model.OpenID; user.UserImage = model.UserImage; user.UserName = model.UserName; db.SaveChanges(); var returnstr = new { usid = user.UserID }; return(Json(Comm.ToJsonResult("Success", "成功", returnstr), JsonRequestBehavior.AllowGet)); } else { return(Json(Comm.ToJsonResult("Exist", "手机号已被注册"), JsonRequestBehavior.AllowGet)); } } else { string guidstr = Guid.NewGuid().ToString(); model.Balance = 0; model.FirstCharge = Enums.Enums.YesOrNo.No; model.RewardMoney = 0; model.Integral = 0; model.UserGrade = UserGrade.Primary; model.ParentID = 0; model.Siteid = "283700162"; // AliPayConfig.MediaID; model.Memberid = "26337984"; // AliPayConfig.Memberid; model.ThisMonthSettlementMoney = 0; model.ThisMonthEstimateIncome = 0; model.LastMonthEstimateIncome = 0; model.LastMonthSettlementMoney = 0; model.AliAccount = string.Empty; model.AliUserName = string.Empty; model.UsPwd = "";// Unite.ToMD5New(model.UsPwd); model.UserID = guidstr; model.createtime = DateTime.Now.ToString(); db.tb_userinfos.Add(model); int row = db.SaveChanges(); if (row > 0) { string temppath = "/Upload/"; string st = DateTime.Now.ToString("yyyyMMddHHmmss"); string filename = temppath + st.Trim() + ".jpg"; string ststr = Comm.GenerateQRCode(guidstr, filename, ""); QinQiuApi qiniu = new QinQiuApi(); string qiniupath = qiniu.UploadFile(ststr, true); //string tempazoneid = ""; //tb_TKInfo tk = db.tb_TKInfo.FirstOrDefault(s => s.PIDState == YesOrNo.No); //if (tk != null) //{ // tempazoneid = tk.Adzoneid; //} //tk.PIDState = YesOrNo.Yes; //tk.UID = model.ID; string uscode = Comm.GetCreateUserCode(model.Phone, model.ID); var usmodel = db.tb_userinfos.Find(model.ID); usmodel.UserCode = uscode; usmodel.Adzoneid = "106412550454"; //tempazoneid; usmodel.UserPath = qiniupath; usmodel.PID = "mm_26337984_283700162_106412550454"; // "mm_" + AliPayConfig.Memberid + "_" + AliPayConfig.MediaID + "_" + tempazoneid; db.SaveChanges(); } var returnstr = new { usid = guidstr }; return(Json(Comm.ToJsonResult("Success", "成功", returnstr), JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { return(Json(Comm.ToJsonResult("Error", ex.Message), JsonRequestBehavior.AllowGet)); } }
/// <summary> /// 接收返回的结果,根据结果处理订单状态 /// </summary> public override void ProcessNotify() { WxPayData notifyData = GetNotifyData(); //检查支付结果中transaction_id是否存在 if (!notifyData.IsSet("transaction_id")) { Log.Debug("notifyData", $"notifyData:完成"); //若transaction_id不存在,则立即返回结果给微信支付后台 WxPayData res = new WxPayData(); res.SetValue("return_code", "FAIL"); res.SetValue("return_msg", "支付结果中微信订单号不存在"); Log.Error(this.GetType().ToString(), "The Pay result is error : " + res.ToXml()); page.Response.Write(res.ToXml()); page.Response.End(); } string transaction_id = notifyData.GetValue("transaction_id").ToString(); string out_trade_no = notifyData.GetValue("out_trade_no").ToString(); //查询订单,判断订单真实性 if (!QueryOrder(transaction_id)) { //若订单查询失败,则立即返回结果给微信支付后台 WxPayData res = new WxPayData(); res.SetValue("return_code", "FAIL"); res.SetValue("return_msg", "订单查询失败"); Log.Error(this.GetType().ToString(), "Order query failure : " + res.ToXml()); page.Response.Write(res.ToXml()); page.Response.End(); } //查询订单成功 else { int row = 0; #region 更改订单状态,保存支付结果 if (!string.IsNullOrEmpty(out_trade_no)) { using (ApplicationDbContext db = new ApplicationDbContext()) { PayOrder order = db.PayOrders.FirstOrDefault(p => p.out_trade_no == out_trade_no && p.OrderState == Enums.Enums.OrderState.UnHandle); if (order != null) { order.cash_fee = Convert.ToDecimal(notifyData.GetValue("total_fee").ToString()) / 100m; order.transaction_id = transaction_id; order.PayResult = notifyData.ToJson(); order.OrderState = notifyData.GetValue("result_code").ToString() == "SUCCESS" ? Enums.Enums.OrderState.Success : Enums.Enums.OrderState.Failed; order.PayTime = DateTime.Now.ToString(); row = db.SaveChanges(); if (row > 0 && order.OrderState == Enums.Enums.OrderState.Success && order.OrderType == Enums.Enums.OrderType.Recharge) { //进行充值数据保存 tb_userinfo user = db.tb_userinfos.FirstOrDefault(s => s.UserID == order.User_ID); var tempisfirstcharge = user.FirstCharge; var tempbalance = user.Balance; var addmodel = new tb_Recharge { CreateDateTime = DateTime.Now, give = 0, paytype = Enums.Enums.PayType.wx, R_Money = order.cash_fee, U_ID = user.ID, RechargeType = ((Enums.Enums.RechargeType)order.cash_fee), UserID = user.UserID, PayOrderID = order.ID }; user.Balance = tempbalance + order.cash_fee; db.tb_Recharges.Add(addmodel); db.SaveChanges(); } } } } #endregion if (row > 0) { WxPayData res = new WxPayData(); res.SetValue("return_code", "SUCCESS"); res.SetValue("return_msg", "OK"); Log.Info(this.GetType().ToString(), "order query success : " + res.ToXml()); page.Response.Write(res.ToXml()); page.Response.End(); } else {//如果没更新成功,就继续接收通知 WxPayData res = new WxPayData(); res.SetValue("return_code", "FAIL"); res.SetValue("return_msg", "未接收成功"); Log.Error(this.GetType().ToString(), "The recieve result is error : " + res.ToXml()); page.Response.Write(res.ToXml()); page.Response.End(); } } }
protected void Page_Load(object sender, EventArgs e) { //try //{ //Log.WriteLog("支付宝回调", "支付宝回调", "sdf"); string charset = "utf-8"; IDictionary <string, string> sArray = new Dictionary <string, string>(); NameValueCollection coll; //Load Form variables into NameValueCollection variable. coll = Request.Form; String[] requestItem = coll.AllKeys; for (int i = 0; i < requestItem.Length; i++) { sArray.Add(requestItem[i], Request.Form[requestItem[i]]); } string out_trade_no = Request.Form["out_trade_no"]; //订单号 string strPrice = Request.Form["receipt_amount"]; //金额 receipt_amount string trade_status = Request.Form["trade_status"]; //交易状态 string gmt_payment = Request.Form["gmt_payment"]; //交易付款时间 //验证 bool flag = AlipaySignature.RSACheckV1(sArray, AliPayConfig.alipaypublickey, charset, "RSA2", false); //验证成功 if (flag && (trade_status.Equals("TRADE_FINISHED") || trade_status.Equals("TRADE_SUCCESS"))) { using (ApplicationDbContext db = new ApplicationDbContext()) { PayOrder order = db.PayOrders.FirstOrDefault(p => p.out_trade_no == out_trade_no && p.OrderState == Enums.Enums.OrderState.UnHandle); if (order != null) { order.cash_fee = Decimal.Parse(strPrice); order.transaction_id = string.Empty; order.PayResult = string.Empty; order.OrderState = trade_status == "TRADE_FINISHED" ? Enums.Enums.OrderState.Success : trade_status == "TRADE_SUCCESS" ? Enums.Enums.OrderState.Success : Enums.Enums.OrderState.Failed; order.PayTime = gmt_payment; int row = db.SaveChanges(); if (row > 0 && order.OrderState == Enums.Enums.OrderState.Success && order.OrderType == Enums.Enums.OrderType.Recharge) { //进行充值数据保存 tb_userinfo user = db.tb_userinfos.FirstOrDefault(s => s.UserID == order.User_ID); var tempisfirstcharge = user.FirstCharge; var tempbalance = user.Balance; var addmodel = new tb_Recharge { CreateDateTime = DateTime.Now, give = 0, paytype = Enums.Enums.PayType.ali, R_Money = order.cash_fee, U_ID = user.ID, RechargeType = ((Enums.Enums.RechargeType)order.cash_fee), UserID = user.UserID, PayOrderID = order.ID }; user.Balance = tempbalance + order.cash_fee; db.tb_Recharges.Add(addmodel); db.SaveChanges(); Response.Write("success"); Response.End(); } } } } else { Response.Write("fail"); Response.End(); } //} //catch (Exception ex) //{ // Log.WriteLog("支付宝支付回调错误", "支付宝回调", ex.Message); //} }