/// <summary> /// add /// </summary> /// <param name="txyInfo"></param> /// <returns></returns> public int Add(txyInfo model) { var str = GetInsertStr(model) + " select @@identity"; var dict = GetParameters(model); return(Convert.ToInt32(SqlHelperHere.ExecuteScalar(str, dict))); }
/// <summary> /// 检查阿里支付。正确返回订单号,错误返回null /// </summary> /// <param name="dict"></param> /// <param name="Total_amount"></param> /// <returns></returns> public string CheckAliPay(IDictionary <string, string> dict, string Total_amount) { bool flag = AlipaySignature.RSACheckV1(dict, alipayPublicKey, "utf-8", "RSA2", false); txyInfo info = new txyInfo(); info.content = JsonConvert.SerializeObject(dict + "==flag===" + flag); txyInfoOper.Instance.Add(info); if (flag) { var total_amount = dict["total_amount"]; var out_trade_no = dict["out_trade_no"]; string status = dict["trade_status"]; string seller_id = dict["seller_id"]; string app_id = dict["app_id"]; if (total_amount == Total_amount && seller_id == sellerId && app_id == appId) { switch (status) { case "TRADE_SUCCESS": return(out_trade_no); } } } return(null); }
/// <summary> /// update /// </summary> /// <param name="txyInfo"></param> /// <returns></returns> public void Update(txyInfo model) { var str = GetUpdateStr(model); var dict = GetParameters(model); SqlHelperHere.ExcuteNon(str, dict); }
/// <summary> /// 微信支付订单异步通知 /// </summary> /// <returns></returns> public string wxpayNotify() { var success = "<xml><return_code><![CDATA[SUCCESS]]></return_code>\n<return_msg><![CDATA[OK]]></return_msg></xml>"; var error = "<xml><return_code><![CDATA[FAIL]]></return_code>\n<return_msg><![CDATA[error]]></return_msg></xml>"; string xmlStr = getPostStr(); var outTradeNo = WXCheck(xmlStr); txyInfo info = new txyInfo(); info.content = "outTradeNo ====" + outTradeNo; txyInfoOper.Instance.Add(info); if (outTradeNo == null) { return(error); } var orderList2 = CacheHelper.GetByCondition <OrderInfo>("orderinfo", " orderNo= " + outTradeNo); if (orderList2.Count < 1) { return(error); } var order = orderList2.First(); if (order.status == 1) { return(success); } order.payType = "wxpay"; if ((bool)order.isTake) { order.status = 2; } else { order.status = 1; } order.payTime = DateTime.Now; OrderInfoOper.Instance.Update(order); var user = UserInfoOper.Instance.GetById((int)order.userId); user.userBalance -= order.useBalance; user.coupon -= order.useCoupon; UserInfoOper.Instance.Update(user); UPushHelper.Instance.PushAfterPayOrder(order); UserPayOper.Instance.payOrderAddRecord(order); return(success); }
/// <summary> /// 微信充值余额异步通知 /// </summary> /// <returns></returns> public string ChargeByWxNotify() { var success = "<xml><return_code><![CDATA[SUCCESS]]></return_code>\n<return_msg><![CDATA[OK]]></return_msg></xml>"; var error = "<xml><return_code><![CDATA[FAIL]]></return_code>\n<return_msg><![CDATA[error]]></return_msg></xml>"; string xmlStr = getPostStr(); var outTradeNo = WXCheck(xmlStr); txyInfo info = new txyInfo(); info.content = "wx--outTradeNo ====" + outTradeNo; txyInfoOper.Instance.Add(info); if (outTradeNo == null) { return(error); } var list = CacheHelper.GetByCondition <UserPay>("UserPay", " outTradeNo= \'" + outTradeNo + "\'"); if (list.Count < 1) { return(error); } var up = list.First(); if ((bool)up.status) { return(success); } up.status = true; UserPayOper.Instance.Update(up); //orderOper.Update(up); var user2 = UserInfoOper.Instance.GetById((int)up.userId); //user2.userBalance += up.money; var userHere = new UserInfo(); userHere.id = user2.id; userHere.userBalance = user2.userBalance + up.money; //user2.coupon -= up.useCoupon; UserInfoOper.Instance.Update(userHere); return(success); }
/// <summary> /// 更新 /// </summary> /// <param name="txyinfo"></param> /// <returns>是否成功</returns> public string GetUpdateStr(txyInfo txyinfo) { StringBuilder part1 = new StringBuilder(); part1.Append("update txyinfo set "); if (txyinfo.content != null) { part1.Append("content = @content,"); } if (txyinfo.ttime != null) { part1.Append("ttime = @ttime,"); } int n = part1.ToString().LastIndexOf(","); part1.Remove(n, 1); part1.Append(" where id= @id "); return(part1.ToString()); }
/// 获取参数 /// </summary> /// <param name="txyinfo"></param> /// <returns></returns> public Dictionary <string, string> GetParameters(txyInfo txyinfo) { Dictionary <string, string> dict = new Dictionary <string, string>(); if (txyinfo.id != null) { dict.Add("@id", txyinfo.id.ToString()); } if (txyinfo.content != null) { dict.Add("@content", txyinfo.content.ToString()); } if (txyinfo.ttime != null) { dict.Add("@ttime", txyinfo.ttime.ToString()); } return(dict); }
/// <summary> /// 支付宝充值余额异步通知 /// </summary> /// <returns></returns> public string chargeByAlipayNotify() { string success = "success"; string failure = "failure"; var dict2 = GetRequestPost(); var out_trade_no = dict2["out_trade_no"]; var list = CacheHelper.GetByCondition <UserPay>("UserPay", " outTradeNo= \'" + out_trade_no + "\'"); if (list.Count < 0) { return(failure); } var up = list.First(); var outTradeNo = CheckAliPay(dict2, up.money.ToString()); txyInfo info = new txyInfo(); info.content = "alipay--outTradeNo=====" + outTradeNo; txyInfoOper.Instance.Add(info); if (outTradeNo == null) { return(failure); } if ((bool)up.status) { return(success); } up.status = true; UserPayOper.Instance.Update(up); var user = UserInfoOper.Instance.GetById((int)up.userId); //user.userBalance += up.money; var userHere = new UserInfo(); userHere.id = user.id; userHere.userBalance = user.userBalance + up.money; UserInfoOper.Instance.Update(userHere); return(success); }
/// <summary> /// 插入 /// </summary> /// <param name="txyinfo"></param> /// <returns>是否成功</returns> public string GetInsertStr(txyInfo txyinfo) { StringBuilder part1 = new StringBuilder(); StringBuilder part2 = new StringBuilder(); if (txyinfo.content != null) { part1.Append("content,"); part2.Append("@content,"); } if (txyinfo.ttime != null) { part1.Append("ttime,"); part2.Append("@ttime,"); } StringBuilder sql = new StringBuilder(); sql.Append("insert into txyinfo(").Append(part1.ToString().Remove(part1.Length - 1)).Append(") values (").Append(part2.ToString().Remove(part2.Length - 1)).Append(")"); return(sql.ToString()); }
/// <summary> /// 成功返回订单号out_trade_no 错误返回 null /// </summary> /// <param name="xmlStr"></param> /// <returns></returns> public string WXCheck(string xmlStr) { try { var signFromWX = ""; XmlDocument xml = new XmlDocument(); xml.LoadXml(xmlStr); var dict = new Dictionary <string, string>(); foreach (XmlNode item in xml.FirstChild) { if (item.Name != "sign") { dict.Add(item.Name, item.InnerText); } else { signFromWX = item.InnerText; } } string sign = StringHelperHere.Instance.GetWXSign(dict, mchKey); if (dict["result_code"] == "SUCCESS") { //交易成功 string out_trade_no = dict["out_trade_no"];//商户订单号 if (sign != signFromWX) { return(null); } return(out_trade_no); } } catch (Exception e) { txyInfo info = new txyInfo(); info.content = e.Message; txyInfoOper.Instance.Add(info); } return(null); }
/// <summary> /// 支付宝支付订单异步通知 /// </summary> /// <returns></returns> public string alipayNotify() { string success = "success"; string failure = "failure"; try { var dict2 = GetRequestPost(); var out_trade_no = dict2["out_trade_no"]; var orderList = CacheHelper.GetByCondition <OrderInfo>("orderinfo", " orderNo= " + out_trade_no); if (orderList.Count < 0) { return(failure); } var order = orderList.First(); if (order.status == 1) { return(success); } var outTradeNo = CheckAliPay(dict2, order.payMoney.ToString()); txyInfo info = new txyInfo(); info.content = "outTradeNo=====" + outTradeNo; txyInfoOper.Instance.Add(info); if (outTradeNo == null) { return(failure); } var areaId = order.orderAreaId; order.payType = "alipay"; if ((bool)order.isTake) { order.status = 2; } else { order.status = 1; } order.payTime = DateTime.Now; OrderInfoOper.Instance.Update(order); var user = UserInfoOper.Instance.GetById((int)order.userId); user.userBalance -= order.useBalance; user.coupon -= order.useCoupon; UserInfoOper.Instance.Update(user); UPushHelper.Instance.PushAfterPayOrder(order); UserPayOper.Instance.payOrderAddRecord(order); } catch (Exception e) { txyInfo info = new txyInfo(); info.content = e.Message; txyInfoOper.Instance.Add(info); return(failure); } return(success); }
public HttpResponseMessage Charge(UserReq req) { var tokenStr = req.Token; var userId = Convert.ToInt32(req.userId); Token token = CacheHelper.GetUserToken(tokenStr); if (token == null) { return(ControllerHelper.Instance.JsonResult(400, "token失效")); } if (token.Payload.UserID != userId) { return(ControllerHelper.Instance.JsonResult(400, "token错误")); } var payType = req.payType; var payMoney = Convert.ToDecimal(req.payMoney); var Spbill_create_ip = req.spbill_create_ip; var out_trade_no = StringHelperHere.Instance.GetTimeStamp() + StringHelperHere.Instance.GetLastFiveStr(userId.ToString()); UserPay up = new UserPay(); up.type = 0; up.status = false; up.userId = userId; up.createTime = DateTime.Now; up.takeType = payType; up.outTradeNo = out_trade_no; up.money = payMoney; UserPayOper.Instance.Add(up); if (payType == "alipay") { //var str = alipay.CreateAlipayOrder(chargeMoney, out_trade_no, "http://" + apiHost + "/user/chargeByAlipayNotify"); AlipayHelperHere a = new AlipayHelperHere(); var b = a.CreateAlipayOrder(req.payMoney, out_trade_no, "https://fan-di.com/notify/chargeByAlipayNotify"); JObject jo = new JObject(); jo.Add("payType", "alipay"); jo.Add("payStr", b); return(ControllerHelper.Instance.JsonResult(200, JsonConvert.SerializeObject(jo), "")); } else { WXPayHelperHere w = new WXPayHelperHere(); var b = w.CreateWXOrder(payMoney, out_trade_no, "https://fan-di.com/notify/ChargeByWxNotify", Spbill_create_ip); XmlDocument doc = new XmlDocument(); doc.LoadXml(b); if (doc.DocumentElement["return_code"].InnerText != "SUCCESS") { txyInfo txy = new txyInfo(); txy.content = JsonConvert.SerializeObject(doc); //txyInfoOper txyOper = new txyInfoOper(); txyInfoOper.Instance.Add(txy); return(ControllerHelper.Instance.JsonResult(500, "网络不稳定,请稍后")); } JObject jo = new JObject(); jo.Add("payType", "wxpay"); foreach (XmlNode item in doc.DocumentElement.ChildNodes) { if (item.Name != "sign") { jo.Add(item.Name, item.InnerText); } } var timestamp = StringHelperHere.Instance.GetTimeStamp(); jo.Add("timestamp", timestamp); var dict = new Dictionary <string, string>(); foreach (var item in jo) { if (item.Key == "prepay_id") { dict.Add("prepayid", item.Value.ToString()); } if (item.Key == "nonce_str") { dict.Add("noncestr", item.Value.ToString()); } } dict.Add("appid", "wxd8482615c33b8859"); dict.Add("partnerid", "1494504712"); dict.Add("package", "Sign=WXPay"); dict.Add("timestamp", timestamp); string sign = StringHelperHere.Instance.GetWXSign(dict, "2BCF8DD9490E328D2FCEDE7B26643231"); jo.Add("sign", sign); return(ControllerHelper.Instance.JsonResult(200, JsonConvert.SerializeObject(jo), "")); } }