Beispiel #1
0
        public ActionResult TX(string userids)
        {
            var usermodel  = db.tb_userinfos.FirstOrDefault(s => s.UserID == userids);
            int thisdaystr = DateTime.Now.Day;

            if (usermodel == null)
            {
                return(Json(Comm.ToJsonResult("nofind", "用户不存在"), JsonRequestBehavior.AllowGet));
            }
            else if (thisdaystr != 10)
            {
                return(Json(Comm.ToJsonResult("noday", "每月10号为提现日"), JsonRequestBehavior.AllowGet));
            }
            else
            {
                string     appid             = AliPayConfig.appid;                //appid
                string     app_private_key   = AliPayConfig.app_private_key;      //私钥
                string     alipay_public_key = AliPayConfig.app_public_key;       //公钥
                string     charset           = "utf-8";
                string     out_biz_no        = AliPayConfig.GenerateOutTradeNo(); //订单号
                IAopClient client            = new DefaultAopClient("https://openapi.alipay.com/gateway.do", appid, app_private_key.Trim(), "json", "1.0", "RSA2", alipay_public_key.Trim(), charset, false);
                AlipayFundTransToaccountTransferRequest request = new AlipayFundTransToaccountTransferRequest();
                string  timestr       = DateTime.Now.AddMonths(-1).Month.ToString();
                decimal txamount      = usermodel.Balance;
                string  alipayaccount = usermodel.AliAccount;
                string  aliusername   = usermodel.AliUserName;
                //如果余额不足
                if (txamount <= 0)
                {
                    return(Json(Comm.ToJsonResult("nobalance", "余额不足"), JsonRequestBehavior.AllowGet));
                }
                //如果没绑定支付宝账号
                else if (string.IsNullOrWhiteSpace(alipayaccount))
                {
                    return(Json(Comm.ToJsonResult("noaccount", "未绑定支付宝"), JsonRequestBehavior.AllowGet));
                }
                else
                {
                    string remarkstr = timestr + "月佣金提现";
                    request.BizContent = "{" +
                                         "\"out_biz_no\":\"" + out_biz_no + "\"," +
                                         "\"payee_type\":\"ALIPAY_LOGONID\"," +
                                         "\"payee_account\":\"" + alipayaccount + "\"," +
                                         "\"amount\":\"" + txamount.ToString() + "\"," +
                                         "\"payer_show_name\":\"RP云购佣金提现\"," +
                                         "\"payee_real_name\":\"" + aliusername + "\"," +
                                         "\"remark\":\"" + remarkstr + "\"" +
                                         "  }";
                    AlipayFundTransToaccountTransferResponse response = client.Execute(request);
                    var    jsondataformain = Newtonsoft.Json.JsonConvert.DeserializeObject(response.Body) as JContainer;//转json格式
                    string signstr         = jsondataformain.SelectToken("sign").ToString();
                    string s   = jsondataformain.SelectToken("alipay_fund_trans_toaccount_transfer_response").ToString();
                    var    js  = Newtonsoft.Json.JsonConvert.DeserializeObject(s) as JContainer;
                    string msg = js.SelectToken("msg").ToString();
                    if (msg.Equals("Success"))
                    {
                        string rout_biz_no = js.SelectToken("out_biz_no").ToString();
                        string order_id    = js.SelectToken("order_id").ToString();
                        string pay_date    = js.SelectToken("pay_date").ToString();
                        //保存提现记录
                        Withdrawcash wmodel = new Withdrawcash();
                        wmodel.AliAccount = alipayaccount;
                        wmodel.order_id   = order_id;
                        wmodel.out_biz_no = rout_biz_no;
                        wmodel.pay_date   = pay_date;
                        wmodel.signstr    = signstr;
                        wmodel.txamount   = txamount;
                        wmodel.txmonth    = timestr;
                        wmodel.Userid     = usermodel.ID;
                        wmodel.UserName   = usermodel.UserName;
                        db.Withdrawcash.Add(wmodel);
                        usermodel.Balance = 0;
                        db.SaveChanges();
                        return(Json(Comm.ToJsonResult("Success", "提现成功"), JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        return(Json(Comm.ToJsonResult("txfail", "提现失败"), JsonRequestBehavior.AllowGet));
                    }
                }
            }
        }
Beispiel #2
0
 public ActionResult ZYOrderAliPay(Enums.Enums.OrderType body, string ordercode, string userID)
 {
     try
     {
         var ordermodel = db.zyorder.FirstOrDefault(s => s.OrderCode == ordercode);//查询订单信息
         if (!db.tb_userinfos.Any(s => s.UserID == userID))
         {
             return(Json(Comm.ToJsonResult("Error", "用户不存在"), JsonRequestBehavior.AllowGet));
         }
         if (body != Enums.Enums.OrderType.Recharge && body != Enums.Enums.OrderType.OrderPay)
         {
             return(Json(Comm.ToJsonResult("Error", "请求参数错误"), JsonRequestBehavior.AllowGet));
         }
         if (ordermodel == null)
         {
             return(Json(Comm.ToJsonResult("Error", "订单不存在"), JsonRequestBehavior.AllowGet));
         }
         string     appid             = AliPayConfig.appid;                //appid
         string     app_private_key   = AliPayConfig.app_private_key;      //私钥
         string     alipay_public_key = AliPayConfig.app_public_key;       //公钥
         string     charset           = "utf-8";
         string     outtradeno        = AliPayConfig.GenerateOutTradeNo(); //订单号
         string     notifyurl         = AliPayConfig.notifyurl;            //回调通知页面地址
         IAopClient client            = new DefaultAopClient("https://openapi.alipay.com/gateway.do", appid, app_private_key.Trim(), "json", "1.0", "RSA2", alipay_public_key.Trim(), charset, false);
         //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称如:alipay.trade.app.pay
         AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
         //SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
         AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
         model.Body           = ((Enums.Enums.OrderType)body).GetDisplayName();
         model.Subject        = "自营订单支付";
         model.TotalAmount    = ordermodel.total_fee.ToString(); //type.GetDisplayName();
         model.ProductCode    = AliPayConfig.productcode;
         model.OutTradeNo     = outtradeno;
         model.TimeoutExpress = "30m";
         request.SetBizModel(model);
         request.SetNotifyUrl(notifyurl);
         //这里和普通的接口调用不同,使用的是sdkExecute
         AlipayTradeAppPayResponse response = client.SdkExecute(request);
         //HttpUtility.HtmlEncode是为了输出到页面时防止被浏览器将关键参数html转义,实际打印到日志以及http传输不会有这个问题
         //Response.Write(HttpUtility.HtmlEncode(response.Body));
         string resultcode = HttpUtility.HtmlEncode(response.Body);
         if (!string.IsNullOrWhiteSpace(resultcode))
         {
             //保存下单信息到数据库
             PayOrder paymodel = new PayOrder();
             paymodel.OrderState           = Enums.Enums.OrderState.UnHandle;
             paymodel.out_trade_no         = outtradeno;
             paymodel.Paynoncestr          = string.Empty;
             paymodel.PayPrepay_id         = outtradeno;
             paymodel.settlement_total_fee = ordermodel.total_fee;
             paymodel.CreateTime           = DateTime.Now;
             paymodel.Sign       = resultcode;
             paymodel.total_fee  = ordermodel.total_fee;
             paymodel.User_ID    = userID;
             paymodel.OrderType  = body;
             paymodel.RelationID = ordermodel.ID;
             db.PayOrders.Add(paymodel);
             int resultrow = db.SaveChanges();
             if (resultrow > 0)
             {
                 string tempresult = resultcode.Replace("amp;", "");
                 var    returndata = new
                 {
                     result    = tempresult,
                     prepay_id = outtradeno
                 };
                 return(Json(Comm.ToJsonResult("Success", "成功", returndata), JsonRequestBehavior.AllowGet));
             }
             else
             {
                 return(Json(Comm.ToJsonResult("Error", "下单失败"), JsonRequestBehavior.AllowGet));
             }
         }
         else
         {
             return(Json(Comm.ToJsonResult("Error", "下单失败"), JsonRequestBehavior.AllowGet));
         }
     }
     catch (Exception ex)
     {
         return(Json(Comm.ToJsonResult("Error", ex.Message), JsonRequestBehavior.AllowGet));
     }
 }