public JsonResult Paying(ExpenseDetailsModel model) { JsonModel jm = new JsonModel(); //获取要去缴费的缴费明细 IHouseUserExpenseDetailsBLL expenseDetailsBLL = BLLFactory <IHouseUserExpenseDetailsBLL> .GetBLL("HouseUserExpenseDetailsBLL"); var expenseDetails = expenseDetailsBLL.GetEntity(u => u.Id == model.Id); if (expenseDetails == null) { jm.Msg = "该缴费记录不存在"; } else if (expenseDetails.IsPayed == ConstantParam.PAYED_TRUE) { jm.Msg = "该缴费记录已缴费"; } else { expenseDetails.IsPayed = ConstantParam.PAYED_TRUE; expenseDetails.PaymentType = 1; expenseDetails.PayedDate = DateTime.Now; expenseDetails.Operator = GetSessionModel().UserID; expenseDetails.InvoiceType = model.InvoiceType; //编辑成功 if (expenseDetailsBLL.Update(expenseDetails)) { //记录操作日志 jm.Content = PropertyUtils.ModelToJsonString(model); } } return(Json(jm, JsonRequestBehavior.AllowGet)); }
public ApiResultModel SetRecordToExpensed(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) { record.IsPayed = ConstantParam.PAYED_TRUE; record.PaymentType = 2; record.PayedDate = DateTime.Now; expenseDetailsBLL.Update(record); } else { resultModel.Msg = APIMessage.EXPENSE_RECORD_NOEXIST; } } else { resultModel.Msg = APIMessage.NO_USER; } } catch { resultModel.Msg = APIMessage.REQUEST_EXCEPTION; } return(resultModel); }
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")); }
/// <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); }