예제 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Log.Info(this.GetType().ToString(), "page load");
            if (!IsPostBack)
            {
                JsApiPay jsApiPay = new JsApiPay(this);
                try
                {
                    //调用【网页授权获取用户信息】接口获取用户的openid和access_token
                    jsApiPay.GetOpenidAndAccessToken();

                    //获取收货地址js函数入口参数
                    wxEditAddrParam     = jsApiPay.GetEditAddressParameters();
                    ViewState["openid"] = jsApiPay.openid;
                }
                catch (Exception ex)
                {
                    Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面加载出错,请重试" + "</span>");
                    Button1.Visible = false;
                    Button2.Visible = false;
                    Label1.Visible  = false;
                    Label2.Visible  = false;
                }
            }
        }
예제 #2
0
        /// <summary>
        /// wx支付提交请求
        /// </summary>
        /// <param name="clientOpenId"></param>
        /// <param name="totalfell">注意这里单位是 分</param>
        /// <returns></returns>
        public string WXJSApi_SubRequest(string clientOpenId, string orderNumber, string totalfell)
        {
            if (!orderNumber.OrderNumberVerify())
            {
                return "-1";//提交失败 参数异常
            }


            JsApiPay jsApiPay = new JsApiPay();
            jsApiPay.openid = clientOpenId;
            jsApiPay.total_fee = AlipayConfig.MoneyFormatEco(totalfell).ParseInt();
            jsApiPay.orderNumber = orderNumber;
            try
            {
                WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult();
                string wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数                    
                Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam);

                return wxJsApiParam;
            }
            catch (Exception ex)
            {
                return "-2";//提交异常
            }
        }
예제 #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Log.Info(this.GetType().ToString(), "page load");
            if (!IsPostBack)
            {
                JsApiPay jsApiPay = new JsApiPay(this);
                try
                {
                    //调用【网页授权获取用户信息】接口获取用户的openid和access_token
                    jsApiPay.GetOpenidAndAccessToken();

                    //获取收货地址js函数入口参数
                    wxEditAddrParam = jsApiPay.GetEditAddressParameters();
                    ViewState["openid"] = jsApiPay.openid;
                }
                catch (Exception ex)
                {
                    Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面加载出错,请重试" + "</span>");
                    Button1.Visible = false;
                    Button2.Visible = false;
                    Label1.Visible = false;
                    Label2.Visible = false;
                }
            }
        }
예제 #4
0
       /// <summary>
       /// 进行微信授权验证,获取Openid
       /// </summary>
       /// <param name="UrlCode">URL参数</param>
       /// <param name="UrlHost">URL服务地址</param>
       /// <param name="UrlPath">URL路径</param>
       /// <returns></returns>
        public static  string GetOpenidAndAccessToken(string UrlCode,string Url)
        {
            string str="";
            JsApiPay jsApiPay = new JsApiPay();
            try
            {
                //调用【网页授权获取用户信息】接口获取用户的openid和access_token
                jsApiPay.GetOpenidAndAccessToken(UrlCode,Url);
             
                if (string.IsNullOrEmpty(UrlCode))
                {  
                    //如果UrlCode为空,则获取重定向URL 
                    str = jsApiPay.url1;
                }
                else
                { 
                    //如果UrlCode不为空,则解析Code,获取Openid
                    //用户统一下单接口
                    str = jsApiPay.openid;     
                    str +=","+ jsApiPay.access_token;
                }
          
            }
            catch (Exception ex)
            {

            }
            return str;
        }
예제 #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Log.Info(this.GetType().ToString(), "page load");
            if (!IsPostBack)
            {

                JsApiPay jsApiPay = new JsApiPay(this);
                DTO.Business.View_OrderList view_order = GetOrderMess(Request.QueryString["orderid"]);
                DTO.Business.User user = new DTO.Business.User();
                user.UserID = view_order.UserID;
                user = Business.Business.UserBLL.Get(user);
                jsApiPay.openid = user.Openid;
                jsApiPay.total_fee = view_order.OrderPrice * 100;//元转为分
                //jsApiPay.total_fee = view_order.OrderPrice;
                jsApiPay.orderid = view_order.OrderID.ToString();
                jsApiPay.good_name = view_order.RepairName;

                //JSAPI支付预处理
                try
                {
                    WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult();
                    wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数
                    Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam);
                    //在页面上显示订单信息
                    //Response.Write("<span style='color:#00CD00;font-size:20px'>订单详情:</span><br/>");
                    //Response.Write("<span style='color:#00CD00;font-size:20px'>" + unifiedOrderResult.ToPrintStr() + "</span>");

                }
                catch (Exception ex)
                {
                    Response.Write("<span style='color:#FF0000;font-size:20px'>" + "下单失败,请返回重试" + "</span>");
                    //submit.Visible = false;
                }
            }
        }
예제 #6
0
        public static void weixin(string Url)
        {
            JsApiPay jsApiPay = new JsApiPay();
            try
            {
                jsApiPay.weixin(Url);
            }
            catch (Exception ex)
            {

            }
        }
예제 #7
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string   openid    = HttpContext.Current.Request.QueryString["openid"];
            string   total_fee = HttpContext.Current.Request.QueryString["total_fee"];
            JsApiPay jsApiPay  = new JsApiPay(context);

            jsApiPay.openid    = openid;
            jsApiPay.total_fee = int.Parse(total_fee);
            WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult();

            context.Response.Write(jsApiPay.GetJsApiParameters());//获取H5调起JS API参数
        }
예제 #8
0
 protected void Page_Load(object sender, EventArgs e)
 {
     Log.Info(this.GetType().ToString(), "page load");
     if (!IsPostBack)
     {
         JsApiPay jsApiPay = new JsApiPay(this);
         try
         {
             //调用【网页授权获取用户信息】接口获取用户的openid和access_token
             jsApiPay.GetOpenidAndAccessToken();
             ViewState["openid"] = jsApiPay.openid;
             //GetUserOpenId();
         }
         catch (Exception ex)
         {
             Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面加载出错,请重试" + "</span>");
             BtnSave.Visible = false;
         }
     }
 }
예제 #9
0
        }                                               //H5调起JS API参数
        protected void Page_Load(object sender, EventArgs e)
        {
            Log.Info(this.GetType().ToString(), "page load");
            //if (!IsPostBack)
            //{
            string openid    = Request.QueryString["openid"];
            string total_fee = Request.QueryString["total_fee"];
            //检测是否给当前页面传递了相关参数
            //if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(total_fee))
            //{
            //    Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面传参出错,请返回重试" + "</span>");
            //    Log.Error(this.GetType().ToString(), "This page have not get params, cannot be inited, exit...");
            //    submit.Visible = false;
            //    return;
            //}

            //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数
            JsApiPay jsApiPay = new JsApiPay(this);

            jsApiPay.openid    = openid;
            jsApiPay.total_fee = int.Parse(total_fee);

            //JSAPI支付预处理
            //try
            //{
            WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult();

            wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数
            Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam);
            //在页面上显示订单信息
            Response.Write("<span style='color:#00CD00;font-size:20px'>订单详情:</span><br/>");
            Response.Write("<span style='color:#00CD00;font-size:20px'>" + unifiedOrderResult.ToPrintStr() + "</span>");

            //}
            //catch (Exception ex)
            //{
            //    Response.Write("<span style='color:#FF0000;font-size:20px'>" + "下单失败,请返回重试" + "</span><span style='color:#FF0000;font-size:20px'>" + wxJsApiParam + "</span>");
            //    //submit.Visible = false;
            //}
            //}
        }
예제 #10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Log.Info(this.GetType().ToString(), "page load");
            if (!IsPostBack)
            {
                string openid = Request.QueryString["openid"];
                string total_fee = Request.QueryString["total_fee"];
                //检测是否给当前页面传递了相关参数
                if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(total_fee))
                {
                    Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面传参出错,请返回重试" + "</span>");
                    Log.Error(this.GetType().ToString(), "This page have not get params, cannot be inited, exit...");
                    submit.Visible = false;
                    return;
                }

                //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数
                JsApiPay jsApiPay = new JsApiPay(this);
                jsApiPay.openid = openid;
                jsApiPay.total_fee = int.Parse(total_fee);

                //JSAPI支付预处理
                try
                {
                    WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult();
                    wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数
                    Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam);
                    //在页面上显示订单信息
                    Response.Write("<span style='color:#00CD00;font-size:20px'>订单详情:</span><br/>");
                    Response.Write("<span style='color:#00CD00;font-size:20px'>" + unifiedOrderResult.ToPrintStr() + "</span>");

                }
                catch(Exception ex)
                {
                    Response.Write("<span style='color:#FF0000;font-size:20px'>" + "下单失败,请返回重试" + "</span>");
                    submit.Visible = false;
                }
            }
        }
예제 #11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                JsApiPay jsApiPay = new JsApiPay(this);
                try
                {
                    //调用【网页授权获取用户信息】接口获取用户的openid和access_token
                    jsApiPay.appid = appid;
                    jsApiPay.appsecret = "53e3943476118a3dff21fb95848de6d7";
                    jsApiPay.GetOpenidAndAccessToken();

                    //ViewState["openid"] = jsApiPay.openid;
                    Response.Write(jsApiPay.openid);

                    BCBill bill = new BCBill(BCPay.PayChannel.WX_JSAPI.ToString(), 1, BCUtil.GetUUID(), "dotNet自来水");
                    bill.openId = jsApiPay.openid;
                    try
                    {
                        BCBill resultBill = BCPay.BCPayByChannel(bill);
                        timeStamp = resultBill.timestamp;
                        noncestr = resultBill.noncestr;
                        package = resultBill.package;
                        paySign = resultBill.paySign;
                        signType = resultBill.signType;
                    }
                    catch (Exception excption)
                    {
                        Response.Write("<span style='color:#00CD00;font-size:20px'>" + excption.Message + "</span><br/>");
                    }
                }
                catch (Exception ex)
                {
                    Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面加载出错,请重试" + ex.Message + "</span>");
                }
            }
        }
예제 #12
0
        //public WxPayData unifiedOrderResult { get; set; }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            writeFile("coming2");
            string openid           = HttpContext.Current.Request.QueryString["openid"];
            string total_fee        = HttpContext.Current.Request.QueryString["jiage"];
            string goods            = HttpContext.Current.Request.QueryString["wupinglx"];
            string huowuguizhongF   = HttpContext.Current.Request.QueryString["huowuguizhongF"];
            string qujianhao        = HttpContext.Current.Request.QueryString["qujianhao"];
            string huojiahao        = HttpContext.Current.Request.QueryString["huojiahao"];
            string zhongliangleibie = HttpContext.Current.Request.QueryString["zhongliangleibie"];
            string name             = HttpContext.Current.Request.QueryString["shouhuoren"];
            string tel         = HttpContext.Current.Request.QueryString["tel"];
            string kuaididizhi = HttpContext.Current.Request.QueryString["kuaididizhi"];

            JsApiPay jsApiPay = new JsApiPay(context);

            jsApiPay.openid = openid;
            writeFile(jsApiPay.openid);
            jsApiPay.goods = goods;
            writeFile(jsApiPay.goods.ToString());
            jsApiPay.total_fee = int.Parse(total_fee);
            double price = jsApiPay.total_fee / 100.0;


            writeFile(jsApiPay.total_fee.ToString());

            //统一下单
            WxPayData data = new WxPayData();

            data.SetValue("body", goods);
            writeFile(data.GetValue("body").ToString());
            data.SetValue("attach", goods);
            writeFile(data.GetValue("attach").ToString());
            data.SetValue("out_trade_no", WxPayApi.GenerateOutTradeNo());

            string out_trade_no = data.GetValue("out_trade_no").ToString();

            writeFile(data.GetValue("out_trade_no").ToString());
            data.SetValue("total_fee", total_fee);
            writeFile(data.GetValue("total_fee").ToString());
            data.SetValue("time_start", DateTime.Now.ToString("yyyyMMddHHmmss"));
            writeFile(data.GetValue("time_start").ToString());
            data.SetValue("time_expire", DateTime.Now.AddMinutes(10).ToString("yyyyMMddHHmmss"));
            writeFile(data.GetValue("time_expire").ToString());
            data.SetValue("goods_tag", goods);
            writeFile(data.GetValue("goods_tag").ToString());
            data.SetValue("trade_type", "JSAPI");
            writeFile(data.GetValue("trade_type").ToString());
            data.SetValue("openid", openid);
            writeFile(data.GetValue("openid").ToString());
            WxPayData result = UnifiedOrder(data);

            writeFile("over...");
            if (!result.IsSet("appid") || !result.IsSet("prepay_id") || result.GetValue("prepay_id").ToString() == "")
            {
                Log.Error(this.GetType().ToString(), "UnifiedOrder response error!");
                throw new WxPayException("UnifiedOrder response error!");
            }
            writeFile("overing");
            kyfly.BLL.yewu_dingdanxinxiB bll = new kyfly.BLL.yewu_dingdanxinxiB(context);
            string jiedanshijian             = DateTime.Now.Date.ToString();
            string peisongshijian            = DateTime.Now.Date.ToString();
            string xiuzhengshijian           = DateTime.Now.Date.ToString();



            WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(); //此处有问题!

            context.Response.Write(jsApiPay.GetJsApiParameters());           //获取H5调起JS API参数

            bll.Add(name, tel, goods, "", kuaididizhi, "待付款", jiedanshijian, qujianhao, huojiahao, huowuguizhongF, zhongliangleibie, price.ToString(), "", peisongshijian, "", "", xiuzhengshijian, out_trade_no, "", "", "");
        }
예제 #13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Log.Info(this.GetType().ToString(), "page load");
            if (!IsPostBack)
            {
                string body = "恒指天成产品注册码";
                attach = this.Request.QueryString["attach"];
                string openid = Request.QueryString["openid"];
                string total_fee = Request.QueryString["total_fee"];
                //检测是否给当前页面传递了相关参数
                if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(total_fee) || string.IsNullOrEmpty(attach))
                {
                    Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面传参出错,请返回重试" + "</span>");
                    Log.Error(this.GetType().ToString(), "This page have not get params, cannot be inited, exit...");
                    BtnSubmit.Visible = false;
                    return;
                }

                //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数
                JsApiPay jsApiPay = new JsApiPay(this);
                jsApiPay.openid = openid;
                jsApiPay.total_fee = int.Parse(total_fee);

                //JSAPI支付预处理
                try
                {
                    string out_trade_no = String.Format("{0}-{1}-{2:yyyyMMddHHmmsss}", attach, EncryptHelper.XorEncryptStr(attach), DateTime.Now);
                    string ip = Page.Request.UserHostAddress;
                    WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(out_trade_no, body, attach, ip);
                    wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数
                    Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam);
                    //在页面上显示订单信息
                    //Response.Write("<span style='color:#00CD00;font-size:20px'>订单详情:</span><br/>");
                    //Response.Write(String.Format("<span style='color:#00CD00;font-size:20px'>{0}</span>", unifiedOrderResult.ToPrintStr()));

                }
                catch (Exception ex)
                {
                    Response.Write("<span style='color:#FF0000;font-size:20px'>" + "下单失败,请返回重试" + "</span>");
                    BtnSubmit.Visible = false;
                    Response.End();
                }
            }
            /*this.NotifyUrl = PayConfig.NotifyUrl;
            #region 支付操作============================
            #region 基本参数===========================
            TimeStamp = TenpayUtil.getTimestamp();
            NonceStr = TenpayUtil.getNoncestr();
            var packageReqHandler = new RequestHandler(Context);
            packageReqHandler.init();
            //设置package订单参数  具体参数列表请参考官方pdf文档,请勿随意设置
            packageReqHandler.setParameter("body", this.Body); //商品信息 127字符
            packageReqHandler.setParameter("appid", PayConfig.AppId);
            packageReqHandler.setParameter("mch_id", PayConfig.MchId);
            packageReqHandler.setParameter("nonce_str", NonceStr.ToLower());
            packageReqHandler.setParameter("notify_url", PayConfig.NotifyUrl);
            packageReqHandler.setParameter("openid", this.UserOpenId);
            packageReqHandler.setParameter("out_trade_no", this.Attach + "-" + EncryptHelper.XorEncryptStr(this.Attach) + "-" + DateTime.Now.ToString("yyyyMMddHHmmsss")); //商家订单号
            packageReqHandler.setParameter("spbill_create_ip", Page.Request.UserHostAddress); //用户的公网ip,不是商户服务器IP
            packageReqHandler.setParameter("total_fee", this.TotalFee); //商品金额,以分为单位(money * 100).ToString()
            packageReqHandler.setParameter("trade_type", "JSAPI");
            if (!string.IsNullOrEmpty(this.Attach))
                packageReqHandler.setParameter("attach", this.Attach);//自定义参数 127字符 机器号
            #endregion
            #region sign===============================
            Sign = packageReqHandler.CreateMd5Sign("key", PayConfig.AppKey);
            LogUtil.WriteLog("WeiPay sign:" + Sign);
            #endregion

            #region 获取package包======================
            packageReqHandler.setParameter("sign", Sign);

            string data = packageReqHandler.parseXML();
            LogUtil.WriteLog("WeiPay 页面  package(XML):" + data);

            string prepayXml = HttpUtil.Send(data, "https://api.mch.weixin.qq.com/pay/unifiedorder");
            LogUtil.WriteLog("WeiPay 页面  package(Back_XML):" + prepayXml);

            //获取预支付ID
            var xdoc = new XmlDocument();
            xdoc.LoadXml(prepayXml);
            XmlNode xn = xdoc.SelectSingleNode("xml");
            XmlNodeList xnl = xn.ChildNodes;
            if (xnl.Count > 7)
            {
                PrepayId = xnl[7].InnerText;
                Package = string.Format("prepay_id={0}", PrepayId);
                LogUtil.WriteLog("WeiPay 页面  package:" + Package);
            }
            #endregion

            #region 设置支付参数 输出页面  该部分参数请勿随意修改 ==============
            var paySignReqHandler = new RequestHandler(Context);
            paySignReqHandler.setParameter("appId", PayConfig.AppId);
            paySignReqHandler.setParameter("timeStamp", TimeStamp);
            paySignReqHandler.setParameter("nonceStr", NonceStr);
            paySignReqHandler.setParameter("package", Package);
            paySignReqHandler.setParameter("signType", "MD5");
            PaySign = paySignReqHandler.CreateMd5Sign("key", PayConfig.AppKey);

            LogUtil.WriteLog("WeiPay 页面  paySign:" + PaySign);
            #endregion
            #endregion*/
        }
예제 #14
0
 /// <summary>
 /// 调用JSAPI
 /// </summary>
 /// <param name="openid">用户对于公众号唯一标识</param>
 /// <param name="total_fee"></param>
 /// <returns></returns>
 public static JSApi_model JsPay(string openid,string total_fee,string oName)
 {
     JSApi_model model = new JSApi_model();
     string wxJsApiParam = "";
     double money = double.Parse(total_fee);
     int truemoney = (int)(money * 100);
     //检测是否给当前页面传递了相关参数
     if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(total_fee))
     {
         return null;
     }
     //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数
     JsApiPay jsApiPay = new JsApiPay();
     //JSAPI支付预处理
     try
     {
         //进行统一支付认证
         WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(oName,openid, truemoney);
         //获取H5调起JS API参数       
         wxJsApiParam = jsApiPay.GetJsApiParameters(); 
         model = wxJsApiParam.toJsonObject<JSApi_model>();
     }
     catch (Exception ex)
     {
         //Response.Write("<span style='color:#FF0000;font-size:20px'>" + ex + "下单失败,请返回重试" + "</span>");
         //submit.Visible = false;
     }
     return model;
 }