public ActionResult ResetPassword(int?id) { JsonModel jm = new JsonModel(); //参数校验 if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } IPlatformUserBLL platformUserBll = BLLFactory <IPlatformUserBLL> .GetBLL("PlatformUserBLL"); // 根据指定id值获取实体对象 var userInfo = platformUserBll.GetEntity(index => index.Id == id && index.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (userInfo != null) { Random r = new Random(); int radVal = r.Next(100, 1000); userInfo.Password = PropertyUtils.GetMD5Str(userInfo.UserName + radVal); // 恢复初始密码值 platformUserBll.Update(userInfo); // 给用户发送邮件 PropertyUtils.SendEmail(userInfo.Email, userInfo.UserName, "物业生活管理系统 用户密码重置", "您的用户密码已重置为" + userInfo.UserName + radVal + ", 请及时修改密码!"); //操作日志 jm.Content = "平台用户" + userInfo.TrueName + "密码一键重置成功"; } else { jm.Msg = "该用户不存在"; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public ActionResult EditUserPwd(AccountPasswordChangeModel model) { JsonModel jm = new JsonModel(); //如果表单模型验证成功 if (ModelState.IsValid) { //获取要修改密码的用户 ICompanyUserBLL companyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); T_CompanyUser companyUser = companyUserBll.GetEntity(m => m.Id == model.UserId && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (companyUser != null) { companyUser.Password = PropertyUtils.GetMD5Str(model.Password); // 保存到数据库 companyUserBll.Update(companyUser); //日志记录 jm.Content = PropertyUtils.ModelToJsonString(model); } else { jm.Msg = "该用户不存在"; } } else { // 保存异常日志 jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public JsonResult ResetPassword(int id) { JsonModel jm = new JsonModel(); IShopUserBLL shopUserBll = BLLFactory <IShopUserBLL> .GetBLL("ShopUserBLL"); // 根据指定id值获取实体对象 var shopUser = shopUserBll.GetEntity(index => index.Id == id && index.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (shopUser != null) { Random r = new Random(); int radVal = r.Next(100, 1000); shopUser.Password = PropertyUtils.GetMD5Str(shopUser.UserName + radVal); //重置密码 shopUserBll.Update(shopUser); //给门店用户发送邮件 PropertyUtils.SendEmail(shopUser.Email, shopUser.UserName, "物业生活管理系统 用户密码重置", "您的用户密码已重置为" + shopUser.UserName + radVal + ", 请及时修改密码!"); //操作日志 jm.Content = "门店用户" + shopUser.TrueName + "密码一键重置成功"; } else { jm.Msg = "该门店用户不存在"; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public JsonResult AddShopUser(ShopUserModel Model) { JsonModel jm = new JsonModel(); //如果表单验证成功 if (ModelState.IsValid) { IShopUserBLL shopUserBll = BLLFactory <IShopUserBLL> .GetBLL("ShopUserBLL"); T_ShopUser shopUser = new T_ShopUser() { UserName = Model.UserName, TrueName = Model.TrueName, Phone = Model.Phone, Gender = Model.Gender, Email = Model.Email, Password = PropertyUtils.GetMD5Str(Model.Password), Memo = Model.Memo }; //保存到数据库 shopUserBll.Save(shopUser); //日志记录 jm.Content = PropertyUtils.ModelToJsonString(Model); } else { //保存异常日志 jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public ActionResult UserResetPassword(UserPassResetModel model) { //判断提交模型数据是否正确 if (!ModelState.IsValid) { return(View(model)); } IUserBLL userBll = BLLFactory <IUserBLL> .GetBLL("UserBLL"); var user = userBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (user != null) { //如果重置密码激活码存在且未失效 if (!string.IsNullOrEmpty(user.Activecode) && model.Activecode == user.Activecode && user.ActivecodeInvalidTime != null && DateTime.Now < user.ActivecodeInvalidTime.Value) { user.Password = PropertyUtils.GetMD5Str(model.Password); //密码重置链接失效 user.Activecode = ""; user.ActivecodeInvalidTime = null; //如果修改成功 if (userBll.Update(user)) { return(RedirectToAction("ResetSuccess")); } } } return(RedirectToAction("Error500")); }
public ActionResult EditPlatUserPwd(AccountPasswordChangeModel model) { JsonModel jm = new JsonModel(); //如果表单模型验证成功 if (ModelState.IsValid) { UserSessionModel sessionModel = (UserSessionModel)Session[ConstantParam.SESSION_USERINFO]; var id = sessionModel.UserID; // 若当前登录用户为平台用户 IPlatformUserBLL platformUserBll = BLLFactory <IPlatformUserBLL> .GetBLL("PlatformUserBLL"); T_PlatformUser platformUser = platformUserBll.GetEntity(m => m.Id == model.UserId && m.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (platformUser != null) { platformUser.Password = PropertyUtils.GetMD5Str(model.Password); // 保存到数据库 platformUserBll.Update(platformUser); //日志记录 jm.Content = PropertyUtils.ModelToJsonString(model); } else { jm.Msg = "该用户不存在"; } } else { // 保存异常日志 jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public ActionResult ResetPassword(int id) { JsonModel jm = new JsonModel(); IUserBLL userBll = BLLFactory <IUserBLL> .GetBLL("UserBLL"); // 根据指定id值获取实体对象 var user = userBll.GetEntity(u => u.Id == id && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (user != null) { Random r = new Random(); string newPassword = user.UserName + r.Next(100, 1000); user.Password = PropertyUtils.GetMD5Str(newPassword); // 恢复初始密码值 userBll.Update(user); // 给用户发送邮件 PropertyUtils.SendEmail(user.Email, user.UserName, "物业生活管理平台 APP用户密码重置", "您的用户密码已重置为:" + newPassword + ",请及时修改密码!"); //操作日志 jm.Content = "APP注册用户" + user.UserName + " 密码一键重置"; } else { jm.Msg = "该用户不存在"; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public ActionResult AddUser(PlatformUserModel model) { JsonModel jm = new JsonModel(); //如果表单模型验证成功 if (ModelState.IsValid) { IPlatformUserBLL platformUserBll = BLLFactory <IPlatformUserBLL> .GetBLL("PlatformUserBLL"); T_PlatformUser platformUser = new T_PlatformUser() { UserName = model.UserName, TrueName = model.TrueName, Password = PropertyUtils.GetMD5Str(model.Password), Memo = model.Memo, Tel = model.Tel, Phone = model.Phone, Email = model.Email }; // 保存到数据库 platformUserBll.Save(platformUser); //日志记录 jm.Content = PropertyUtils.ModelToJsonString(model); } else { // 保存异常日志 jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public ActionResult CompanyPlatformLogin(AccountModel model) { //判断提交模型数据是否正确 if (!ModelState.IsValid) { return(View(model)); } string code = (string)Session["ValidateCode"]; if (model.CheckCode != code) { ModelState.AddModelError("CheckCode", "验证码不正确"); return(View(model)); } //根据用户名查找用户 ICompanyUserBLL companyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); T_CompanyUser user = companyUserBll.GetEntity(u => u.UserName == model.UserName.Trim() && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); //1.判断用户名是否正确 if (user == null) { ModelState.AddModelError("UserName", "用户名不存在"); return(View(model)); } //2.判断密码是否正确 string md5Str = PropertyUtils.GetMD5Str(model.Password); if (user.Password != md5Str) { ModelState.AddModelError("Password", "密码不正确"); return(View(model)); } //3.如果未设置角色 if (user.CompanyUserRoles.Count == 0) { ModelState.AddModelError("UserName", "该用户未设置角色,请联系管理员"); return(View(model)); } //4.获取用户对象信息(权限菜单,Action等)保存基本信息到session中 this.SetUserSessiong(user, companyUserBll); //5.判断是否拥有访问首页的权限 UserSessionModel session = (UserSessionModel)Session[ConstantParam.SESSION_USERINFO]; if (session.IsMgr == ConstantParam.USER_ROLE_DEFAULT && !session.ActionDic.ContainsKey("/CompanyPlatform/Index")) { ModelState.AddModelError("UserName", "该用户无访问权限,请联系管理员"); return(View(model)); } BreadCrumb.ClearState(); //5.跳转到 return(RedirectToAction("Index", "CompanyPlatform")); }
public ApiResultModel ChangePassword(OwnerChangePasswordModel model) { ApiResultModel resultModel = new ApiResultModel(); try { //获取要修改密码的物业用户 IPropertyUserBLL userBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); T_PropertyUser user = userBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); if (user != null) { //如果验证Token不通过或已过期 if (DateTime.Now > user.TokenInvalidTime || model.Token != user.Token) { resultModel.Msg = APIMessage.TOKEN_INVALID; return(resultModel); } //更新最近登录时间和Token失效时间 user.LatelyLoginTime = DateTime.Now; user.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid"))); userBll.Update(user); string OldMd5Pwd = PropertyUtils.GetMD5Str(model.OldPwd); //如果输入的旧密码与数据库中不一致 if (OldMd5Pwd != user.Password) { resultModel.Msg = APIMessage.OLD_PWD_ERROR; } else { //修改密码并保存 user.Password = PropertyUtils.GetMD5Str(model.NewPwd); userBll.Update(user); } } else { resultModel.Msg = APIMessage.NO_USER; } } catch { resultModel.Msg = APIMessage.REQUEST_EXCEPTION; } return(resultModel); }
public JsonResult PasswordMgr(PasswordModel model) { JsonModel jm = new JsonModel(); if (ModelState.IsValid) { var owner = GetCurrentUser(); if (owner != null) { IUserBLL ownerBll = BLLFactory <IUserBLL> .GetBLL("UserBLL"); if (!string.IsNullOrEmpty(owner.Password)) { string md5Str = PropertyUtils.GetMD5Str(model.BeforePassword); if (md5Str != owner.Password) { jm.Msg = "原密码不正确"; } else { string Md5str = PropertyUtils.GetMD5Str(model.NewPassword); owner.Password = Md5str; ownerBll.Update(owner); } } else { string md5str = PropertyUtils.GetMD5Str(model.sPassword); owner.Password = md5str; ownerBll.Update(owner); } } else { jm.Msg = "该用户不存在"; } return(Json(jm, JsonRequestBehavior.AllowGet)); } else { //jm.Msg = "请重新输入"; jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR;; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public ActionResult ShopPlatformLogin(AccountModel model) { //判断提交模型数据是否正确 if (!ModelState.IsValid) { return(View(model)); } string code = (string)Session["ValidateCode"]; if (model.CheckCode != code) { ModelState.AddModelError("CheckCode", "验证码不正确"); return(View(model)); } //根据用户名查找门店平台用户 IShopUserBLL shopUserBll = BLLFactory <IShopUserBLL> .GetBLL("ShopUserBLL"); T_ShopUser user = shopUserBll.GetEntity(u => u.UserName == model.UserName.Trim() && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); //1.判断用户名是否正确 if (user == null) { ModelState.AddModelError("UserName", "用户名不存在"); return(View(model)); } //2.判断密码是否正确 string md5Str = PropertyUtils.GetMD5Str(model.Password); if (user.Password != md5Str) { ModelState.AddModelError("Password", "密码不正确"); return(View(model)); } //3.保存基本信息到session中 this.SetUserSessiong(user, shopUserBll); BreadCrumb.ClearState(); //4.跳转到 return(RedirectToAction("Index", "ShopPlatform")); }
public JsonResult SetCompanyAdministrator(CompanyUserModel model) { JsonModel jm = new JsonModel(); //如果表单模型验证成功 if (ModelState.IsValid) { ICompanyUserBLL propertyUserBll = BLLFactory <ICompanyUserBLL> .GetBLL("CompanyUserBLL"); T_CompanyUser companyUser = new T_CompanyUser() { CompanyId = model.CompanyId, UserName = model.UserName, Email = model.Email, Password = PropertyUtils.GetMD5Str(model.Password), IsMgr = ConstantParam.USER_ROLE_MGR, DelFlag = ConstantParam.DEL_FLAG_DEFAULT, }; //为管理员添加角色 ICompanyRoleBLL roleBll = BLLFactory <ICompanyRoleBLL> .GetBLL("CompanyRoleBLL"); var role = roleBll.GetEntity(r => r.IsSystem == ConstantParam.USER_ROLE_MGR && r.CompanyId == model.CompanyId); if (role != null) { companyUser.CompanyUserRoles.Add(new R_CompanyUserRole() { RoleId = role.Id, }); } //创建管理员 propertyUserBll.Save(companyUser); //日志记录 jm.Content = PropertyUtils.ModelToJsonString(model); } else { jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(Json(jm, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 设置管理员提交 /// </summary> /// <param name="model"></param> /// <returns></returns> public JsonModel SetAdmin(PropertyUserModel model) { JsonModel jm = new JsonModel(); //如果表单模型验证成功 if (ModelState.IsValid) { IPropertyUserBLL propertyUserBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); T_PropertyUser propertyUser = new T_PropertyUser() { PropertyPlaceId = model.PlaceId, UserName = model.UserName, Email = model.Email, Password = PropertyUtils.GetMD5Str(model.Password), IsMgr = ConstantParam.USER_ROLE_MGR, DelFlag = ConstantParam.DEL_FLAG_DEFAULT, }; //为管理员添加角色 IPropertyRoleBLL roleBll = BLLFactory <IPropertyRoleBLL> .GetBLL("PropertyRoleBLL"); var role = roleBll.GetEntity(r => r.IsSystem == ConstantParam.USER_ROLE_MGR && r.PropertyPlaceId == model.PlaceId); if (role != null) { propertyUser.PropertyUserRoles.Add(new R_PropertyUserRole() { RoleId = role.Id, }); } //创建管理员 propertyUserBll.Save(propertyUser); //日志记录 jm.Content = PropertyUtils.ModelToJsonString(model); } else { jm.Msg = ConstantParam.JSON_RESULT_MODEL_CHECK_ERROR; } return(jm); }
/// <summary> /// 获取退款结果数据 /// </summary> /// <param name="OrderId">订单ID</param> /// <returns></returns> private string GetRefundResult(int OrderId) { string RefundResult = ""; //获取订单数据 IOrderBLL orderBll = BLLFactory <IOrderBLL> .GetBLL("OrderBLL"); var order = orderBll.GetEntity(o => o.Id == OrderId); //如果已经生成了微信支付订单号且退单类型为退单退款 if (!string.IsNullOrEmpty(order.PayTradeNo) && order.RecedeType == 2) { //如果是微信在线支付 if (order.PayWay == 1) { //获取商家账户信息 var wxAccount = order.Shop.ShopAccounts.Where(a => a.AccountType == ConstantParam.PROPERTY_ACCOUNT_WeChat).FirstOrDefault(); if (wxAccount != null) { //获取商家账户信息 string WeixinAppId = wxAccount.Number; string WeixinMchId = wxAccount.MerchantNo; string WeixinPayKey = wxAccount.AccountKey; Random r = new Random(); #region 组装参数 //组装签名字符串 StringBuilder signStr = new StringBuilder(); //组装xml格式 StringBuilder varBody = new StringBuilder(); varBody.Append("<xml>"); //APP应用ID varBody.Append("<appid>" + WeixinAppId + "</appid>"); signStr.Append("appid=" + WeixinAppId + "&"); //商户号 varBody.Append("<mch_id>" + WeixinMchId + "</mch_id>"); signStr.Append("mch_id=" + WeixinMchId + "&"); //随机字符串 string str = "1234567890abcdefghijklmnopqrstuvwxyz"; string randomStr = ""; for (int i = 0; i < 32; i++) { randomStr = randomStr + str[r.Next(str.Length)].ToString(); } varBody.Append("<nonce_str>" + randomStr + "</nonce_str>"); signStr.Append("nonce_str=" + randomStr + "&"); //支付订单号 varBody.Append("<out_trade_no>" + order.PayTradeNo + "</out_trade_no>"); signStr.Append("out_trade_no=" + order.PayTradeNo + "&"); //签名 signStr.Append("key=" + WeixinPayKey); varBody.Append("<sign>" + PropertyUtils.GetMD5Str(signStr.ToString()).ToUpper() + "</sign>"); varBody.Append("</xml>"); #endregion //发送HTTP POST请求 string url = "https://api.mch.weixin.qq.com/pay/refundquery"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.ContentType = "text/xml"; // 信任证书 ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult); byte[] bytes = Encoding.UTF8.GetBytes(varBody.ToString()); request.ContentLength = bytes.Length; using (Stream writer = request.GetRequestStream()) { writer.Write(bytes, 0, bytes.Length); writer.Flush(); writer.Close(); } //处理返回结果 string result = null; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode == HttpStatusCode.OK) { using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) { result = reader.ReadToEnd(); reader.Close(); } } //解析返回数据 XmlDocument doc = new XmlDocument(); doc.LoadXml(result); string return_code = doc.GetElementsByTagName("return_code")[0].InnerText; //如果返回成功 if (return_code == "SUCCESS") { string result_code = doc.GetElementsByTagName("result_code")[0].InnerText; if (result_code == "SUCCESS") { String RefundStatus = doc.GetElementsByTagName("refund_status_0")[0].InnerText; switch (RefundStatus) { case "SUCCESS": RefundResult = "退款成功"; break; case "FAIL": RefundResult = "退款失败"; break; case "PROCESSING": RefundResult = "退款处理中"; break; default: RefundResult = "退款失败"; break; } } } } } //如果是支付宝在线支付 else if (order.PayWay == 2) { RefundResult = order.RefundResult; } } return(RefundResult); }
/// <summary> /// Post请求 订单申请退款 /// </summary> /// <returns></returns> private string ApplyRefund(T_Order order, string WeixinAppId, string WeixinMchId, string WeixinPayKey) { Random r = new Random(); #region 组装参数 //组装签名字符串 StringBuilder signStr = new StringBuilder(); //组装xml格式 StringBuilder varBody = new StringBuilder(); varBody.Append("<xml>"); //APP应用ID varBody.Append("<appid>" + WeixinAppId + "</appid>"); signStr.Append("appid=" + WeixinAppId + "&"); //商户号 varBody.Append("<mch_id>" + WeixinMchId + "</mch_id>"); signStr.Append("mch_id=" + WeixinMchId + "&"); //随机字符串 string str = "1234567890abcdefghijklmnopqrstuvwxyz"; string randomStr = ""; for (int i = 0; i < 32; i++) { randomStr = randomStr + str[r.Next(str.Length)].ToString(); } varBody.Append("<nonce_str>" + randomStr + "</nonce_str>"); signStr.Append("nonce_str=" + randomStr + "&"); //操作员 varBody.Append("<op_user_id>" + WeixinMchId + "</op_user_id>"); signStr.Append("op_user_id=" + WeixinMchId + "&"); //商户退款单号 string refundNo = DateTime.Now.ToFileTime().ToString() + new Random().Next(1000); varBody.Append("<out_refund_no>" + refundNo + "</out_refund_no>"); signStr.Append("out_refund_no=" + refundNo + "&"); //商户订单号 varBody.Append("<out_trade_no>" + order.PayTradeNo + "</out_trade_no>"); signStr.Append("out_trade_no=" + order.PayTradeNo + "&"); int fee = Convert.ToInt32(order.OrderPrice * 100); //退款金额 varBody.Append("<refund_fee>" + fee + "</refund_fee>"); signStr.Append("refund_fee=" + fee + "&"); //总金额 varBody.Append("<total_fee>" + fee + "</total_fee>"); signStr.Append("total_fee=" + fee + "&"); //签名 signStr.Append("key=" + WeixinPayKey); varBody.Append("<sign>" + PropertyUtils.GetMD5Str(signStr.ToString()).ToUpper() + "</sign>"); varBody.Append("</xml>"); #endregion //发送HTTP POST请求 string url = "https://api.mch.weixin.qq.com/secapi/pay/refund"; string cert = HttpContext.Current.Server.MapPath("/App_Data/apiclient_cert.p12"); string password = WeixinMchId; ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult); X509Certificate cer = new X509Certificate(cert, password); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.ContentType = "text/xml"; request.ClientCertificates.Add(cer); byte[] bytes = Encoding.UTF8.GetBytes(varBody.ToString()); request.ContentLength = bytes.Length; using (Stream writer = request.GetRequestStream()) { writer.Write(bytes, 0, bytes.Length); writer.Flush(); writer.Close(); } //处理返回结果 string result = null; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode == HttpStatusCode.OK) { using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) { result = reader.ReadToEnd(); reader.Close(); } } return(result); }
/// <summary> /// Post请求 生成订单 /// </summary> /// <returns></returns> private string CreateTradePost(T_HouseUserExpenseDetails record, string WeixinAppId, string WeixinMchId, string WeixinPayKey) { Random r = new Random(); #region 组装参数 //组装签名字符串 StringBuilder signStr = new StringBuilder(); //组装xml格式 StringBuilder varBody = new StringBuilder(); varBody.Append("<xml>"); //APP应用ID varBody.Append("<appid>" + WeixinAppId + "</appid>"); signStr.Append("appid=" + WeixinAppId + "&"); //商品描述 string body = record.PropertyExpenseType.Name + "(" + record.ExpenseDateDes + ")"; varBody.Append("<body>" + body + "</body>"); signStr.Append("body=" + body + "&"); //商户号 varBody.Append("<mch_id>" + WeixinMchId + "</mch_id>"); signStr.Append("mch_id=" + WeixinMchId + "&"); //随机字符串 string str = "1234567890abcdefghijklmnopqrstuvwxyz"; string randomStr = ""; for (int i = 0; i < 32; i++) { randomStr = randomStr + str[r.Next(str.Length)].ToString(); } varBody.Append("<nonce_str>" + randomStr + "</nonce_str>"); signStr.Append("nonce_str=" + randomStr + "&"); //通知地址 string notifyUrl = PropertyUtils.GetConfigParamValue("HostUrl") + "/Common/WeixinExpenseNotifyUrl"; varBody.Append("<notify_url>" + notifyUrl + "</notify_url>"); signStr.Append("notify_url=" + notifyUrl + "&"); //商户订单号 string no = DateTime.Now.ToFileTime().ToString() + new Random().Next(1000); varBody.Append("<out_trade_no>" + no + "</out_trade_no>"); signStr.Append("out_trade_no=" + no + "&"); //保存订单号 IHouseUserExpenseDetailsBLL expenseDetailsBLL = BLLFactory <IHouseUserExpenseDetailsBLL> .GetBLL("HouseUserExpenseDetailsBLL"); record.PayTradeNo = no; expenseDetailsBLL.Update(record); //终端ID varBody.Append("<spbill_create_ip>218.58.55.130</spbill_create_ip>"); signStr.Append("spbill_create_ip=" + "218.58.55.130" + "&"); //总金额 int fee = Convert.ToInt32(record.Expense * 100); varBody.Append("<total_fee>" + fee + "</total_fee>"); signStr.Append("total_fee=" + fee + "&"); //交易类型 varBody.Append("<trade_type>APP</trade_type>"); signStr.Append("trade_type=APP&"); //签名 signStr.Append("key=" + WeixinPayKey); varBody.Append("<sign>" + PropertyUtils.GetMD5Str(signStr.ToString()).ToUpper() + "</sign>"); varBody.Append("</xml>"); #endregion //发送HTTP POST请求 string url = "https://api.mch.weixin.qq.com/pay/unifiedorder"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.ContentType = "text/xml"; // 信任所有证书 ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult); byte[] bytes = Encoding.UTF8.GetBytes(varBody.ToString()); request.ContentLength = bytes.Length; using (Stream writer = request.GetRequestStream()) { writer.Write(bytes, 0, bytes.Length); writer.Flush(); writer.Close(); } //处理返回结果 string result = null; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode == HttpStatusCode.OK) { using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) { result = reader.ReadToEnd(); reader.Close(); } } return(result); }
public ActionResult WeixinPayNotifyUrl() { Stream st = Request.InputStream; StreamReader sr = new StreamReader(st); string SRstring = sr.ReadToEnd(); XmlDocument doc = new XmlDocument(); doc.LoadXml(SRstring); sr.Close(); string return_code = doc.GetElementsByTagName("return_code")[0].InnerText; //如果返回成功 if (return_code == "SUCCESS") { string result_code = doc.GetElementsByTagName("result_code")[0].InnerText; if (result_code == "SUCCESS") { IOrderBLL orderBll = BLLFactory <IOrderBLL> .GetBLL("OrderBLL"); string orderNo = doc.GetElementsByTagName("out_trade_no")[0].InnerText; var order = orderBll.GetEntity(o => o.PayTradeNo == orderNo); if (order != null && order.OrderStatus == ConstantParam.OrderStatus_NOPAY) { //获取商家账户信息 var wxAccount = order.Shop.ShopAccounts.Where(a => a.AccountType == ConstantParam.PROPERTY_ACCOUNT_WeChat).FirstOrDefault(); if (wxAccount != null) { //获取商家账户信息 string WeixinPayKey = wxAccount.AccountKey; //组装签名字符串 StringBuilder signStr = new StringBuilder(); signStr.Append("appid=" + doc.GetElementsByTagName("appid")[0].InnerText + "&"); signStr.Append("bank_type=" + doc.GetElementsByTagName("bank_type")[0].InnerText + "&"); signStr.Append("cash_fee=" + doc.GetElementsByTagName("cash_fee")[0].InnerText + "&"); signStr.Append("fee_type=" + doc.GetElementsByTagName("fee_type")[0].InnerText + "&"); signStr.Append("is_subscribe=" + doc.GetElementsByTagName("is_subscribe")[0].InnerText + "&"); signStr.Append("mch_id=" + doc.GetElementsByTagName("mch_id")[0].InnerText + "&"); signStr.Append("nonce_str=" + doc.GetElementsByTagName("nonce_str")[0].InnerText + "&"); signStr.Append("openid=" + doc.GetElementsByTagName("openid")[0].InnerText + "&"); signStr.Append("out_trade_no=" + orderNo + "&"); signStr.Append("result_code=" + result_code + "&"); signStr.Append("return_code=" + return_code + "&"); signStr.Append("time_end=" + doc.GetElementsByTagName("time_end")[0].InnerText + "&"); signStr.Append("total_fee=" + doc.GetElementsByTagName("total_fee")[0].InnerText + "&"); signStr.Append("trade_type=" + doc.GetElementsByTagName("trade_type")[0].InnerText + "&"); signStr.Append("transaction_id=" + doc.GetElementsByTagName("transaction_id")[0].InnerText + "&"); signStr.Append("key=" + WeixinPayKey); string sign = PropertyUtils.GetMD5Str(signStr.ToString()).ToUpper(); //签名验证成功 if (doc.GetElementsByTagName("sign")[0].InnerText == sign) { //更新订单状态 order.OrderStatus = ConstantParam.OrderStatus_RECEIPT; order.PayWay = 1; order.PayDate = DateTime.Now; if (orderBll.Update(order)) { IShopBLL shopBLL = BLLFactory <IShopBLL> .GetBLL("ShopBLL"); var ShopUserId = shopBLL.GetEntity(s => s.Id == order.ShopId).ShopUserId; //推送给订单所属商家 IShopUserPushBLL userPushBLL = BLLFactory <IShopUserPushBLL> .GetBLL("ShopUserPushBLL"); var userPush = userPushBLL.GetEntity(p => p.UserId == ShopUserId); if (userPush != null) { string registrationId = userPush.RegistrationId; string alert = "订单号为" + order.OrderNo + "的订单已支付,点击查看详情"; //通知信息 PropertyUtils.SendPush("订单支付通知", alert, ConstantParam.MOBILE_TYPE_SHOP, registrationId); } } } } } return(Content("success")); } } return(Content("fail")); }
public ActionResult WeixinExpenseNotifyUrl() { Stream st = Request.InputStream; StreamReader sr = new StreamReader(st); string SRstring = sr.ReadToEnd(); XmlDocument doc = new XmlDocument(); doc.LoadXml(SRstring); sr.Close(); string return_code = doc.GetElementsByTagName("return_code")[0].InnerText; //如果返回成功 if (return_code == "SUCCESS") { string result_code = doc.GetElementsByTagName("result_code")[0].InnerText; if (result_code == "SUCCESS") { string expenseOrderNo = doc.GetElementsByTagName("out_trade_no")[0].InnerText; IHouseUserExpenseDetailsBLL expenseDetailsBLL = BLLFactory <IHouseUserExpenseDetailsBLL> .GetBLL("HouseUserExpenseDetailsBLL"); var record = expenseDetailsBLL.GetEntity(e => e.PayTradeNo == expenseOrderNo); if (record != null && record.IsPayed == ConstantParam.PAYED_FALSE) { //获取物业微信账户信息 T_PropertyAccount wxAccount = null; if (record.BuildDoorId != null) { wxAccount = record.BuildDoor.BuildUnit.Build.PropertyPlace.PropertyAccounts.Where( a => a.AccountType == ConstantParam.PROPERTY_ACCOUNT_WeChat).FirstOrDefault(); } else { wxAccount = record.BuildCompany.PropertyPlace.PropertyAccounts.Where( a => a.AccountType == ConstantParam.PROPERTY_ACCOUNT_WeChat).FirstOrDefault(); } if (wxAccount != null) { string WeixinPayKey = wxAccount.AccountKey; //组装签名字符串 StringBuilder signStr = new StringBuilder(); signStr.Append("appid=" + doc.GetElementsByTagName("appid")[0].InnerText + "&"); signStr.Append("bank_type=" + doc.GetElementsByTagName("bank_type")[0].InnerText + "&"); signStr.Append("cash_fee=" + doc.GetElementsByTagName("cash_fee")[0].InnerText + "&"); signStr.Append("fee_type=" + doc.GetElementsByTagName("fee_type")[0].InnerText + "&"); signStr.Append("is_subscribe=" + doc.GetElementsByTagName("is_subscribe")[0].InnerText + "&"); signStr.Append("mch_id=" + doc.GetElementsByTagName("mch_id")[0].InnerText + "&"); signStr.Append("nonce_str=" + doc.GetElementsByTagName("nonce_str")[0].InnerText + "&"); signStr.Append("openid=" + doc.GetElementsByTagName("openid")[0].InnerText + "&"); signStr.Append("out_trade_no=" + expenseOrderNo + "&"); signStr.Append("result_code=" + result_code + "&"); signStr.Append("return_code=" + return_code + "&"); signStr.Append("time_end=" + doc.GetElementsByTagName("time_end")[0].InnerText + "&"); signStr.Append("total_fee=" + doc.GetElementsByTagName("total_fee")[0].InnerText + "&"); signStr.Append("trade_type=" + doc.GetElementsByTagName("trade_type")[0].InnerText + "&"); signStr.Append("transaction_id=" + doc.GetElementsByTagName("transaction_id")[0].InnerText + "&"); signStr.Append("key=" + WeixinPayKey); string sign = PropertyUtils.GetMD5Str(signStr.ToString()).ToUpper(); //签名验证成功 if (doc.GetElementsByTagName("sign")[0].InnerText == sign) { record.IsPayed = ConstantParam.PAYED_TRUE; record.PaymentType = 2; record.PayedDate = DateTime.Now; expenseDetailsBLL.Update(record); } } } return(Content("success")); } } return(Content("fail")); }
public ApiResultModel CreateWeixinPayTrade(DetailSearchModel model) { ApiResultModel resultModel = new ApiResultModel(); try { //根据用户ID查找业主 IUserBLL ownerBll = BLLFactory <IUserBLL> .GetBLL("UserBLL"); T_User owner = ownerBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); //如果业主存在 if (owner != null) { //如果验证Token不通过或已过期 if (DateTime.Now > owner.TokenInvalidTime || model.Token != owner.Token) { resultModel.Msg = APIMessage.TOKEN_INVALID; return(resultModel); } //更新最近登录时间和Token失效时间 owner.LatelyLoginTime = DateTime.Now; owner.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid"))); ownerBll.Update(owner); //生成微信支付订单 IHouseUserExpenseDetailsBLL expenseDetailsBLL = BLLFactory <IHouseUserExpenseDetailsBLL> .GetBLL("HouseUserExpenseDetailsBLL"); var record = expenseDetailsBLL.GetEntity(e => e.Id == model.Id); if (record != null) { //获取物业缴费账户信息 T_PropertyAccount wxAccount = null; if (record.BuildDoorId != null) { wxAccount = record.BuildDoor.BuildUnit.Build.PropertyPlace.PropertyAccounts.Where( a => a.AccountType == ConstantParam.PROPERTY_ACCOUNT_WeChat).FirstOrDefault(); } else { wxAccount = record.BuildCompany.PropertyPlace.PropertyAccounts.Where( a => a.AccountType == ConstantParam.PROPERTY_ACCOUNT_WeChat).FirstOrDefault(); } if (wxAccount == null) { resultModel.Msg = "该用户所属物业未设置账户信息"; return(resultModel); } //获取物业账户信息 string WeixinAppId = wxAccount.Number; string WeixinMchId = wxAccount.MerchantNo; string WeixinPayKey = wxAccount.AccountKey; //生成预订单 string result = CreateTradePost(record, WeixinAppId, WeixinMchId, WeixinPayKey); //如果请求失败 if (result == null) { resultModel.Msg = APIMessage.WEIXIN_YUORDER_FAIL; return(resultModel); } //解析返回结果 XmlDocument doc = new XmlDocument(); doc.LoadXml(result); string return_code = doc.GetElementsByTagName("return_code")[0].InnerText; //如果返回成功 if (return_code == "SUCCESS") { string result_code = doc.GetElementsByTagName("result_code")[0].InnerText; if (result_code == "SUCCESS") { //预支付交易会话标识 string prepayid = doc.GetElementsByTagName("prepay_id")[0].InnerText; //随机字符串 string str = "1234567890abcdefghijklmnopqrstuvwxyz"; Random r = new Random(); string PayRandomStr = ""; for (int i = 0; i < 32; i++) { PayRandomStr += str[r.Next(str.Length)].ToString(); } //时间戳 var timestamp = Convert.ToInt64(DateTime.Now.Subtract(DateTime.Parse("1970-1-1")).TotalMilliseconds / 10000) * 10; //签名字符串 string PaySignStr = "appid=" + WeixinAppId + "&noncestr=" + PayRandomStr + "&package=Sign=WXPay&partnerid=" + WeixinMchId + "&prepayid=" + prepayid + "×tamp=" + timestamp + "&key=" + WeixinPayKey; resultModel.result = new { appid = WeixinAppId, partnerid = WeixinMchId, package = "Sign=WXPay", prepayid = prepayid, noncestr = PayRandomStr, timestamp = timestamp, sign = PropertyUtils.GetMD5Str(PaySignStr.ToString()).ToUpper() }; } else { string err_code_des = doc.GetElementsByTagName("err_code_des")[0].InnerText; resultModel.Msg = err_code_des; } } else { string return_msg = doc.GetElementsByTagName("return_msg")[0].InnerText; resultModel.Msg = return_msg; } } else { resultModel.Msg = APIMessage.EXPENSE_RECORD_NOEXIST; } } else { resultModel.Msg = APIMessage.NO_USER; } } catch { resultModel.Msg = APIMessage.REQUEST_EXCEPTION; } return(resultModel); }
public ApiResultModel Login(OwnerLoginModel model) { ApiResultModel resultModel = new ApiResultModel(); try { //根据用户名查找用户 IPropertyUserBLL propertyUserBll = BLLFactory <IPropertyUserBLL> .GetBLL("PropertyUserBLL"); T_PropertyUser user = propertyUserBll.GetEntity(u => u.UserName == model.UserName && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT); //1.判断用户名是否正确 if (user == null) { resultModel.Msg = APIMessage.NAME_ERROR; return(resultModel); } //2.判断密码是否正确 string md5Str = PropertyUtils.GetMD5Str(model.Password); if (user.Password != md5Str) { resultModel.Msg = APIMessage.PWD_ERROR; return(resultModel); } //产生随机令牌 var token = System.Guid.NewGuid().ToString("N"); //更新用户令牌和最近登录时间及Token失效时间 user.Token = token; user.LatelyLoginTime = DateTime.Now; user.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid"))); propertyUserBll.Update(user); //返回登录用户的ID和用户名以及令牌 resultModel.result = new { token = token, userId = user.Id, userName = user.UserName, isMgr = user.IsMgr }; //推送设备管理 IPropertyUserPushBLL userPushBll = BLLFactory <IPropertyUserPushBLL> .GetBLL("PropertyUserPushBLL"); var userPush = userPushBll.GetEntity(p => p.UserId == user.Id); var userPush1 = userPushBll.GetEntity(p => p.RegistrationId == model.RegistrationId); if (userPush != null) { userPush.RegistrationId = model.RegistrationId; userPushBll.Update(userPush); } else if (userPush1 != null) { userPush1.UserId = user.Id; userPushBll.Update(userPush1); } else { userPush = new T_PropertyUserPush() { UserId = user.Id, RegistrationId = model.RegistrationId }; userPushBll.Save(userPush); } } catch { resultModel.Msg = APIMessage.REQUEST_EXCEPTION; } return(resultModel); }