public async Task <ApiResult> ReApplys(OrderReApplysModel model) { var order = await orderService.GetModelAsync(model.OrderId); if (order == null) { return(new ApiResult { status = 0, msg = "订单不存在" }); } long payResId = await userService.BalancePayAsync(model.OrderId); if (payResId == -1) { return(new ApiResult { status = 0, msg = "订单不存在" }); } if (payResId == -2) { return(new ApiResult { status = 0, msg = "用户不存在", data = order.Id }); } if (payResId == -5) { return(new ApiResult { status = 0, msg = "订单中有商品已经下架,请重新下单", data = order.Id }); } if (payResId == -3) { return(new ApiResult { status = 0, msg = "商品库存不足", data = order.Id }); } if (payResId == -4) { return(new ApiResult { status = 0, msg = "用户账户余额不足", data = order.Id }); } return(new ApiResult { status = 1, msg = "支付成功", data = order.Id }); }
public async Task <ApiResult> RePay(OrderReApplysModel model) { //long orderStateId = await idNameService.GetIdByNameAsync("待付款"); User user = JwtHelper.JwtDecrypt <User>(ControllerContext); OrderDTO order = await orderService.GetModelAsync(model.OrderId); if (order == null) { return(new ApiResult { status = 0, msg = "订单不存在" }); } long id = await orderService.ValidOrder(order.Id); if (id == -1) { return(new ApiResult { status = 0, msg = "订单不存在" }); } if (id == -2) { return(new ApiResult { status = 0, msg = "会员不存在", data = order.Id }); } if (id == -4) { return(new ApiResult { status = 0, msg = "订单中有商品已经下架,请重新下单", data = order.Id }); } if (id == -3) { return(new ApiResult { status = 0, msg = "商品库存不足", data = order.Id }); } WeChatPay weChatPay = new WeChatPay(); weChatPay.body = "订单支付"; weChatPay.out_trade_no = order.Code; weChatPay.openid = user.Code.Substring(3, 28); weChatPay.total_fee = Math.Truncate(order.Amount * 100).ToString(); string parm = HttpClientHelper.BuildParam(weChatPay); string key = System.Configuration.ConfigurationManager.AppSettings["KEY"]; parm = parm + "&key=" + key; string sign = CommonHelper.GetMD5(parm); HttpClient httpClient = new HttpClient(); string xml = HttpClientHelper.ObjSerializeXml(weChatPay, sign); //CacheHelper.SetCache("App_Order_Pay" + weChatPay.out_trade_no, sign, DateTime.UtcNow.AddMinutes(2), TimeSpan.Zero); string res = await HttpClientHelper.GetResponseByPostXMLAsync(httpClient, xml, "https://api.mch.weixin.qq.com/pay/unifiedorder"); if (!res.Contains("SUCCESS")) { return(new ApiResult { status = 0, msg = res }); } XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(res); XmlNode Child = xmlDoc.SelectSingleNode("xml/prepay_id"); log.DebugFormat($"待支付订单微信支付统一下单,时间:{DateTime.Now}"); TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0); GetWechat getWeChat = new GetWechat(); getWeChat.timeStamp = Convert.ToInt64(ts.TotalSeconds).ToString(); getWeChat.package = "prepay_id" + Child.InnerText; parm = HttpClientHelper.BuildParam(getWeChat); parm = parm.Replace("prepay_id", "prepay_id="); parm = parm + "&key=" + key; string paySign = CommonHelper.GetMD5(parm); GetWechat1 getWeChat1 = new GetWechat1(); getWeChat1.appId = getWeChat.appId; getWeChat1.nonceStr = getWeChat.nonceStr; getWeChat1.package = "prepay_id=" + Child.InnerText; getWeChat1.signType = getWeChat.signType; getWeChat1.timeStamp = getWeChat.timeStamp; getWeChat1.paySign = paySign; getWeChat1.orderId = order.Id; return(new ApiResult { status = 1, data = getWeChat1 }); }