Пример #1
0
        /// <summary>
        /// 及时获得access_token值
        /// access_token是公众号的全局唯一票据,公众号调用各接口时都需使用access_token。正常情况下access_token有效期为7200秒,
        /// 重复获取将导致上次获取的access_token失效。
        /// 每日限额获取access_token.我们将access_token保存到数据库里,间隔时间为20分钟,从微信公众平台获得一次。
        /// </summary>
        /// <returns></returns>
        public string getAccessToken(int wid, out string error)
        {
            string token = "";

            error = "";
            try
            {
                Model.wx_userweixin weixininfo = wBll.GetModel(wid);
                if (weixininfo.AppId == null || weixininfo.AppSecret == null || weixininfo.AppId.Trim().Length <= 0 || weixininfo.AppSecret.Trim().Length <= 0)
                {
                    error = "appId或者AppSecret未填写完全,请在[我的公众帐号]里补全信息!";
                    return("");
                }
                XCWeiXin.Model.wx_property_info wxProperty = new XCWeiXin.Model.wx_property_info();
                //第一次插入微信属性表
                if (!pBll.ExistsWid(wid))
                {
                    var result = Senparc.Weixin.MP.CommonAPIs.CommonApi.GetToken(weixininfo.AppId, weixininfo.AppSecret);
                    token = result.access_token;
                    pBll.AddAccess_Token(wid, token);
                    return(token);
                }

                wxProperty = pBll.GetModelList("iName='access_token' and wid=" + wid)[0];
                TimeSpan chajun       = DateTime.Now - wxProperty.createDate.Value;
                double   chajunSecond = chajun.TotalSeconds;

                if (wxProperty.iContent == null || wxProperty.iContent.Trim() == "" || chajunSecond >= wxProperty.expires_in)
                {  //从微信平台重新获得access_token
                    var result = Senparc.Weixin.MP.CommonAPIs.CommonApi.GetToken(weixininfo.AppId, weixininfo.AppSecret);

                    token = result.access_token;
                    //更新到数据库里
                    wxProperty.iContent   = token;
                    wxProperty.createDate = DateTime.Now;
                    pBll.Update(wxProperty);
                }
                else
                {
                    token = wxProperty.iContent;
                }
            }
            catch (Exception ex)
            {
                error = "获得access_token出错:" + ex.Message;
            }
            return(token);
        }
Пример #2
0
        /// <summary>
        /// 选择某一个微信公众帐号,并且将其保存到session里
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            switch (e.CommandName)
            {
            case "toIndex":
            {
                int wid = int.Parse(e.CommandArgument.ToString());
                Model.wx_userweixin weixin = bll.GetModel(wid);
                if (weixin.wStatus != null && weixin.wStatus == 0)
                {
                    MessageBox.Show(this, "账号已被禁用,无法进入");
                    return;
                }

                if (weixin.endDate != null)
                {
                    if (weixin.endDate < DateTime.Now)
                    {
                        MessageBox.Show(this, "账号已过期,无法进入");
                        return;
                    }
                }

                Session["nowweixin"] = weixin;
                Utils.WriteCookie("nowweixinId", "WeiXinPF", e.CommandArgument.ToString());
                Response.Write("<script>parent.location.href='/admin/index.aspx'</script>");
            }
            break;
            }
        }
Пример #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //OAuth2
            string thisUrl = MyCommFun.getWebSite() + "/weixin/restaurant/index.aspx" + Request.Url.Query;
            var    bll     = new BLL.wx_userweixin();
            int    widInt  = MyCommFun.RequestWid();

            Model.wx_userweixin uWeiXinModel = bll.GetModel(widInt);
            OAuth2BaseProc(uWeiXinModel, "index", thisUrl);


            this.shopid = string.IsNullOrEmpty(WebHelper.GetQueryString("shopid")) ? 0 : int.Parse(WebHelper.GetQueryString("shopid"));
            this.openid = string.IsNullOrEmpty(WebHelper.GetQueryString("openid")) ? "loseopenid" : WebHelper.GetQueryString("openid");
            this.wid    = string.IsNullOrEmpty(WebHelper.GetQueryString("wid")) ? "1" : WebHelper.GetQueryString("wid");
            this.title  = this.GetTitle();

            if (!Page.IsPostBack)
            {
                if (this.shopid == 0)
                {
                    this.hotelName = "无选定商铺";
                }
                else
                {
                    var shopinfo = new BLL.wx_diancai_shopinfo().GetModel(this.shopid);

                    if (shopinfo == null)
                    {
                        return;
                    }
                    this.hotelName = shopinfo.hotelName;
                }
            }
        }
Пример #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int wid = 40;
                BLL.wx_userweixin   wx      = new BLL.wx_userweixin();
                Model.wx_userweixin wxModel = wx.GetModel(wid);

                string url          = Common.MyCommFun.getWebSite();
                string redirect_uri = url + "/api/oauth/weixin/index.aspx";
                string reurl        = XCWeiXin.Common.MyCommFun.RequestParam("reurl");

                string appid = wxModel.AppId;



                WebClient client = new WebClient();
                //   client.Encoding = Encoding.UTF8;
                //    var address = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=" + redirect_uri + "?reurl=" + reurl + "&response_type=code&scope=snsapi_base&state=1#wechat_redirect";
                //   string content = client.DownloadString(address);

                //     string aa="";
                //弹出授权页面(如在不弹出授权页面基础下未获得openid,弹出授权页面,提示用户授权)
                if (Request.QueryString["auth"] != null && Request.QueryString["auth"] != "" && Request.QueryString["auth"] == "1")
                {
                    Response.Redirect("https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=" + redirect_uri + "?reurl=" + reurl + "&response_type=code&scope=snsapi_userinfo&state=" + wid + "#wechat_redirect");
                }
                else
                {
                    //不弹出授权页面
                    Response.Redirect("https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=" + redirect_uri + "?reurl=" + reurl + "&response_type=code&scope=snsapi_base&state=" + wid + "#wechat_redirect");
                }
            }
        }
Пример #5
0
        public void GetOpenId(string code, int wid, string url)
        {
            string openid = string.Empty;

            try
            {
                if (Session["openid"] == null)
                {
                    BLL.wx_userweixin   bll     = new BLL.wx_userweixin();
                    Model.wx_userweixin wxModel = bll.GetModel(wid);
                    openid = OAuth2BaseProc(wxModel, "OpenId", code, url);
                    if (!string.IsNullOrEmpty(openid))
                    {
                        Session["openid"] = openid;
                    }
                }
                Context.Response.Write(AjaxResult.Success(openid).ToCamelString());
            }
            catch (UnAuthException oEx)
            {
                Context.Response.Write(AjaxResult.Error(oEx.RedirectUrl, oEx.Code).ToCamelString());
            }
            catch (Exception ex)
            {
                Context.Response.Write(AjaxResult.Error("获取OpenID失败。").ToCamelString());
            }
        }
Пример #6
0
        override protected void OnInit(EventArgs e)
        {
            base.OnInit(e);
            if (errInitTemplates != "")
            {
                Response.Write(errInitTemplates);
                return;
            }

            //1获得模版基本信息
            BLL.wx_module_templates tBll = new BLL.wx_module_templates();
            templateFileName = tBll.GetTemplatesFileNameByWid("shop", wid);
            if (templateFileName == null || templateFileName.Trim() == "")
            {
                errInitTemplates = "不存在该帐号或者该帐号尚未设置模版!";
                Response.Write(errInitTemplates);
                Response.End();
                return;
            }

            BLL.wx_userweixin   bll     = new BLL.wx_userweixin();
            Model.wx_userweixin wxModel = bll.GetModel(wid);
            string thisUrl = MyCommFun.getTotalUrl();

            OAuth2BaseProc(wxModel, "cart", thisUrl);

            serverPath = MyCommFun.GetRootPath() + "/shop/templates/" + templateFileName + "/category.html";
            ShopTemplateMgr template = new ShopTemplateMgr("/shop/templates/" + templateFileName, serverPath, wid);

            template.tType  = TemplateType.Index;
            template.openid = MyCommFun.RequestOpenid();
            template.OutPutHtml(wid);
        }
Пример #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int    wid     = MyCommFun.RequestWid();
            int    actid   = MyCommFun.RequestInt("aid");
            string thisUrl = MyCommFun.getWebSite() + "/weixin/cashred/index.aspx?wid=" + wid + "&aid=" + actid;

            //授权
            BLL.wx_userweixin   bll          = new BLL.wx_userweixin();
            Model.wx_userweixin uWeiXinModel = bll.GetModel(wid);
            OAuth2BaseProc(uWeiXinModel, "index", thisUrl);
            //授权 end

            BLL.wx_xjhongbao_action actBll = new BLL.wx_xjhongbao_action();
            act = actBll.GetPageHongBaoModel(actid, wid);
            if (act == null)
            {
                litActionRemark.Text = "该时间段没有该活动";
                return;
            }
            //jssdk
            this.Title        = act.act_name;
            fxModel.fxImg     = MyCommFun.getWebSite() + "" + act.share_imgurl;
            fxModel.fxTitle   = act.act_name;
            fxModel.fxContent = act.share_content;
            jssdkInit(uWeiXinModel);
            //jssdk end
            ActionBaseInfo(wid);
        }
Пример #8
0
        private void ShowInfo(int id)
        {
            Model.wx_userweixin model = bll.GetModel(id);
            lblId.Text              = model.id.ToString();
            this.txtwxName.Text     = model.wxName;
            this.txtwxId.Text       = model.wxId;
            this.txtweixinCode.Text = model.weixinCode;
            this.txtImgUrl.Text     = model.headerpic;
            this.txtapiurl.Text     = MyCommFun.getWebSite() + "/api/weixin/api.aspx?apiid=" + model.id;
            this.txtwxToken.Text    = model.wxToken;
            if (model.wStatus != null && model.wStatus == 0)
            {
                this.rblwStatus.SelectedValue = "0";
            }


            this.txtAppId.Text     = model.AppId;
            this.txtAppSecret.Text = model.AppSecret;
            // txtEndTime.Text = model.endDate.Value.ToString("yyyy-MM-dd");
            lblEndDate.Text      = model.endDate.Value.ToString("yyyy-MM-dd");
            lblAddDate.Text      = model.createDate.Value.ToString("yyyy-MM-dd");
            lblEndDate.Font.Bold = true;
            if (model.endDate < DateTime.Now)
            {
                //过期
                lblEndDate.ForeColor = System.Drawing.Color.Red;
                lblEndDate.Text     += "[已过期]";
            }
            else if (model.endDate <= DateTime.Now.AddDays(20))
            {
                //快到期
                TimeSpan ts  = model.endDate.Value - DateTime.Now;
                int      sub = ts.Days;
                lblEndDate.ForeColor = System.Drawing.Color.Red;
                lblEndDate.Text     += " [还有" + sub + "天到期]";
            }
            else
            {
            }

            //代理商信息
            if (agent != null)
            {
                lblremainMony.Text = agent.remainMony.Value.ToString();
                lblagentPrice.Text = agent.agentPrice.Value.ToString();
            }
        }
Пример #9
0
        private void ShowInfo(int id)
        {
            Model.wx_userweixin model = bll.GetModel(id);
            lblId.Text              = model.id.ToString();
            this.txtwxName.Text     = model.wxName;
            this.txtwxId.Text       = model.wxId;
            this.txtweixinCode.Text = model.weixinCode;
            this.txtImgUrl.Text     = model.headerpic;
            this.txtapiurl.Text     = MyCommFun.getWebSite() + "/api/weixin/api.aspx?apiid=" + model.id;
            this.txtwxToken.Text    = model.wxToken;

            this.txtAppId.Text     = model.AppId;
            this.txtAppSecret.Text = model.AppSecret;
            txtEndTime.Text        = model.endDate.Value.ToString("yyyy-MM-dd");
            lblEndDate.Text        = model.endDate.Value.ToString("yyyy-MM-dd");
            lblAddDate.Text        = model.createDate.Value.ToString("yyyy-MM-dd");
        }
Пример #10
0
        private void ShowInfo(int id)
        {
            Model.wx_userweixin model = bll.GetModel(id);
            this.id = model.id;

            this.txtwxName.Text = model.wxName;
            this.txtwxId.Text   = model.wxId;

            this.txtweixinCode.Text = model.weixinCode;

            this.txtImgUrl.Text = model.headerpic;
            //this.txtapiurl.Text = model.apiurl;
            this.txtwxToken.Text = model.wxToken;

            this.txtAppId.Text     = model.AppId;
            this.txtAppSecret.Text = model.AppSecret;
            txtapiurl.Text         = MyCommFun.getWebSite() + "/api/weixin/api.aspx?apiid=" + model.id;
        }
Пример #11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            wid = MyCommFun.RequestInt("wid");
            //授权
            BLL.wx_userweixin   bll     = new BLL.wx_userweixin();
            Model.wx_userweixin wxModel = bll.GetModel(wid);
            string code = MyCommFun.QueryString("code");

            if (code == null || code.Trim() == "")
            {
                string thisUrl = MyCommFun.getTotalUrl();
                string newUrl  = OAuthApi.GetAuthorizeUrl(wxModel.AppId, thisUrl, "fukuan", OAuthScope.snsapi_base);
                Response.Redirect(newUrl);
            }
            else
            {
                var result = OAuthApi.GetAccessToken(wxModel.AppId, wxModel.AppSecret, code);
                openid = result.openid;
            }
            //授权结束
            // logBll.AddLog("【微支付】微信预定", "paypage.aspx Page_Load", " 授权结束openid= " + openid, 1);

            try
            {
                int otid = MyCommFun.RequestInt("orderid");
                otid_str = otid.ToString();
                rpage    = "/api/payment/paypage.aspx?showwxpaytitle=1&paytype=shop&wid=" + wid + "&openid=" + openid + "&orderid=" + otid_str;
                if (code == null || code.Trim() == "" || openid == "" || otid == 0 || wid == 0)
                {
                    return;
                }
                //expireMinute = MyCommFun.RequestInt("expireminute");
                //if (expireMinute == 0)
                //{
                //    expireMinute = 30;
                //}
                //else if (expireMinute == -1)
                //{  //如果为-1,则有限期间为1年
                //    expireMinute = 60 * 12 * 365;
                //}

                BLL.orders   otBll       = new BLL.orders();
                Model.orders orderEntity = otBll.GetModel(otid, wid);
                WXLogs.AddLog("【微支付】微信预定", "paypage.aspx Page_Load", "orderEntity.order_no: " + orderEntity.order_no + "|orderEntity.order_amount:" + orderEntity.order_amount, 1);
                litout_trade_no.Text = orderEntity.order_no;
                litMoney.Text        = orderEntity.order_amount.ToString();
                litDate.Text         = orderEntity.add_time.ToString();
                //WxPayData(orderEntity.order_amount, orderEntity.id.ToString(), orderEntity.order_no, code);//老的接口
                WxPayDataV3(orderEntity.order_amount, orderEntity.id.ToString(), orderEntity.order_no, code);
            }
            catch (Exception ex)
            {
                WXLogs.AddLog("【微支付】微信预定", "paypage.aspx Page_Load", "ex: " + ex.Message, 1);
                //MessageBox.ShowAndRedirect(this, "支付有问题:" + ex.Message, "/shop/index.aspx?wid=" + wid);
            }
        }
Пример #12
0
        private void ShowInfo(int id)
        {
            Model.wx_userweixin model = bll.GetModel(id);
            this.id = model.id;

            this.txtwxName.Text = model.wxName;
            this.txtwxId.Text   = model.wxId;

            this.txtweixinCode.Text = model.weixinCode;

            this.txtImgUrl.Text = model.headerpic;
            //this.txtapiurl.Text = model.apiurl;
            this.txtwxToken.Text = model.wxToken;

            this.txtAppId.Text          = model.AppId;
            this.txtAppSecret.Text      = model.AppSecret;
            txtapiurl.Text              = MyCommFun.getWebSite() + "/api/weixin/api.aspx?apiid=" + model.id;
            this.txtEncodingAESKey.Text = model.extStr;
            rblweixintype.SelectedValue = model.wxType == null ? "3" : model.wxType.Value.ToString();
        }
Пример #13
0
        /// <summary>
        /// 获取用户基本信息
        /// </summary>
        /// <param name="wid"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        protected OAuthUserInfo GetUser(int wid, string state, string code, string targetUrl)
        {
            OAuthUserInfo user = null;

#if DEBUG
            string isTest = MyCommFun.getAppSettingValue("isOAuthTest");

            if (isTest == "1")
            {
                user = new OAuthUserInfo()
                {
                    openid     = "obzTsw4p1nhpl97G1xJwKicDNsiQ",
                    nickname   = "谷巍",
                    sex        = 1,
                    city       = "广州",
                    province   = "广东",
                    country    = "中国",
                    headimgurl = "http://wx.qlogo.cn/mmopen/PiajxSqBRaEJrWO5PQSm2auIaHPNnTPCZAfAwNyXVsUADnVhInAYbkYo70cpvEujyOXBibwAUEGpULiafevgqQ9dg/0",
                };
                return(user);
            }
#endif

            string error;
            var    accessToken = WeiXinPF.WeiXinComm.WeiXinCRMComm.getAccessToken(wid, out error);
            if (string.IsNullOrEmpty(error))
            {
                BLL.wx_userweixin   bll     = new BLL.wx_userweixin();
                Model.wx_userweixin wxModel = bll.GetModel(wid);
                var openId = OAuth2BaseProc(wxModel, state, code, targetUrl);


                var userInfo = UserApi.Info(accessToken, openId);
                if (userInfo != null)
                {
                    user = new OAuthUserInfo()
                    {
                        openid     = userInfo.openid,
                        city       = userInfo.city,
                        country    = userInfo.country,
                        headimgurl = userInfo.headimgurl,
                        nickname   = userInfo.nickname,
                        province   = userInfo.province
                    };
                }
                //user = OAuthApi.GetUserInfo(accessToken, openId);
            }
            else
            {
                throw new Exception(error);
            }
            return(user);
        }
Пример #14
0
        protected void Page_Load(object sender, EventArgs e)
        {
            base.OnInit(e);
            if (errInitTemplates != "")
            {
                Response.Write(errInitTemplates);
                return;
            }


            //1获得模版基本信息
            BLL.wx_module_templates tBll = new BLL.wx_module_templates();
            templateFileName = tBll.GetTemplatesFileNameByWid("shop", wid);
            if (templateFileName == null || templateFileName.Trim() == "")
            {
                errInitTemplates = "不存在该帐号或者该帐号尚未设置模版!";
                Response.Write(errInitTemplates);
                Response.End();
                return;
            }


            //授权

            int orderId = MyCommFun.RequestInt("orderid");

            BLL.wx_userweixin   bll     = new BLL.wx_userweixin();
            Model.wx_userweixin wxModel = bll.GetModel(wid);
            string thisUrl = MyCommFun.getWebSite() + "/shop/order_detail.aspx?wid=" + wid + "&orderid=" + orderId;

            OAuth2BaseProc(wxModel, "order_detail", thisUrl);

            //授权结束



            BLL.wx_shop_user_addr           uAddrBll  = new BLL.wx_shop_user_addr();
            IList <Model.wx_shop_user_addr> uaddrList = uAddrBll.GetOpenidAddr(openid, wid);

            if (uaddrList == null || uaddrList.Count <= 0 || uaddrList[0].id <= 0)
            {
                //该微信用户没有添加地址
                Response.Redirect("/shop/editaddr.aspx?wid=" + wid + "&openid=" + openid + "&frompage=confirmOrder.aspx");
                // MessageBox.ResponseScript(this, "window.location.href =/shop/editaddr.aspx?wid=" + wid + "&openid=" + openid + "&frompage=confirmOrder.aspx");
                return;
            }
            serverPath = MyCommFun.GetRootPath() + "/shop/templates/" + templateFileName + "/order_detail.html";
            ShopTemplateMgr template = new ShopTemplateMgr("/shop/templates/" + templateFileName, serverPath, wid);

            template.tType  = TemplateType.orderDetail;
            template.openid = openid;
            template.OutPutHtml(wid);
        }
Пример #15
0
        public string OrderQuery()
        {
            int    orderId = MyCommFun.RequestInt("orderid");
            int    wid     = MyCommFun.RequestInt("wid");
            string code    = MyCommFun.RequestParam("code");
            string state   = MyCommFun.RequestParam("state");

            BLL.wx_payment_wxpay   wxPayBll    = new BLL.wx_payment_wxpay();
            Model.wx_payment_wxpay paymentInfo = wxPayBll.GetModelByWid(wid);
            BLL.wx_userweixin      wx          = new BLL.wx_userweixin();
            Model.wx_userweixin    wxModel     = wx.GetModel(wid);
            BLL.orders             otBll       = new BLL.orders();
            Model.orders           orderEntity = otBll.GetModel(orderId, wid);
            litout_trade_no = orderEntity.order_no;
            string         nonceStr          = TenPayV3Util.GetNoncestr();
            RequestHandler packageReqHandler = new RequestHandler(null);

            //设置package订单参数
            packageReqHandler.SetParameter("appid", paymentInfo.appId);      //公众账号ID
            packageReqHandler.SetParameter("mch_id", paymentInfo.partnerId); //商户号
            packageReqHandler.SetParameter("transaction_id", "");            //填入微信订单号
            packageReqHandler.SetParameter("out_trade_no", litout_trade_no); //填入商家订单号
            packageReqHandler.SetParameter("nonce_str", nonceStr);           //随机字符串
            string sign = packageReqHandler.CreateMd5Sign("key", paymentInfo.paySignKey);

            packageReqHandler.SetParameter("sign", sign);                           //签名

            string data = packageReqHandler.ParseXML();

            var result = TenPayV3.OrderQuery(data);
            var res    = XDocument.Parse(result);

            openid = res.Element("xml").Element("sign").Value;
            string transaction_id = res.Element("xml").Element("sign").Value;

            openids   = res.Element("xml").Element("openid").Value;
            bank_type = res.Element("xml").Element("bank_type").Value;
            if (bank_type == "CNY")
            {
                bank_type = "钱包零钱";
            }
            if (bank_type == "CFT")
            {
                bank_type = "银行卡";
            }
            total_fee      = res.Element("xml").Element("total_fee").Value;
            time_end       = res.Element("xml").Element("time_end").Value;
            out_trade_no   = res.Element("xml").Element("out_trade_no").Value;
            transaction_id = res.Element("xml").Element("transaction_id").Value;
            result_code    = res.Element("xml").Element("result_code").Value;

            return(openid);
        }
Пример #16
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var thisUrl      = MyCommFun.getWebSite() + "/weixin/WeChatPay/getopenId.aspx" + Request.Url.Query;
            var widInt       = MyCommFun.RequestWid();
            var bll          = new BLL.wx_userweixin();
            var uWeiXinModel = bll.GetModel(widInt);

            if (uWeiXinModel == null)
            {
                throw new Exception("不合法的参数wid");
            }
            OAuth2BaseProc(uWeiXinModel, "MyOrderCenter", thisUrl);
        }
Пример #17
0
        public void GetCouponList(string code, int wid, string url)
        {
            string openid = string.Empty;

            try
            {
                var service = new CouponService();

                if (Session["openid"] == null)
                {
                    BLL.wx_userweixin   bll     = new BLL.wx_userweixin();
                    Model.wx_userweixin wxModel = bll.GetModel(wid);
                    openid = OAuth2BaseProc(wxModel, "coupon", code, url);
                    if (!string.IsNullOrEmpty(openid))
                    {
                        Session["openid"] = openid;
                    }
                }
                else
                {
                    openid = Session["openid"] as string;
                }
                CouponListDTO dto = service.GetCouponList(wid, openid);
                if (dto != null)
                {
                    var data = new
                    {
                        lists  = dto,
                        openid = openid
                    };
                    Context.Response.Write(AjaxResult.Success(data));
                }
                else
                {
                    throw new Exception("参数异常");
                }
            }
            catch (UnAuthException jsEx)
            {
                Context.Response.Write(AjaxResult.Error(jsEx.RedirectUrl, jsEx.Code));
            }
            catch (Exception ex)
            {
                var s = "";
                if (ex.InnerException != null)
                {
                    s = ex.InnerException.Message;
                }
                Context.Response.Write(AjaxResult.Error(s));
            }
        }
Пример #18
0
        override protected void OnInit(EventArgs e)
        {
            base.OnInit(e);
            if (errInitTemplates != "")
            {
                Response.Write(errInitTemplates);
                return;
            }

            //1获得模版基本信息
            BLL.wx_module_templates tBll = new BLL.wx_module_templates();
            templateFileName = tBll.GetTemplatesFileNameByWid("shop", wid);
            if (templateFileName == null || templateFileName.Trim() == "")
            {
                errInitTemplates = "不存在该帐号或者该帐号尚未设置模版!";
                Response.Write(errInitTemplates);
                Response.End();
                return;
            }

            //授权
            BLL.wx_userweixin   bll     = new BLL.wx_userweixin();
            Model.wx_userweixin wxModel = bll.GetModel(wid);
            //string openid = "";
            //string code = MyCommFun.QueryString("code");
            //if (code == null || code.Trim() == "")
            //{
            //    string thisUrl = MyCommFun.getWebSite() + "/shop/cart.aspx?wid=" + wid;
            //    string newUrl = OAuthApi.GetAuthorizeUrl(wxModel.AppId, thisUrl, "reg", OAuthScope.snsapi_base);
            //    Response.Redirect(newUrl);
            //}
            //else
            //{
            //    var result = OAuthApi.GetAccessToken(wxModel.AppId, wxModel.AppSecret, code);
            //    openid = result.openid;
            //}

            string thisUrl = MyCommFun.getWebSite() + "/shop/cart.aspx?wid=" + wid;

            OAuth2BaseProc(wxModel, "cart", thisUrl);
            //授权结束


            serverPath = MyCommFun.GetRootPath() + "/shop/templates/" + templateFileName + "/cart.html";
            ShopTemplateMgr template = new ShopTemplateMgr("/shop/templates/" + templateFileName, serverPath, wid);

            template.tType  = TemplateType.Cart;
            template.openid = openid;
            template.OutPutHtml(wid);
        }
Пример #19
0
 /// <summary>
 /// 选择某一个微信公众帐号,并且将其保存到session里
 /// </summary>
 /// <param name="source"></param>
 /// <param name="e"></param>
 protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e)
 {
     switch (e.CommandName)
     {
     case "toIndex":
     {
         int wid = int.Parse(e.CommandArgument.ToString());
         Model.wx_userweixin weixin = bll.GetModel(wid);
         Session["nowweixin"] = weixin;
         Utils.WriteCookie("nowweixinId", "XCWeiXin", e.CommandArgument.ToString());
         Response.Write("<script>parent.location.href='/admin/index.aspx'</script>");
     }
     break;
     }
 }
Пример #20
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //OAuth2认证
            string thisUrl = MyCommFun.getWebSite() + "/weixin/restaurant/diancai_shoppingCart.aspx" + Request.Url.Query;
            int    widInt  = MyCommFun.RequestWid();
            var    bll     = new BLL.wx_userweixin();

            Model.wx_userweixin uWeiXinModel = bll.GetModel(widInt);
            OAuth2BaseProc(uWeiXinModel, "index", thisUrl);

            if (!Page.IsPostBack)
            {
                BindFormControl();
            }
        }
Пример #21
0
        public string stoce()
        {
            Model.wx_userweixin weixin = GetWeiXinCode();
            int wid = weixin.id;

            Model.wx_userweixin model = bll.GetModel(wid);
            string _appId             = model.AppId;
            string _appSecret         = model.AppSecret;

            normalReturn = new AccessTokenResult();
            normalReturn = CommonApi.GetToken(_appId, _appSecret);
            string sctokn = normalReturn.access_token;


            return(sctokn);
        }
Пример #22
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int wid = 43;

            BLL.wx_userweixin   wx      = new BLL.wx_userweixin();
            Model.wx_userweixin wxModel = wx.GetModel(wid);

            int hc = this.GetHashCode();


            var returnUrl = MyCommFun.getWebSite() + "/api/oauth/Weixin_oauth/Info.aspx?wid=" + wid + "";
            var state     = string.Format("{0}|{1}", "zql", hc);
            var url       = OAuthApi.GetAuthorizeUrl(wxModel.AppId, returnUrl, state, OAuthScope.snsapi_userinfo);

            Response.Redirect(url);
        }
Пример #23
0
        protected void Page_Load(object sender, EventArgs e)
        {
#if  DEBUG
            openid = "obzTsw5qxlbwGYYZJC9b-91J-X1Y";
#else
            var thisUrl      = MyCommFun.getWebSite() + "/weixin/WeChatPay/MyOrderCenter.aspx" + Request.Url.Query;
            var widInt       = MyCommFun.RequestWid();
            var bll          = new BLL.wx_userweixin();
            var uWeiXinModel = bll.GetModel(widInt);
            if (uWeiXinModel == null)
            {
                throw new Exception("不合法的参数wid");
            }
            OAuth2BaseProc(uWeiXinModel, "MyOrderCenter", thisUrl);
#endif
        }
Пример #24
0
        private void ShowInfo(int _id)
        {
            Model.wx_userweixin weixin = GetWeiXinCode();
            BLL.payment         bll    = new BLL.payment();
            model         = bll.GetModel(_id);
            txtTitle.Text = model.title;

            if (model.is_lock == 0)
            {
                cbIsLock.Checked = true;
            }
            else
            {
                cbIsLock.Checked = false;
            }
            txtSortId.Text = model.sort_id.ToString();
            rblPoundageType.SelectedValue = model.poundage_type.ToString();
            txtPoundageAmount.Text        = model.poundage_amount.ToString();
            txtImgUrl.Text = model.img_url;
            txtRemark.Text = model.remark;
            if (model.pTypeId == 2)
            {
                //支付宝
                Model.wx_payment_alipay alipay = aliBll.GetModelList("wid=" + weixin.id)[0];
                txtAlipaySellerEmail.Text = alipay.ownerName;
                txtAlipayPartner.Text     = alipay.partner;
                txtAlipayKey.Text         = alipay.e_key;
                txtprivate_key.Text       = alipay.private_key;
                txtpublic_key.Text        = alipay.public_key;
                hidPayId.Value            = alipay.id.ToString();
            }
            else if (model.pTypeId == 3)
            {
                //微信支付
                Model.wx_payment_wxpay wxpay = wxBll.GetModelByWid(weixin.id);
                txtpaySignKey.Text         = wxpay.paySignKey;
                txtTenpayPartnerId.Text    = wxpay.partnerId;
                txtTenpayKey.Text          = wxpay.partnerKey;
                hidPayId.Value             = wxpay.id.ToString();
                rblQuicklyFH.SelectedValue = wxpay.quicklyFH.ToString().ToLower() == "true" ? "1" : "0";
                BLL.wx_userweixin   uwBll    = new BLL.wx_userweixin();
                Model.wx_userweixin uwEneity = uwBll.GetModel(weixin.id);

                lblAppId.Text = uwEneity.AppId;
            }
        }
Пример #25
0
        override protected void OnInit(EventArgs e)
        {
            base.OnInit(e);
            if (errInitTemplates != "")
            {
                Response.Write(errInitTemplates);
                return;
            }

            //1获得模版基本信息04e11d01b9df2865
            BLL.wx_module_templates tBll = new BLL.wx_module_templates();
            templateFileName = tBll.GetTemplatesFileNameByWid("shop", wid);
            if (templateFileName == null || templateFileName.Trim() == "")
            {
                errInitTemplates = "不存在该帐号或者该帐号尚未设置模版!";
                Response.Write(errInitTemplates);
                Response.End();
                return;
            }

            //授权
            BLL.wx_userweixin   bll     = new BLL.wx_userweixin();
            Model.wx_userweixin wxModel = bll.GetModel(wid);

            string type = MyCommFun.QueryString("type");

            if (type != "")
            {
                type = "&type=new";
            }

            string thisUrl = MyCommFun.getWebSite() + "/shop/list.aspx?wid=" + wid + "&cid=" + MyCommFun.RequestInt("cid") + type;

            OAuth2BaseProc(wxModel, "list", thisUrl);
            //授权结束


            serverPath = MyCommFun.GetRootPath() + "/shop/templates/" + templateFileName + "/list.html";
            ShopTemplateMgr template = new ShopTemplateMgr("/shop/templates/" + templateFileName, serverPath, wid);

            template.tType  = TemplateType.Class;
            template.openid = openid;
            template.OutPutHtml(wid);
            DataSet ds = new DataSet();
        }
Пример #26
0
        void showInfo()
        {
            BLL.wx_wq_fuhuiSys fhBll = new BLL.wx_wq_fuhuiSys();
            BLL.article        aBll  = new BLL.article();
            BLL.wx_userweixin  uw    = new BLL.wx_userweixin();
            this.Title = uw.GetModel(wid).wxName;

            //首页幻灯片
            this.imgList.DataSource = aBll.GetList(10, " wid=" + wid, "id asc,add_time asc");
            this.imgList.DataBind();
            this.rptDian.DataSource = aBll.GetList(10, " wid=" + wid, "id asc,add_time asc");
            this.rptDian.DataBind();

            fhModel = fhBll.GetModelList("wid=" + wid)[0];
            StringBuilder sb     = new StringBuilder();
            string        canshu = "?wid=" + wid + "&openid=" + openid;

            //经销车型
            string jxcxUrl = fhModel.jscxurl == "" ? "ppList.aspx" + canshu : fhModel.jscxurl + canshu;

            sb.Append("<li><a href=\"" + jxcxUrl + "\" style=\"background-image: url(" + fhModel.jscxpic + ");" + "background-size: 100% 100%;\"><label>" + fhModel.jscx + "</label></a></li>");

            //销售顾问
            string xsgwUrl = fhModel.xsgwurl == "" ? "xiaoshouMgr.aspx" + canshu : fhModel.xsgw + canshu;

            sb.Append("<li><a href=\"" + xsgwUrl + "\" style=\"background-image: url(" + fhModel.xsgwpic + ");" + "background-size: 100% 100%;\"><label>" + fhModel.xsgw + "</label></a></li>");

            //在线预约
            string zxyyUrl = fhModel.zxyyurl == "" ? "yyBaoyang.aspx" + canshu + "&type=2" : fhModel.zxyy + canshu + "&type=2";

            sb.Append("<li><a href=\"" + zxyyUrl + "\" style=\"background-image: url(" + fhModel.zxyypic + ");" + "background-size: 100% 100%;\"><label>" + fhModel.zxyy + "</label></a></li>");

            //车主关怀
            string czghUrl = fhModel.czghurl == "" ? "czGuanhuai.aspx" + canshu : fhModel.czgh + canshu;

            sb.Append("<li><a href=\"" + czghUrl + "\" style=\"background-image: url(" + fhModel.czghpic + ");" + "background-size: 100% 100%;\"><label>" + fhModel.czgh + "</label></a></li>");

            //实用工具
            string sygjUrl = fhModel.sygjurl == "" ? "syGongju.aspx" + canshu : fhModel.sygj + canshu;

            sb.Append("<li><a href=\"" + sygjUrl + "\" style=\"background-image: url(" + fhModel.sygjpic + ");" + "background-size: 100% 100%;\"><label>" + fhModel.sygj + "</label></a></li>");


            this.litMenu.Text = sb.ToString();
        }
Пример #27
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int wid = MyCommFun.RequestInt("wid");

            BLL.wx_userweixin   wx      = new BLL.wx_userweixin();
            Model.wx_userweixin wxModel = wx.GetModel(wid);

            if (string.IsNullOrEmpty(code))
            {
                Response.Write("您拒绝了授权!");
                return;
            }

            if (!state.Contains("|"))
            {
                //这里的state其实是会暴露给客户端的,验证能力很弱,这里只是演示一下
                //实际上可以存任何想传递的数据,比如用户ID,并且需要结合例如下面的Session["OAuthAccessToken"]进行验证
                Response.Write("验证失败!请从正规途径进入!1001");
                return;
            }
            var openIdResult = OAuthApi.GetAccessToken(wxModel.AppId, wxModel.AppSecret, code);

            if (openIdResult.errcode != ReturnCode.请求成功)
            {
                Response.Write("错误:" + openIdResult.errmsg);
                return;
            }
            else
            {
                var result = OAuthApi.GetUserInfo(openIdResult.access_token, openIdResult.openid);
                name                   = result.nickname;
                image                  = result.headimgurl;
                Session["name"]        = name;
                Session["imageheader"] = image;
                HttpCookie cookie = new HttpCookie("open_id1");
                cookie.Value   = result.openid;
                cookie.Expires = DateTime.Now.AddDays(3650);
                HttpContext.Current.Response.Cookies.Add(cookie);

                Response.Redirect("/hugongll/index.aspx?open_ids=" + result.openid + "");
            }
        }
Пример #28
0
        public void WeChatConfigInit(int wid, string url)
        {
            try
            {
                //获取当前对象实体
                BLL.wx_userweixin   bll          = new BLL.wx_userweixin();
                Model.wx_userweixin uWeiXinModel = bll.GetModel(wid);

                //初始话jsskd
                var signatureDto = jssdkInit(uWeiXinModel, url);
                Context.Response.Write(AjaxResult.Success(signatureDto));
            }
            catch (Exception ex)
            {
                var s = "";
                if (ex.InnerException != null)
                {
                    s = ex.InnerException.Message;
                }
                Context.Response.Write(AjaxResult.Error(s));
            }
        }
Пример #29
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int wid = MyCommFun.RequestInt("wid");

            BLL.wx_userweixin   wx      = new BLL.wx_userweixin();
            Model.wx_userweixin wxModel = wx.GetModel(wid);

            if (string.IsNullOrEmpty(code))
            {
                Response.Write("您拒绝了授权!");
                return;
            }

            if (!state.Contains("|"))
            {
                //这里的state其实是会暴露给客户端的,验证能力很弱,这里只是演示一下
                //实际上可以存任何想传递的数据,比如用户ID,并且需要结合例如下面的Session["OAuthAccessToken"]进行验证
                Response.Write("验证失败!请从正规途径进入!1001");
                return;
            }
            var openIdResult = OAuthApi.GetAccessToken(wxModel.AppId, wxModel.AppSecret, code);

            if (openIdResult.errcode != ReturnCode.请求成功)
            {
                Response.Write("错误:" + openIdResult.errmsg);
                return;
            }
            else
            {
                var result = OAuthApi.GetUserInfo(openIdResult.access_token, openIdResult.openid);
                name                   = result.nickname;
                image                  = result.headimgurl;
                Session["name"]        = name;
                Session["imageheader"] = image;
                openid                 = result.openid;
                SendTemplateMessageTest();
            }
        }
Пример #30
0
        protected void Page_Load(object sender, EventArgs e)
        {
//            hotelid = MyCommFun.RequestInt("hotelid");
            openid = MyCommFun.QueryString("openid");
            roomid = MyCommFun.RequestInt("roomid");
            wid    = MyCommFun.RequestInt("wid");
            if (!string.IsNullOrEmpty(MyCommFun.QueryString("type")))
            {
                type = MyCommFun.QueryString("type");
            }
            var userbll = new BLL.wx_userweixin();

            Model.wx_userweixin uWeiXinModel = userbll.GetModel(wid);
            OAuth2BaseProc(uWeiXinModel, "hotel_userOrder", Request.Url.AbsoluteUri);

            if (!Page.IsPostBack)
            {
                menuStr = GetMenuStr(openid, wid, type);
                BLL.wx_hotels_info   infobll = new BLL.wx_hotels_info();
                Model.wx_hotels_info info    = new Model.wx_hotels_info();



                BLL.wx_hotel_dingdan dingdanbll = new BLL.wx_hotel_dingdan();
                DataSet dr = dingdanbll.GetUserOrderList(openid, wid, type);
                if (dr.Tables[0].Rows.Count > 0)
                {
                    numdingdan = dr.Tables[0].Rows.Count;
                }
                else
                {
                    numdingdan = 0;
                }


                List(openid, wid);
            }
        }
Пример #31
0
 public bool IsWeiXinCode()
 {
     //如果Session为Null
     if (Session["nowweixin"] != null)
     {
         return true;
     }
     else
     {
         //检查Cookies
         string uweixinId = Utils.GetCookie("nowweixinId", "MxWeiXinPF");
         if (uweixinId != "")
         {
             BLL.wx_userweixin bll = new BLL.wx_userweixin();
             Model.wx_userweixin model = bll.GetModel(int.Parse(uweixinId));
             if (model != null)
             {
                 Session["nowweixin"] = model;
                 return true;
             }
         }
     }
     return false;
 }