Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Request.ValidateInput();
            int orderid = Request["out_trade_no"].ConvertTo <int>(0);
            //根据订单id得到订单信息
            B2bOrderData dataorder     = new B2bOrderData();
            B2b_order    modelb2border = dataorder.GetOrderById(orderid);

            //根据产品id得到产品信息
            B2bComProData datapro     = new B2bComProData();
            B2b_com_pro   modelcompro = datapro.GetProById(modelb2border.Pro_id.ToString());

            ////////////////////////////////////////////请求参数////////////////////////////////////////////

            //必填参数//

            //请与贵网站订单系统中的唯一订单号匹配
            string out_trade_no = orderid.ToString();
            //订单名称,显示在支付宝收银台里的“商品名称”里,显示在支付宝的交易管理的“商品名称”的列表里。
            string subject = "";

            if (modelb2border.Order_type == 2)
            {
                subject = "预付款充值";
            }
            else
            {
                subject = modelcompro.Pro_name;
            }

            //订单描述、订单详细、订单备注,显示在支付宝收银台里的“商品描述”里
            string body = "pay";
            //订单总金额,显示在支付宝收银台里的“应付总额”里
            string total_fee = String.Format("{0:N2}", (modelb2border.U_num * modelb2border.Pay_price + modelb2border.Express) - modelb2border.Integral1 - modelb2border.Imprest1); //

            if (modelb2border.Shopcartid > 0)                                                                                                                                       //如果是购物车产品重新计算费用
            {
                total_fee = String.Format("{0:N2}", dataorder.GetCartOrderMoneyById(orderid));
            }


            total_fee = total_fee.Replace(",", "");


            //扩展功能参数——默认支付方式//

            //默认支付方式,代码见“即时到帐接口”技术文档
            string paymethod = Request["paymethod"];
            //默认网银代号,代号列表见“即时到帐接口”技术文档“附录”→“银行列表”
            string defaultbank = Request["defaultbank"];

            //扩展功能参数——防钓鱼//

            //防钓鱼时间戳
            string anti_phishing_key = "";
            //获取客户端的IP地址,建议:编写获取客户端IP地址的程序
            string exter_invoke_ip = "";
            //注意:
            //请慎重选择是否开启防钓鱼功能
            //exter_invoke_ip、anti_phishing_key一旦被设置过,那么它们就会成为必填参数
            //建议使用POST方式请求数据
            //示例:
            //exter_invoke_ip = "";
            //Service aliQuery_timestamp = new Service();
            //anti_phishing_key = aliQuery_timestamp.Query_timestamp();               //获取防钓鱼时间戳函数

            //扩展功能参数——其他//

            //商品展示地址,要用http:// 格式的完整路径,不允许加?id=123这类自定义参数
            string show_url = "";
            //自定义参数,可存放任何内容(除=、&等特殊字符外),不会显示在页面上
            string extra_common_param = "";
            //默认买家支付宝账号
            string buyer_email = "";

            //扩展功能参数——分润(若要使用,请按照注释要求的格式赋值)//

            //提成类型,该值为固定值:10,不需要修改
            string royalty_type = "";
            //提成信息集
            string royalty_parameters = "";
            //注意:
            //与需要结合商户网站自身情况动态获取每笔交易的各分润收款账号、各分润金额、各分润说明。最多只能设置10条
            //各分润金额的总和须小于等于total_fee
            //提成信息集格式为:收款方Email_1^金额1^备注1|收款方Email_2^金额2^备注2
            //示例:
            //royalty_type = "10";
            //royalty_parameters = "[email protected]^0.01^分润备注一|[email protected]^0.01^分润备注二";

            ////////////////////////////////////////////////////////////////////////////////////////////////

            //把请求参数打包成数组
            SortedDictionary <string, string> sParaTemp = new SortedDictionary <string, string>();

            sParaTemp.Add("payment_type", "1");
            sParaTemp.Add("show_url", show_url);
            sParaTemp.Add("out_trade_no", out_trade_no);
            sParaTemp.Add("subject", subject);
            sParaTemp.Add("body", body);
            sParaTemp.Add("total_fee", total_fee);
            sParaTemp.Add("paymethod", paymethod);
            sParaTemp.Add("defaultbank", defaultbank);
            sParaTemp.Add("anti_phishing_key", anti_phishing_key);
            sParaTemp.Add("exter_invoke_ip", exter_invoke_ip);
            sParaTemp.Add("extra_common_param", extra_common_param);
            sParaTemp.Add("buyer_email", buyer_email);
            sParaTemp.Add("royalty_type", royalty_type);
            sParaTemp.Add("royalty_parameters", royalty_parameters);
            sParaTemp.Add("default_login", "Y");


            //写入支付数据库,先判定是否有此订单支付
            //根据订单id得到订单信息
            B2bPayData datapay    = new B2bPayData();
            B2b_pay    modelb2pay = datapay.GetPayByoId(orderid);


            if (modelb2pay == null)
            {
                B2b_pay eticket = new B2b_pay()
                {
                    Id           = 0,
                    Oid          = orderid,
                    Pay_com      = "alipay",
                    Pay_name     = modelb2border.U_name,
                    Pay_phone    = modelb2border.U_phone,
                    Total_fee    = decimal.Parse(total_fee),
                    Trade_no     = "",
                    Trade_status = "trade_pendpay",
                    Uip          = "",
                    comid        = 106
                };
                int payid = datapay.InsertOrUpdate(eticket);
            }
            else
            {
                //对已完成支付的,再次提交支付,跳转到订单也或显示此订单已支付
                if (modelb2pay.Trade_status != "TRADE_SUCCESS")
                {
                    //防止金额有所改动
                    modelb2pay.comid     = 106;
                    modelb2pay.Pay_com   = "alipay";
                    modelb2pay.Total_fee = decimal.Parse(total_fee);
                    datapay.InsertOrUpdate(modelb2pay);
                }
                else
                {
                }
            }


            //构造即时到帐接口表单提交HTML数据,无需修改
            Service ali       = new Service();
            string  sHtmlText = ali.Create_direct_pay_by_user(sParaTemp);

            Response.Write(sHtmlText);
        }
Exemplo n.º 2
0
        public void Page_Load(object sender, EventArgs e)
        {
            string u = Request.ServerVariables["HTTP_USER_AGENT"];

            bo = detectmobilebrowser.HttpUserAgent(u);


            //TxtHelper.WriteFile("D:\\site\\b2betown\\ETS2.WebApp\\Log.txt", "Request.Url:" + Request.Url.ToString());

            id = Request["id"].ConvertTo <string>("");
            string temp_id = Request["id"].ConvertTo <string>("");


            if (Request.Cookies["temp_userid"] != null)
            {
                userid = Request.Cookies["temp_userid"].Value;
            }
            else
            {
                userid = Domain_def.HuoQu_Temp_UserId();
                //Response.Cookies("userid").val();

                HttpCookie cookie = new HttpCookie("temp_userid");     //实例化HttpCookie类并添加值
                cookie.Value   = userid;
                cookie.Expires = DateTime.Now.AddDays(365);
                Response.Cookies.Add(cookie);
            }


            //取消超时订单
            B2b_com_pro pro_cannelorder = new B2b_com_pro();

            pro_cannelorder.Server_type = 0;
            int rs_cannelorder = new B2bComProData().CancelOvertimeOrder(pro_cannelorder);



            num = Request["num"].ConvertTo <int>(1);

            string aRequestUrl = Request.ServerVariables["SERVER_NAME"].ToLower();

            //TxtHelper.WriteFile("D:\\site\\b2betown\\ETS2.WebApp\\Log.txt", "aRequestUrl:" + aRequestUrl);
            if (Domain_def.Domain_yanzheng(aRequestUrl))//如果符合shop101.etown.cn的格式
            {
                //先通过正则表达式获取COMid
                comid = Int32.Parse(Domain_def.Domain_Huoqu(aRequestUrl).ToString());
            }

            if (comid == 0)//如果非标准格式,查询 是否有绑定的域名
            {
                var domaincomid = B2bCompanyData.GetComId(RequestUrl);
                if (domaincomid != null)
                {
                    comid = domaincomid.Com_id;
                }
            }



            //TxtHelper.WriteFile("D:\\site\\b2betown\\ETS2.WebApp\\Log.txt", "comid:" + comid);
            #region 判断是否含有微信端传递过来的code值,不含有自刷新
            code = Request.QueryString["code"].ConvertTo <string>("");
            if (code == "")
            {
                selfrefreshurl = WeiXinJsonData.GetFollowOpenLinkUrlAboutPay(comid, "http://shop" + comid + ".etown.cn/wxpay/micromart_pay_" + num + "_" + id + ".aspx");
                //TxtHelper.WriteFile("D:\\site\\b2betown\\ETS2.WebApp\\Log.txt", "selfrefreshurl:" + selfrefreshurl);
                //Response.Redirect(refreshurl);
            }
            #endregion


            //buyuid = Request["buyuid"].ConvertTo<int>(0);
            //tocomid = Request["tocomid"].ConvertTo<int>(0);
            //uid = Request["uid"].ConvertTo<int>(0);
            //获取IP地址
            uip = CommonFunc.GetRealIP();


            nowdate  = DateTime.Now.ToString("yyyy-MM-dd");
            nowtoday = DateTime.Now;

            if (temp_id != "")
            {
                B2bOrderData orderdata = new B2bOrderData();
                var          pro       = orderdata.GetOrderById(int.Parse(temp_id));
                if (pro != null)
                {
                    orderstatus = EnumUtils.GetName((OrderStatus)pro.Order_state);
                    order_state = pro.Order_state;
                    subtime     = pro.U_subdate.ToString("yyyy/MM/dd hh:mm:ss");
                    paystate    = pro.Pay_state;

                    #region 微信端 共享收货地址接口 参数获取

                    //根据产品判断商家是否含有自己的微信支付:a.含有的话支付到商家;b.没有的话支付到平台的微信公众号账户中
                    B2b_finance_paytype model = new B2b_finance_paytypeData().GetFinancePayTypeByComid(pro.Comid);
                    //TxtHelper.WriteFile("D:\\site\\b2betown\\ETS2.WebApp\\Log.txt", "b");
                    if (model != null)
                    {
                        //TxtHelper.WriteFile("D:\\site\\b2betown\\ETS2.WebApp\\Log.txt", "c");
                        //商家微信支付的所有参数都存在
                        if (model.Wx_appid != "" && model.Wx_appkey != "" && model.Wx_partnerid != "" && model.Wx_paysignkey != "")
                        {
                            appId     = model.Wx_appid;
                            appsecret = model.Wx_appkey;
                            //appkey = model.Wx_paysignkey;
                            //mchid = model.Wx_partnerid;
                            //TxtHelper.WriteFile("D:\\site\\b2betown\\ETS2.WebApp\\Log.txt", "d");
                            issetfinancepaytype = true;
                            if (code != "")
                            {
                                string url =
                                    string.Format(
                                        "https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code",
                                        appId, appsecret, code);
                                string returnStr = HttpUtil.Send("", url);
                                //TxtHelper.WriteFile("D:\\site\\b2betown\\ETS2.WebApp\\Log.txt", "returnStr:" + returnStr);

                                var obj = JsonConvert.DeserializeObject <ModelOpenID>(returnStr);
                                if (obj.openid == null)
                                {
                                    //TxtHelper.WriteFile("D:\\site\\b2betown\\ETS2.WebApp\\Log.txt", "微信转发页面打开的,returnStr:" + returnStr);

                                    selfrefreshurl = WeiXinJsonData.GetFollowOpenLinkUrlAboutPay(comid, "http://shop" + comid + ".etown.cn/wxpay/micromart_pay_" + num + "_" + id + ".aspx");
                                    Response.Redirect(selfrefreshurl);
                                }

                                if (obj != null)
                                {
                                    timeStamp          = TenpayUtil.getTimestamp();
                                    nonceStr           = TenpayUtil.getNoncestr();
                                    access_tokenstring = obj.access_token;
                                    openid             = obj.openid;

                                    HttpCookie newCookie = new HttpCookie("openid");
                                    //往Cookie里面添加值,均为键/值对。Cookie可以根据关键字寻找到相应的值
                                    newCookie.Values.Add("openid", openid);
                                    newCookie.Expires = DateTime.Now.AddDays(365);
                                    //Cookie的设置页面要用Response
                                    Response.AppendCookie(newCookie);

                                    //签名字段:appId、url(当前网页url)、timestamp、noncestr、accessToken
                                    var paySignReqHandler = new RequestHandler(Context);
                                    paySignReqHandler.setParameter("appid", appId);
                                    paySignReqHandler.setParameter("timestamp", timeStamp);
                                    paySignReqHandler.setParameter("noncestr", nonceStr);
                                    paySignReqHandler.setParameter("url", Request.Url.ToString());
                                    paySignReqHandler.setParameter("accesstoken", obj.access_token);
                                    //addrSign = paySignReqHandler.CreateAddrSign();
                                    //TxtHelper.WriteFile("D:\\site\\b2betown\\ETS2.WebApp\\Log.txt", appId + ";" + timeStamp + ";" + nonceStr + ";" + Request.Url.ToString() + ";" + obj.access_token + ";" + addrSign);
                                    //TxtHelper.WriteFile("D:\\site\\b2betown\\ETS2.WebApp\\Log.txt", "Request.Url:" + Request.Url.ToString());
                                    //TxtHelper.WriteFile("D:\\site\\b2betown\\ETS2.WebApp\\Log.txt", "addrSign:" + addrSign);
                                }
                            }
                        }
                    }

                    #endregion



                    address = pro.U_name + " " + pro.U_phone + "<br>" + pro.Province + " " + pro.City + " " + pro.Address;



                    if (pro.Shopcartid == 0)
                    {
                        B2b_com_pro proinfo = new B2bComProData().GetProById(pro.Pro_id.ToString(), pro.Speciid, pro.channelcoachid);
                        if (proinfo != null)
                        {
                            pro_name    = proinfo.Pro_name;
                            imgurl      = FileSerivce.GetImgUrl(proinfo.Imgurl);
                            Ispanicbuy  = proinfo.Ispanicbuy;
                            Server_type = proinfo.Server_type;
                        }
                        else
                        {
                            pro_name = "对订单进行支付";
                        }
                        pay_price = Math.Round(pro.Pay_price, 2);
                        pro_price = Math.Round(pro.Pay_price * pro.U_num, 2);
                        price     = Math.Round(pro.Pay_price * pro.U_num - pro.Integral1 - pro.Imprest1 + pro.Express, 2);
                        num       = pro.U_num;
                        Express   = Math.Round(pro.Express, 2);
                    }
                    else
                    { //如果是购物车订单,必须一起支付
                        cart_id  = pro.Shopcartid;
                        cart     = 1;
                        price    = Math.Round(orderdata.GetCartOrderMoneyById(pro.Id), 2);
                        pro_name = orderdata.GetCartOrderProById(pro.Id);
                        Express  = Math.Round(orderdata.GetCartOrderExpressMoneyById(pro.Id), 2);
                        num      = 1;
                        var shopcart = orderdata.shopcartorder(pro.Shopcartid);
                        if (shopcart != null)
                        {
                            for (int i = 0; i < shopcart.Count; i++)
                            {
                                pro_price += shopcart[i].Pay_price * shopcart[i].U_num;
                                proid     += shopcart[i].Pro_id + ",";
                            }
                        }

                        pro_price = Math.Round(pro_price, 2);
                    }
                }



                if (price == 0)
                {
                    price = 0;
                }
                else
                {
                    CommonFunc.OperTwoDecimal(price.ToString());
                    //price = price.IndexOf(".") != -1 ? price.Substring(0, price.IndexOf(".")) : price;
                }

                nowdate = DateTime.Now.ToString("yyyy-MM-dd");

                if (summary.Length > 30)
                {
                    summary = summary.Substring(0, 30);
                }
                if (summary.Length > 150)
                {
                    summary = summary.Substring(0, 150) + "...";
                }
                var commodel = B2bCompanyData.GetCompany(comid);
                if (commodel != null)
                {
                    if (commodel.B2bcompanyinfo != null)
                    {
                        Wxfocus_url    = commodel.B2bcompanyinfo.Wxfocus_url;
                        Wxfocus_author = commodel.B2bcompanyinfo.Wxfocus_author;;
                    }
                }


                var saleset = B2bCompanySaleSetData.GetDirectSellByComid(comid.ToString());
                if (saleset != null)
                {
                    phone = saleset.Service_Phone;
                }

                //查询项目电话,如果有项目电话调取项目电话
                var projectdata  = new B2b_com_projectData();
                var projectmodel = projectdata.GetProject(projectid, comid);
                if (projectmodel != null)
                {
                    if (projectmodel.Mobile != "")
                    {
                        phone = projectmodel.Mobile;
                    }
                }


                //从cookie中得到微信号
                if (Request.Cookies["openid"] != null)
                {
                    openid = Request.Cookies["openid"].Value;
                }
                B2bCrmData b2b_crm = new B2bCrmData();
                if (openid != "")
                {
                    B2b_crm b2bmodle = b2b_crm.b2b_crmH5(openid, comid);
                    if (b2bmodle != null)
                    {
                        Imprest  = b2bmodle.Imprest;
                        Integral = b2bmodle.Integral;
                    }
                }
            }


            if (Domain_def.Domain_yanzheng(RequestUrl))//如果符合shop101.etown.cn的格式,则从多微信商户基本信息表中获取comid
            {
                //先通过正则表达式获取COMid
                comid = Int32.Parse(Domain_def.Domain_Huoqu(RequestUrl).ToString());
                if (comid == 0)
                {
                    comid = new WeiXinBasicData().GetWeiXinBasicByDomain(RequestUrl).Comid;
                }
                if (comid != 0)
                {
                    var commodel = B2bCompanyData.GetCompany(comid);

                    if (commodel != null)
                    {
                        if (commodel.B2bcompanyinfo != null)
                        {
                            Wxfocus_url    = commodel.B2bcompanyinfo.Wxfocus_url;
                            Wxfocus_author = commodel.B2bcompanyinfo.Wxfocus_author;
                            weixinname     = commodel.B2bcompanyinfo.Weixinname;
                            Scenic_intro   = commodel.B2bcompanyinfo.Scenic_intro;
                        }

                        title = commodel.Com_name;
                    }


                    B2b_company_saleset pro = B2bCompanySaleSetData.GetDirectSellByComid(comid.ToString());
                    if (pro != null)
                    {
                        comlogo = FileSerivce.GetImgUrl(pro.Smalllogo.ConvertTo <int>(0));
                    }

                    ////获取微信平台端code
                    //string weixincode = Request["code"].ConvertTo<string>("");
                    ////获取微信号和一次性密码
                    //openid = Request["openid"].ConvertTo<string>("");
                    //string weixinpass = Request["weixinpass"].ConvertTo<string>("");

                    ////获得会员信息
                    //GetCrmInfo(weixincode, openid, weixinpass);
                }
            }


            //获取BANNER,及logo
            if (comid != 0)
            {
                //根据公司id得到 直销设置
                B2b_company_saleset saleset = B2bCompanySaleSetData.GetDirectSellByComid(comid.ToString());
                if (saleset != null)
                {
                    logoimg = FileSerivce.GetImgUrl(saleset.Smalllogo.ConvertTo <int>(0));
                }
            }



            //微信转发访问归属渠道
            if (uid != 0)//必须记录转发用户信息才能继续统计
            {
                //判断有转发人的渠道
                var    crmdata       = new B2bCrmData();
                var    pro           = crmdata.Readuser(uid, comid);//读取转发人用户信息
                string zhuanfa_phone = "";
                if (pro != null)
                {
                    zhuanfa_phone = pro.Phone;
                }

                if (zhuanfa_phone != "")
                {                                                                                  //转发人手机存在
                    MemberChannelData channeldata = new MemberChannelData();
                    var channeinfo = channeldata.GetPhoneComIdChannelDetail(zhuanfa_phone, comid); //查询渠道
                    if (channeinfo != null)
                    {
                        //转发人渠道记录COOKI
                        HttpCookie cookie = new HttpCookie("ZF_ChanneId");     //实例化HttpCookie类并添加值
                        cookie.Value   = channeinfo.Id.ToString();
                        cookie.Expires = DateTime.Now.AddDays(120);
                        Response.Cookies.Add(cookie);
                    }
                }
            }
        }
Exemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int orderid = Request["out_trade_no"].ConvertTo <int>(0);
            //根据订单id得到订单信息
            B2bOrderData dataorder     = new B2bOrderData();
            B2b_order    modelb2border = dataorder.GetOrderById(orderid);

            //根据产品id得到产品信息
            B2bComProData datapro     = new B2bComProData();
            B2b_com_pro   modelcompro = datapro.GetProById(modelb2border.Pro_id.ToString());

            if (modelb2border != null)
            {
                //支付宝网关地址
                string GATEWAY_NEW = "http://wappaygw.alipay.com/service/rest.htm?";

                ////////////////////////////////////////////调用授权接口alipay.wap.trade.create.direct获取授权码token////////////////////////////////////////////

                //返回格式
                string format = "xml";
                //必填,不需要修改

                //返回格式
                string v = "2.0";
                //必填,不需要修改

                //请求号
                string req_id = DateTime.Now.ToString("yyyyMMddHHmmss");
                //必填,须保证每次请求都是唯一

                //req_data详细信息

                //服务器异步通知页面路径
                //string notify_url = "";
                string notify_url = "http://" + RequestUrl + "/h5/pay_by/notify_url.aspx";
                //需http://格式的完整路径,不允许加?id=123这类自定义参数

                //页面跳转同步通知页面路径
                //string call_back_url = "http://127.0.0.1:64704/WS_WAP_PAYWAP-CSHARP-UTF-8/call_back_url.aspx";
                string call_back_url = "http://" + RequestUrl + "/h5/pay_by/call_back_url.aspx";
                //需http://格式的完整路径,不允许加?id=123这类自定义参数

                //操作中断返回地址
                //string merchant_url = "http://v.etown.cn";
                string merchant_url = "http://" + RequestUrl + "/h5/Orderlist.aspx";
                //用户付款中途退出返回商户的地址。需http://格式的完整路径,不允许加?id=123这类自定义参数

                //卖家支付宝帐户
                string seller_email = "*****@*****.**";
                //必填

                //商户订单号
                string out_trade_no = modelb2border.Id.ToString();
                //商户网站订单系统中唯一订单号,必填

                //订单名称
                string subject = "";
                if (modelb2border.Order_type == 1)
                {
                    subject = modelcompro.Pro_name;
                }
                if (modelb2border.Order_type == 2)
                {
                    if (modelb2border.serverid == "")
                    {
                        subject = "预付款充值";
                    }
                    else
                    {
                        subject = "购买服务于押金";
                    }
                }
                //必填

                //付款金额
                string total_fee = (modelb2border.Pay_price * modelb2border.U_num + modelb2border.Express - modelb2border.Integral1 - modelb2border.Imprest1).ToString();
                //必填


                if (modelb2border.Child_u_num > 0)//如果是旅游包含儿童的
                {
                    total_fee = (Decimal.Parse(total_fee) + modelb2border.Child_u_num * (modelb2border.Pay_price - modelcompro.Childreduce)).ToString();
                }


                //如果是购物车订单重新写金额
                if (modelb2border.Shopcartid != 0)
                {
                    total_fee = dataorder.GetCartOrderMoneyById(orderid).ToString("0.00");;
                }


                //请求业务参数详细
                string req_dataToken = "<direct_trade_create_req><notify_url>" + notify_url + "</notify_url><call_back_url>" + call_back_url + "</call_back_url><seller_account_name>" + seller_email + "</seller_account_name><out_trade_no>" + out_trade_no + "</out_trade_no><subject>" + subject + "</subject><total_fee>" + total_fee + "</total_fee><merchant_url>" + merchant_url + "</merchant_url></direct_trade_create_req>";
                //必填

                //把请求参数打包成数组
                Dictionary <string, string> sParaTempToken = new Dictionary <string, string>();
                sParaTempToken.Add("partner", Config.Partner);
                sParaTempToken.Add("_input_charset", Config.Input_charset.ToLower());
                sParaTempToken.Add("sec_id", Config.Sign_type.ToUpper());
                sParaTempToken.Add("service", "alipay.wap.trade.create.direct");
                sParaTempToken.Add("format", format);
                sParaTempToken.Add("v", v);
                sParaTempToken.Add("req_id", req_id);
                sParaTempToken.Add("req_data", req_dataToken);

                //建立请求
                string sHtmlTextToken = Submit.BuildRequest(GATEWAY_NEW, sParaTempToken);
                //URLDECODE返回的信息
                Encoding code = Encoding.GetEncoding(Config.Input_charset);
                sHtmlTextToken = HttpUtility.UrlDecode(sHtmlTextToken, code);

                //解析远程模拟提交后返回的信息
                Dictionary <string, string> dicHtmlTextToken = Submit.ParseResponse(sHtmlTextToken);

                //获取token
                string request_token = dicHtmlTextToken["request_token"];

                ////////////////////////////////////////////根据授权码token调用交易接口alipay.wap.auth.authAndExecute////////////////////////////////////////////


                //业务详细
                string req_data = "<auth_and_execute_req><request_token>" + request_token + "</request_token></auth_and_execute_req>";
                //必填

                //把请求参数打包成数组
                Dictionary <string, string> sParaTemp = new Dictionary <string, string>();
                sParaTemp.Add("partner", Config.Partner);
                sParaTemp.Add("_input_charset", Config.Input_charset.ToLower());
                sParaTemp.Add("sec_id", Config.Sign_type.ToUpper());
                sParaTemp.Add("service", "alipay.wap.auth.authAndExecute");
                sParaTemp.Add("format", format);
                sParaTemp.Add("v", v);
                sParaTemp.Add("req_data", req_data);



                //写入支付数据库,先判定是否有此订单支付
                //根据订单id得到订单信息
                B2bPayData datapay    = new B2bPayData();
                B2b_pay    modelb2pay = datapay.GetPayByoId(orderid);


                if (modelb2pay == null)
                {
                    B2b_pay eticket = new B2b_pay()
                    {
                        Id           = 0,
                        Oid          = orderid,
                        Pay_com      = "malipay",
                        Pay_name     = modelb2border.U_name,
                        Pay_phone    = modelb2border.U_phone,
                        Total_fee    = decimal.Parse(total_fee),
                        Trade_no     = "",
                        Trade_status = "trade_pendpay",
                        Uip          = "",
                        comid        = 106
                    };
                    int payid = datapay.InsertOrUpdate(eticket);
                }
                else
                {
                    //对已完成支付的,再次提交支付,跳转到订单也或显示此订单已支付
                    if (modelb2pay.Trade_status != "TRADE_SUCCESS")
                    {
                        //防止金额有所改动
                        modelb2pay.comid     = 106;
                        modelb2pay.Pay_com   = "malipay";
                        modelb2pay.Total_fee = decimal.Parse(total_fee);
                        datapay.InsertOrUpdate(modelb2pay);
                    }
                }



                //建立请求
                string sHtmlText = Submit.BuildRequest(GATEWAY_NEW, sParaTemp, "get", "确认");
                Response.Write(sHtmlText);
            }
        }
Exemplo n.º 4
0
        public string nativePayImgurl = "/Images/defaultThumb.png"; //微信原生支付二维码
        protected void Page_Load(object sender, EventArgs e)
        {
            //返回订单号
            orderid = Request["orderid"].ConvertTo <int>(0);
            #region 正常订单支付操作
            if (orderid != 0)
            {
                string u  = Request.ServerVariables["HTTP_USER_AGENT"];
                bool   bo = detectmobilebrowser.HttpUserAgent(u);
                if (bo)
                {
                    Response.Redirect("/h5/pay.aspx?orderid=" + orderid);
                }
                //根据订单id得到订单信息
                B2bOrderData dataorder     = new B2bOrderData();
                B2b_order    modelb2border = dataorder.GetOrderById(orderid);

                cart = modelb2border.Shopcartid;//不等于0则为购物车订单

                //根据产品id得到产品信息
                B2bComProData datapro     = new B2bComProData();
                B2b_com_pro   modelcompro = datapro.GetProById(modelb2border.Pro_id.ToString(), modelb2border.Speciid);

                if (modelcompro != null)
                {
                    Server_type = modelcompro.Server_type;
                    comid       = modelcompro.Com_id;
                    //绿野 不显示头部
                    if (modelcompro.Com_id == 2553)
                    {
                        viewtop = 0;
                    }
                    string urljson = WeiXinJsonData.getNativePayQrcode(orderid, comid, "oid");
                    try
                    {
                        XmlDocument retdoc  = (XmlDocument)JsonConvert.DeserializeXmlNode("{\"root\":" + urljson + "}");
                        XmlElement  retroot = retdoc.DocumentElement;
                        string      type    = retroot.SelectSingleNode("type").InnerText;
                        string      msg     = retroot.SelectSingleNode("msg").InnerText;

                        nativePayImgurl = "/ui/pmui/eticket/showtcode.aspx?pno=" + msg;
                    }
                    catch
                    { }
                }
                else
                {
                    //产品错误
                }

                //如果订单“未付款”现实支付及订单信息
                if ((int)modelb2border.Order_state == (int)OrderStatus.WaitPay)
                {
                    u_name   = modelb2border.U_name.Substring(0, 1) + "**";
                    u_mobile = modelb2border.U_phone.Substring(0, 4) + "****" + modelb2border.U_phone.Substring(modelb2border.U_phone.Length - 3, 3);

                    ;
                    travel_date  = modelb2border.U_traveldate.ToString();
                    buy_num      = modelb2border.U_num;
                    p_totalprice = CommonFunc.OperTwoDecimal((modelb2border.U_num * modelb2border.Pay_price + modelb2border.Express - modelb2border.Integral1 - modelb2border.Imprest1).ToString());
                    if (modelb2border.Child_u_num > 0)//如果是旅游包含儿童的
                    {
                        p_totalprice = (Decimal.Parse(p_totalprice) + modelb2border.Child_u_num * (modelb2border.Pay_price - modelcompro.Childreduce)).ToString();
                    }

                    ordertype = modelb2border.Order_type;
                    if (ordertype == 2)
                    {
                        proname     = "预付款充值";
                        u_youxiaoqi = "";
                    }
                    else
                    {
                        proname = modelcompro.Pro_name;
                        if (modelcompro.Server_type == 10)
                        {//服务类型是:旅游大巴
                            u_youxiaoqi = modelb2border.U_traveldate.ToString("yyyy-MM-dd");
                        }
                        else
                        {
                            u_youxiaoqi = modelcompro.Pro_start.ToString() + " - " + modelcompro.Pro_end.ToString();
                        }
                    }


                    //如果是购物车订单再次处理
                    if (cart > 0)
                    {
                        proname      = dataorder.GetCartOrderProById(orderid);
                        p_totalprice = dataorder.GetCartOrderMoneyById(orderid).ToString("0.00");
                        buy_num      = 1;
                    }


                    tenpay_url = string.Format("/tenpay/payRequest.aspx?order_no={0}&product_name={1}&order_price={2}&remarkexplain={3}",
                                               orderid, Server.UrlEncode(proname), Server.UrlEncode(p_totalprice), Server.UrlEncode(proname));

                    if (Server_type == 9)
                    {
                        //订房查询入住 及离店日期
                        var hoteldata  = new B2b_order_hotelData();
                        var hotelmodel = hoteldata.GetHotelOrderByOrderId(orderid);

                        if (hotelmodel != null)
                        {
                            stardate = hotelmodel.Start_date.ToString("yyyy-MM-dd");
                            enddate  = hotelmodel.End_date.ToString("yyyy-MM-dd");
                        }
                    }
                }
            }
            #endregion
        }