Пример #1
0
        public ActionResult OrderPay()
        {
            //订单id列表
            string oidList = WebHelper.GetQueryString("oidList");

            string           paySystemName   = "";
            decimal          allSurplusMoney = 0M;
            List <OrderInfo> orderList       = new List <OrderInfo>();

            foreach (string oid in StringHelper.SplitString(oidList))
            {
                //订单信息
                OrderInfo orderInfo = Orders.GetOrderByOid(TypeHelper.StringToInt(oid));
                if (orderInfo != null && orderInfo.Uid == WorkContext.Uid && orderInfo.OrderState == (int)OrderState.WaitPaying && orderInfo.PayMode == 1 && (paySystemName.Length == 0 || paySystemName == orderInfo.PaySystemName))
                {
                    orderList.Add(orderInfo);
                }
                else
                {
                    return(Redirect(Url.Action("index", "home")));
                }

                paySystemName    = orderInfo.PaySystemName;
                allSurplusMoney += orderInfo.SurplusMoney;
            }

            if (orderList.Count < 1 || allSurplusMoney == 0M)
            {
                return(Redirect(Url.Action("index", "home")));
            }
            WeiXinConfig wxconfig  = BMAConfig.WeiXinConfig;
            var          appId     = wxconfig.AppID; //WeixinConfig.AppID;
            var          nonceStr  = Util.CreateNonce_str();
            var          timestamp = DateTime.Now.Ticks.ToString().Substring(0, 10);
            var          domain    = wxconfig.Domain;
            var          url       = Request.Url.ToString().Replace("#", "");// domain + Request.Url.PathAndQuery;

            var jsTickect   = WeiXinHelp.IsExistjsapi_ticket();
            var string1     = "";
            var signature   = WeiXinHelp.GetjsSDK_Signature(nonceStr, jsTickect, timestamp, url); //JSAPI.GetSignature(jsTickect, nonceStr, timestamp, url, out string1);
            var userAgent   = Request.UserAgent;
            var userVersion = userAgent.Substring(userAgent.LastIndexOf("/") + 1);

            //WeiXinConfig wxconfig = BMAConfig.WeiXinConfig;
            //Logs.Write(form.ToString());
            var out_trade_no = orderList[0].OSN; //Guid.NewGuid().ToString();
            //var domain = wxconfig.Domain;
            var body             = "购买创梦星火商城商品";
            var detail           = "购买创梦星火商城商品";
            var attach           = "购买创梦星火商城商品";
            var fee_type         = "CNY";
            var total_fee        = Decimal.ToInt32(orderList[0].SurplusMoney) * 100;// *100;
            var trade_type       = "JSAPI";
            var spbill_create_ip = (trade_type == "APP" || trade_type == "NATIVE") ? Request.UserHostName : wxconfig.Spbill_create_ip;
            var time_start       = DateTime.Now.ToString("yyyyMMddHHmmss");
            var time_expire      = DateTime.Now.AddDays(7).ToString("yyyyMMddHHmmss"); //默认1个小时订单过期,开发者可自定义其他超时机制,原则上微信订单超时时间不超过2小时
            var goods_tag        = "商品";
            var notify_url       = wxconfig.NOTIFY_URL;                                //与下面的Notify对应,开发者可自定义其他url地址
            var product_id       = orderList[0].Oid.ToString();
            var openid           = WorkContext.Openid;
            var partnerKey       = wxconfig.PartnerKey;
            var content          = WxPayAPI.UnifiedOrder(
                wxconfig.AppID, wxconfig.Mch_id, wxconfig.Device_info, Util.CreateNonce_str(),
                body, detail, attach, out_trade_no, fee_type, total_fee, spbill_create_ip, time_start, time_expire,
                goods_tag, notify_url, trade_type, product_id, openid, partnerKey);
            var prepay_id = "";
            //var trade_type = "";
            var paySign = "";
            //var timestamp = "";
            var nonce_str   = "";
            var return_code = "";

            if (content.return_code.Value == "SUCCESS" && content.result_code.Value == "SUCCESS")
            {
                WxPayAPIHelp.WxPayData jsApiParam = new WxPayAPIHelp.WxPayData();
                string payTimeSamp = DateTime.Now.Ticks.ToString().Substring(0, 10);
                jsApiParam.SetValue("appId", wxconfig.AppID);
                jsApiParam.SetValue("timeStamp", payTimeSamp);
                jsApiParam.SetValue("nonceStr", content.nonce_str.Value);
                jsApiParam.SetValue("package", "prepay_id=" + content.prepay_id.Value);
                jsApiParam.SetValue("signType", "MD5");
                //prepay_id = content.prepay_id.Value;
                prepay_id  = content.prepay_id.Value;
                trade_type = content.trade_type.Value;
                paySign    = jsApiParam.MakeSign();

                timestamp   = payTimeSamp;
                nonce_str   = content.nonce_str.Value;
                return_code = content.result_code.Value;
            }
            else
            {
                return(PromptView("错误编号:" + content.return_code.Value + "错误信息:" + content.return_msg.Value));
            }
            OrderPayModel model = new OrderPayModel();

            model.OidList         = oidList;
            model.AllSurplusMoney = allSurplusMoney;
            model.OrderList       = orderList;
            model.PayPlugin       = Plugins.GetPayPluginBySystemName(paySystemName);
            model.nonceStr        = nonceStr;
            model.jsapiTicket     = jsTickect;
            model.nonce_str       = nonce_str;
            model.paySign         = paySign;
            model.signature       = signature;
            model.timestamp       = timestamp;
            model.userAgent       = userAgent;
            model.userVersion     = userVersion;
            model.appId           = appId;
            model.prepay_id       = prepay_id;
            return(View(model));

            //return PromptView("出错了!");
        }
Пример #2
0
        public ActionResult UserUpdate()
        {
            Models.UserUpdateModel model = new UserUpdateModel();
            if (WebHelper.IsGet())
            {
                if (WorkContext.UserLevel < 3)
                {
                    WeiXinConfig wxconfig  = BMAConfig.WeiXinConfig;
                    var          appId     = wxconfig.AppID; //WeixinConfig.AppID;
                    var          nonceStr  = Util.CreateNonce_str();
                    var          timestamp = DateTime.Now.Ticks.ToString().Substring(0, 10);
                    var          domain    = wxconfig.Domain;
                    var          url       = Request.Url.ToString().Replace("#", "");// domain + Request.Url.PathAndQuery;

                    var jsTickect   = WeiXinHelp.IsExistjsapi_ticket();
                    var string1     = "";
                    var signature   = WeiXinHelp.GetjsSDK_Signature(nonceStr, jsTickect, timestamp, url); //JSAPI.GetSignature(jsTickect, nonceStr, timestamp, url, out string1);
                    var userAgent   = Request.UserAgent;
                    var userVersion = userAgent.Substring(userAgent.LastIndexOf("/") + 1);                //微信版本号高于或者等于5.0才支持微信支付
                    model = new UserUpdateModel
                    {
                        appId       = appId,
                        nonceStr    = nonceStr,
                        signature   = signature,
                        timestamp   = timestamp,
                        jsapiTicket = jsTickect,
                        string1     = string1,
                        userAgent   = userAgent,
                        userVersion = userVersion,
                    };
                    return(View(model));
                    //return View(model);
                }

                else
                {
                    return(PromptView("/mob/ucenter", "你已是钻石会员"));
                }
            }
            else
            {
                int paytype = WebHelper.GetFormInt("paytype");
                int payfee  = 1;
                switch (paytype)
                {
                case 1:
                    if (WorkContext.UserLevel >= 1)
                    {
                        return(AjaxResult("", "已是银卡会员"));
                    }
                    payfee = 100;
                    break;

                case 2:
                    if (WorkContext.UserLevel >= 2)
                    {
                        return(AjaxResult("error", "已是金卡会员"));
                    }
                    payfee = 200;
                    if (WorkContext.UserLevel == 0)
                    {
                        paytype = 4;
                        payfee  = 300;
                    }
                    break;

                case 3:
                    if (WorkContext.UserLevel >= 3)
                    {
                        return(AjaxResult("error", "已是钻石会员"));
                    }
                    payfee = 300;
                    if (WorkContext.UserLevel == 1)

                    {
                        paytype = 5;
                        payfee  = 500;
                    }
                    if (WorkContext.UserLevel == 0)

                    {
                        paytype = 6;
                        payfee  = 600;
                    }
                    break;

                default:
                    return(AjaxResult("error", "请选择卡类型"));

                    break;
                }


                //return AjaxResult("success", WebHelper.GetRequestData("http://localhost:6174/mob/weixinweb/Notify", "body=" + paytype.ToString() + "&payfee=" + payfee));
                // return AjaxResult("success", GetpayJson(paytype, payfee));
                return(View());
            }
            //model.appid = "100";
            //return View(model);
        }