예제 #1
0
        /// <summary>
        /// 获取code
        /// </summary>
        private void GetOAuthCode()
        {
            try
            {
                //判断客户ID是否传递
                if (!string.IsNullOrEmpty(Request["customerId"]))
                {
                    customerId = Request["customerId"];
                }
                if (!string.IsNullOrEmpty(Request["applicationId"]))
                {
                    applicationId = Request["applicationId"];
                }
                else
                {
                    loggingSessionInfo = Default.GetBSLoggingSession(customerId, "1");
                    var list = new WApplicationInterfaceBLL(loggingSessionInfo).QueryByEntity(new WApplicationInterfaceEntity {
                        CustomerId = customerId
                    }, null).ToList();

                    if (list != null && list.Count > 0)
                    {
                        applicationId = list.FirstOrDefault().ApplicationId;
                    }
                    else
                    {
                        Response.Write("<br>");
                        Response.Write("没有获取微信标识,请联系管理员尽快处理.");
                        Response.End();
                    }
                }
                strState = customerId + "," + amount;
                strState = HttpUtility.UrlEncode(strState, Encoding.UTF8);
                byte[] buff = Encoding.UTF8.GetBytes(strState);
                strState = Convert.ToBase64String(buff);
                //strState = CommonCompress.StringCompress(strState);
                Loggers.Debug(new DebugLogInfo()
                {
                    Message = string.Format("strState1: {0}", strState)
                });
                string url = "http://open.weixin.qq.com/connect/oauth2/authorize?appid=" + strAppId + "&redirect_uri=" + HttpUtility.UrlEncode(strRedirectUri) + "&response_type=code&scope=snsapi_base&state=" + strState + "#wechat_redirect";
                //Response.Write(url);
                Response.Redirect(url);
            }
            catch (Exception ex)
            {
                Loggers.Debug(new DebugLogInfo()
                {
                    Message = string.Format("GetOAuthCode 出错: {0}", ex.ToString())
                });
            }
        }
예제 #2
0
        protected override ShortUrlRD ProcessRequest(APIRequest <ShortUrlRP> pRequest)
        {
            ShortUrlRD rd   = new ShortUrlRD();
            var        para = pRequest.Parameters;

            var list = new WApplicationInterfaceBLL(CurrentUserInfo).QueryByEntity(new WApplicationInterfaceEntity {
                CustomerId = CurrentUserInfo.ClientID, IsDelete = 0
            }, null).ToList();

            if (list == null)
            {
                throw new Exception("该商户没有绑定微信公众号,无法生成商品二维码");
            }
            var wapentity = list.FirstOrDefault();            //获取公众号信息

            JIT.CPOS.BS.BLL.WX.CommonBLL commonServer = new JIT.CPOS.BS.BLL.WX.CommonBLL();
            var shorturl = commonServer.GetShorturl(wapentity.AppID.ToString().Trim()
                                                    , wapentity.AppSecret.Trim()
                                                    , para.Url
                                                    , CurrentUserInfo);

            rd.ShortUrl = shorturl;
            return(rd);
        }
예제 #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Write("进入认证界面<br/>");
            if (!IsPostBack)
            {
                Random rad  = new Random();
                int    iRad = rad.Next(1000, 100000);
                if (!string.IsNullOrEmpty(Request["state"]))
                {
                    #region state不为空
                    string state = Request["state"];
                    //Response.Write("state:" + state);
                    try
                    {
                        #region 参数拼成
                        Loggers.Debug(new DebugLogInfo()
                        {
                            Message = string.Format("strState2: {0}", state)
                        });
                        //byte[] buff1 = Convert.FromBase64String(state);
                        //state = Encoding.UTF8.GetString(buff1);
                        //state = HttpUtility.UrlDecode(state, Encoding.UTF8);
                        //string[] array = state.Split(',');
                        //customerId = array[0];
                        //applicationId = array[1];
                        //goUrl = array[2];
                        //goUrl = goUrlTemp + goUrl;

                        byte[] buff1 = Convert.FromBase64String(state);
                        state = Encoding.UTF8.GetString(buff1);
                        state = HttpUtility.UrlDecode(state, Encoding.UTF8);
                        string[] array = state.Split(',');
                        customerId    = array[1];
                        applicationId = array[2];
                        goUrl         = array[0];
                        #endregion
                    }
                    catch (Exception ex)
                    {
                        Response.Write("<br/>");
                        Response.Write("state错误:" + ex.ToString());
                    }
                    #endregion
                }
                else
                {
                    #region 参数
                    //判断客户ID是否传递
                    if (!string.IsNullOrEmpty(Request["customerId"]))
                    {
                        customerId = Request["customerId"];
                    }
                    else
                    {
                        Response.Write("<br>");
                        Response.Write("没有获取客户标识");
                    }

                    if (!string.IsNullOrEmpty(Request["applicationId"]))
                    {
                        applicationId = Request["applicationId"];
                    }
                    else
                    {
                        loggingSessionInfo = Default.GetBSLoggingSession(customerId, "1");
                        var list = new WApplicationInterfaceBLL(loggingSessionInfo).QueryByEntity(new WApplicationInterfaceEntity {
                            CustomerId = customerId
                        }, null).ToList();

                        if (list != null && list.Count > 0)
                        {
                            applicationId = list.FirstOrDefault().ApplicationId;
                        }
                        else
                        {
                            Response.Write("<br>");
                            Response.Write("没有获取微信标识,请联系管理员尽快处理.");
                            Response.End();
                        }
                    }

                    if (!string.IsNullOrEmpty(Request["goUrl"]))
                    {
                        goUrl = Request["goUrl"];
                        Response.Write("<br>");
                        Response.Write("goUrl:" + goUrl);
                        string eventId = Request["eventId"];
                        if (eventId != null && !eventId.Equals(""))
                        {
                            if (goUrl.IndexOf("?") > 0)
                            {
                                goUrl = goUrl + "&eventId=" + eventId + "";
                            }
                            else
                            {
                                goUrl = goUrl + "?eventId=" + eventId + "";
                            }
                        }
                        //Response.End();
                    }
                    else
                    {
                        Response.Write("<br>");
                        Response.Write("没有获取goUrl");
                        Response.End();
                    }
                    #endregion
                }
                Response.Write("<br>");
                Response.Write("goUrl:" + goUrl);
                //Response.End();
                loggingSessionInfo = Default.GetBSLoggingSession(customerId, "1");

                //Get keys about Wechat
                GetKey();

                string code = Request["code"];
                if (code == null || code.Equals(""))
                {
                    //strState = customerId + "," + applicationId + "," + goUrl; //
                    //strState = HttpUtility.UrlEncode(strState, Encoding.UTF8);
                    //byte[] buff = Encoding.UTF8.GetBytes(strState);
                    //strState = Convert.ToBase64String(buff);

                    strState = goUrl + "," + customerId + "," + applicationId; //
                    strState = HttpUtility.UrlEncode(strState, Encoding.UTF8);
                    byte[] buff = Encoding.UTF8.GetBytes(strState);
                    strState = Convert.ToBase64String(buff);

                    authBll.GetOAuthCode(strAppId, strRedirectUri, strState, this.Response);
                }
                else
                {
                    Response.Write("存在code:" + code);
                    string token  = "";
                    string openId = authBll.GetAccessToken(code, strAppId, strAppSecret, loggingSessionInfo, iRad, out token);
                    Response.Write("<br>");
                    Response.Write("OpenID:" + openId);
                    PageRedict(openId);
                }
            }
        }
예제 #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //Response.Write("进入认证界面<br/>");
            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request["state"]))
                {
                    string state = Request["state"];
                    //Response.Write("state:" + state);
                    try
                    {
                        Loggers.Debug(new DebugLogInfo()
                        {
                            Message = string.Format("strState2: {0}", state)
                        });
                        //state = ((((state).Replace("sb", ".")).Replace("555", "/")).Replace("666", ":")).Replace("sss",",");
                        //string[] array = state.Split(',');
                        //customerId = array[1];
                        //applicationId = array[2];
                        //goUrl = array[0];

                        byte[] buff1 = Convert.FromBase64String(state);
                        state = Encoding.UTF8.GetString(buff1);
                        state = HttpUtility.UrlDecode(state, Encoding.UTF8);
                        string[] array = state.Split(',');
                        customerId    = array[1];
                        applicationId = array[2];
                        goUrl         = array[0];
                        Loggers.Debug(new DebugLogInfo()
                        {
                            Message = string.Format("认证之后的goUrl: goUrl = {0}", goUrl)
                        });
                    }
                    catch (Exception ex)
                    {
                        Response.Write("<br/>");
                        Response.Write("state错误:请联系管理员尽快处理." + ex.ToString());
                    }
                }
                else
                {
                    //判断客户ID是否传递
                    if (!string.IsNullOrEmpty(Request["customerId"]))
                    {
                        customerId = Request["customerId"];
                    }
                    else
                    {
                        Response.Write("<br>");
                        Response.Write("没有获取客户标识,请联系管理员尽快处理.");
                    }
                    if (!string.IsNullOrEmpty(Request["applicationId"]))
                    {
                        applicationId = Request["applicationId"];
                    }
                    else
                    {
                        loggingSessionInfo = Default.GetBSLoggingSession(customerId, "1");
                        var list = new WApplicationInterfaceBLL(loggingSessionInfo).QueryByEntity(new WApplicationInterfaceEntity {
                            CustomerId = customerId
                        }, null).ToList();

                        if (list != null && list.Count > 0)
                        {
                            applicationId = list.FirstOrDefault().ApplicationId;
                        }
                        else
                        {
                            Response.Write("<br>");
                            Response.Write("没有获取微信标识,请联系管理员尽快处理.");
                        }
                    }
                    if (!string.IsNullOrEmpty(Request["goUrl"]))
                    {
                        goUrl = Request["goUrl"];
                        string eventId = Request["eventId"];
                        if (eventId != null && !eventId.Equals(""))
                        {
                            if (goUrl.IndexOf("?") > 0)
                            {
                                goUrl = goUrl + "&eventId=" + eventId + "";
                            }
                            else
                            {
                                goUrl = goUrl + "?eventId=" + eventId + "";
                            }
                        }
                        Response.Write("<br>");
                        Response.Write("goUrl:" + goUrl);
                        //Response.End();
                        Loggers.Debug(new DebugLogInfo()
                        {
                            Message = string.Format("认证之前的goUrl: goUrl = {0}", goUrl)
                        });
                    }
                    else
                    {
                        Response.Write("<br>");
                        Response.Write("没有获取goUrl,请联系管理员尽快处理.");
                        Response.End();
                    }
                }
                Response.Write("<br>");
                Response.Write("goUrl:" + goUrl);
                //Response.End();
                loggingSessionInfo = Default.GetBSLoggingSession(customerId, "1");

                GetKeyByApp();
                string code = Request["code"];
                if (code == null || code.Equals(""))
                {
                    strState = goUrl + "," + customerId + "," + applicationId; //
                    strState = HttpUtility.UrlEncode(strState, Encoding.UTF8);
                    byte[] buff = Encoding.UTF8.GetBytes(strState);
                    strState = Convert.ToBase64String(buff);

                    GetOAuthCode(strState);
                }
                else
                {
                    //Response.Write("存在code:" + code);
                    GetAccessToken(code);
                }
            }
        }
예제 #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Write("进入认证界面<br/>");
            if (!IsPostBack)
            {
                Random rad            = new Random();
                int    iRad           = rad.Next(1000, 100000);
                var    openOAuthAppid = string.Empty;
                if (!string.IsNullOrEmpty(Request["state"]))//很少会走到这里
                {
                    #region state不为空
                    string state = Request["state"];
                    //Response.Write("state:" + state);
                    try
                    {
                        #region Jermyn20140923
                        if (state.Equals("State"))
                        {
                            state = (string)HttpContext.Current.Session["State"];
                        }
                        Loggers.Debug(new DebugLogInfo()
                        {
                            Message = "State-Jermyn20140923:" + state
                        });
                        #endregion
                        #region 参数拼成
                        Loggers.Debug(new DebugLogInfo()
                        {
                            Message = string.Format("strState2: {0}", state)
                        });
                        //byte[] buff1 = Convert.FromBase64String(state);
                        //state = Encoding.UTF8.GetString(buff1);
                        //state = HttpUtility.UrlDecode(state, Encoding.UTF8);
                        //string[] array = state.Split(',');
                        //customerId = array[0];
                        //applicationId = array[1];
                        //goUrl = array[2];
                        //goUrl = goUrlTemp + goUrl;

                        byte[] buff1 = Convert.FromBase64String(state);
                        state = Encoding.UTF8.GetString(buff1);
                        state = HttpUtility.UrlDecode(state, Encoding.UTF8);
                        string[] array = state.Split(',');
                        customerId    = array[1];
                        applicationId = array[2];
                        goUrl         = array[0];
                        pageName      = array[3];
                        #endregion
                    }
                    catch (Exception ex)
                    {
                        Response.Write("<br/>");
                        Response.Write("state错误:" + ex.ToString());
                    }
                    #endregion
                }
                else
                {
                    #region 参数
                    //判断客户ID是否传递
                    if (!string.IsNullOrEmpty(Request["customerId"]))
                    {
                        customerId         = Request["customerId"];
                        loggingSessionInfo = Default.GetBSLoggingSession(customerId, "AuthUniversal");
                    }
                    else
                    {
                        Response.Write("<br>");
                        Response.Write("没有获取客户标识");
                    }
                    if (!string.IsNullOrEmpty(Request["applicationId"]))//微信菜单传来了applicationId,微信信息的唯一标识
                    {
                        applicationId = Request["applicationId"];
                        var wailist = new WApplicationInterfaceBLL(loggingSessionInfo).QueryByEntity(new WApplicationInterfaceEntity {
                            ApplicationId = applicationId, CustomerId = customerId, IsDelete = 0
                        }, null).FirstOrDefault();
                        openOAuthAppid = wailist != null ? wailist.OpenOAuthAppid : string.Empty;
                    }
                    else
                    {
                        loggingSessionInfo = Default.GetBSLoggingSession(customerId, "1");
                        var list = new WApplicationInterfaceBLL(loggingSessionInfo).QueryByEntity(new WApplicationInterfaceEntity {
                            CustomerId = customerId, IsDelete = 0
                        }, null).ToList();

                        if (list != null && list.Count > 0)
                        {
                            applicationId = list.FirstOrDefault().ApplicationId;
                            if (!string.IsNullOrEmpty(list.FirstOrDefault().OpenOAuthAppid))
                            {
                                openOAuthAppid = list.FirstOrDefault().OpenOAuthAppid;
                            }
                        }
                        else
                        {
                            Response.Write("<br>");
                            Response.Write("没有获取微信标识");
                        }
                    }
                    if (!string.IsNullOrWhiteSpace(Request["pageName"]))
                    {
                        this.pageName = Request["pageName"];
                    }
                    //else
                    //{
                    //    var temp = this.GetPageNameFromUrl(Request["goUrl"]);
                    //    if (!string.IsNullOrWhiteSpace(temp))
                    //    {//如果没有则尝试从goUrl的querystring中获取pageName
                    //        this.pageName = temp;
                    //    }
                    //    else
                    //    {
                    //        Response.Write("<br>");
                    //        Response.Write("没有获取跳转页面名");
                    //    }
                    //}
                    if (!string.IsNullOrEmpty(Request["goUrl"]))
                    {
                        goUrl = Request["goUrl"];
                        Response.Write("<br>");
                        Response.Write("goUrl:" + goUrl);
                        string eventId           = Request["eventId"];
                        string employeeId        = Request["employeeId"];
                        string strRetailTraderId = Request["RetailTraderId"];
                        string strChannelID      = Request["ChannelID"];
                        if (eventId != null && !eventId.Equals(""))//如果是跳转到活动的链接,还要加上活动标识***
                        {
                            if (goUrl.IndexOf("?") > 0)
                            {
                                goUrl = goUrl + "&eventId=" + eventId + "";
                            }
                            else
                            {
                                goUrl = goUrl + "?eventId=" + eventId + "";
                            }
                        }
                        if (employeeId != null && !employeeId.Equals(""))//如果是员工打赏的链接,还要加上员工标识***
                        {
                            if (goUrl.IndexOf("?") > 0)
                            {
                                goUrl = goUrl + "&employeeId=" + employeeId + "";
                            }
                            else
                            {
                                goUrl = goUrl + "?employeeId=" + employeeId + "";
                            }
                        }
                        if (strRetailTraderId != null && !strRetailTraderId.Equals(""))
                        {
                            if (goUrl.IndexOf("?") > 0)
                            {
                                goUrl = goUrl + "&RetailTraderId=" + strRetailTraderId + "";
                            }
                            else
                            {
                                goUrl = goUrl + "?RetailTraderId=" + strRetailTraderId + "";
                            }
                        }
                        if (strChannelID != null && !strChannelID.Equals(""))
                        {
                            if (goUrl.IndexOf("?") > 0)
                            {
                                goUrl = goUrl + "&channelId=" + strChannelID + "";
                            }
                            else
                            {
                                goUrl = goUrl + "?channelId=" + strChannelID + "";
                            }
                        }
                        var pObjectID = Request["ObjectID"];
                        if (!string.IsNullOrWhiteSpace(pObjectID))
                        {
                            pObjectID = pObjectID.Split(',')[0];
                        }
                        var pSourceID = Request["SourceID"];
                        if (!string.IsNullOrWhiteSpace(pSourceID))
                        {
                            pSourceID = pSourceID.Split(',')[0];
                        }
                        var pShareVipID = Request["ShareVipID"];
                        if (!string.IsNullOrWhiteSpace(pShareVipID))
                        {
                            pShareVipID = pShareVipID.Split(',')[0];
                        }
                        var objectType = Request["objectType"];
                        if (!string.IsNullOrWhiteSpace(objectType))
                        {
                            objectType = objectType.Split(',')[0];
                        }
                        if (!string.IsNullOrWhiteSpace(pObjectID))
                        {
                            if (goUrl.IndexOf("?") > 0)
                            {
                                goUrl = goUrl + "&ObjectID=" + pObjectID + "";
                            }
                            else
                            {
                                goUrl = goUrl + "?ObjectID=" + pObjectID + "";
                            }
                        }
                        if (!string.IsNullOrWhiteSpace(pSourceID))
                        {
                            if (goUrl.IndexOf("?") > 0)
                            {
                                goUrl = goUrl + "&SourceID=" + pSourceID + "";
                            }
                            else
                            {
                                goUrl = goUrl + "?SourceID=" + pSourceID + "";
                            }
                        }
                        if (!string.IsNullOrWhiteSpace(pShareVipID))
                        {
                            if (goUrl.IndexOf("?") > 0)
                            {
                                goUrl = goUrl + "&ShareVipID=" + pShareVipID + "";
                            }
                            else
                            {
                                goUrl = goUrl + "?ShareVipID=" + pShareVipID + "";
                            }
                        }
                        if (!string.IsNullOrWhiteSpace(objectType))
                        {
                            if (goUrl.IndexOf("?") > 0)
                            {
                                goUrl = goUrl + "&objectType=" + objectType + "";
                            }
                            else
                            {
                                goUrl = goUrl + "?objectType=" + objectType + "";
                            }
                        }

                        ////会员分享的SourceId,ShareVipID,ObjectID


                        //同样可以把商品的标识也这样处理goodsId,因为如下:
                        //  string itemUrl = weixinDomain + "/WXOAuth/AuthUniversal.aspx?customerId=" + CurrentUserInfo.ClientID
                        //+ "&applicationId=" + applicationId
                        //+ "&goUrl=" + weixinDomain + "/HtmlApps/html/public/shop/goods_detail.html?goodsId="     //把goodsId直接放在了gourl后面,系统会把它作为gourl的参数
                        //+ itemId + "&scope=snsapi_userinfo";

                        //把goodsId直接放在了gourl后面,系统会把它作为gourl的参数,不会吧他作为AuthUniversal的参数,所以不能通过 Request["的方式获取,
                        //也就不需要另外再拼接到gourl后面了***

                        //Response.End();
                    }
                    else
                    {
                        Response.Write("<br>");
                        Response.Write("没有获取goUrl");
                        Response.End();
                    }
                    #endregion
                }
                Response.Write("<br>");
                Response.Write("goUrl:" + goUrl);
                //Response.End();
                //loggingSessionInfo = Default.GetBSLoggingSession(customerId, "1");

                GetKeyByApp();
                string code = Request["code"];

                string scope = Request["scope"];
                if (code == null || code.Equals(""))
                {
                    //strState = customerId + "," + applicationId + "," + goUrl; //
                    //strState = HttpUtility.UrlEncode(strState, Encoding.UTF8);
                    //byte[] buff = Encoding.UTF8.GetBytes(strState);
                    //strState = Convert.ToBase64String(buff);
                    if (scope == null || scope.Equals(""))
                    {
                        strState = goUrl + "," + customerId + "," + applicationId + "," + "0" + "," + this.pageName; //
                    }
                    else
                    {
                        if (scope.Equals("snsapi_userinfo"))
                        {
                            strState = goUrl + "," + customerId + "," + applicationId + "," + "1" + "," + this.pageName; //
                        }
                        else
                        {
                            strState = goUrl + "," + customerId + "," + applicationId + "," + "0" + "," + this.pageName; //
                        }
                    }
                    strState = HttpUtility.UrlEncode(strState, Encoding.UTF8);
                    byte[] buff = Encoding.UTF8.GetBytes(strState);
                    strState = Convert.ToBase64String(buff);

                    //Loggers.Debug(new DebugLogInfo()
                    //{
                    //    Message = "一维码扫描---:" + "SetSignIn"
                    //});
                    Loggers.Debug(new DebugLogInfo()
                    {
                        Message = string.Format("goUrl:{0},strRedirectUri:{1}", goUrl, strRedirectUri)
                    });
                    //获取code    ,然后跳到下一步页面获取acces_token,openid
                    if (!string.IsNullOrEmpty(openOAuthAppid))
                    {
                        authBll.GetOAuthCode(strAppId, strRedirectUri, strState, this.Response, scope, openOAuthAppid);
                    }
                    else
                    {
                        authBll.GetOAuthCode(strAppId, strRedirectUri, strState, this.Response, scope);//strRedirectUri是WXOAuth/AuthCodeReques.aspx,strState包含goUrl,并且跳转页面
                    }
                }
                else
                {
                    Response.Write("存在code:" + code);
                    string token  = "";
                    string openId = string.Empty;
                    if (!string.IsNullOrEmpty(openOAuthAppid))
                    {
                        openId = authBll.GetAccessToken(code, strAppId, strAppSecret, loggingSessionInfo, iRad, out token, openOAuthAppid);
                    }
                    else
                    {
                        openId = authBll.GetAccessToken(code, strAppId, strAppSecret, loggingSessionInfo, iRad, out token);
                    }
                    Response.Write("<br>");
                    Response.Write("OpenID:" + openId);
                    PageRedict(openId);
                }
            }
        }
예제 #6
0
        private void DownloadQRCode()
        {
            string weixinDomain  = ConfigurationManager.AppSettings["original_url"];
            string sourcePath    = this.CurrentContext.Server.MapPath("/QRCodeImage/qrcode.jpg");
            string targetPath    = this.CurrentContext.Server.MapPath("/QRCodeImage/");
            string currentDomain = this.CurrentContext.Request.Url.Host;//当前项目域名

            if (currentDomain == "localhost")
            {
                currentDomain += ":2330";
            }
            string itemId   = FormatParamValue(Request("item_id"));   //商品ID
            string itemName = FormatParamValue(Request("item_name")); //商品名
            string imageURL;



            ObjectImagesBLL objectImagesBLL = new ObjectImagesBLL(CurrentUserInfo);

            //查找是否已经生成了二维码
            ObjectImagesEntity[] objectImagesEntityArray = objectImagesBLL.QueryByEntity(new ObjectImagesEntity()
            {
                ObjectId = itemId, Description = "自动生成的产品二维码"
            }, null);

            if (objectImagesEntityArray.Length == 0)
            {
                string applicationId = "";
                //根据CustomerId去取公众号信息

                var list = new WApplicationInterfaceBLL(CurrentUserInfo).QueryByEntity(new WApplicationInterfaceEntity {
                    CustomerId = CurrentUserInfo.ClientID, IsDelete = 0
                }, null).ToList();

                if (list != null && list.Count > 0)
                {
                    applicationId = list.FirstOrDefault().ApplicationId;
                }
                else
                {
                    //Response.Write("<br>");
                    //Response.Write("没有获取微信标识");
                    throw new Exception("该商户没有绑定微信公众号,无法生成商品二维码");
                }
                var wapentity = list.FirstOrDefault();//获取公众号信息

                //http://api.dev.chainclouds.com
                //    http://api.dev.chainclouds.com/WXOAuth/AuthUniversal.aspx?customerId=049b0a8f641f4ca7b17b0b7b6291de1f&applicationId=1D7A01FC1E7D41ECBAC2696D0D363315&goUrl=api.dev.chainclouds.com/HtmlApps/html/public/shop/goods_detail.html?rootPage=true&rootPage=true&goodsId=DBF5326F4C5B4B0F8508AB54B0B0EBD4&ver=1448273310707&scope=snsapi_userinfo

                string itemUrl = weixinDomain + "/WXOAuth/AuthUniversal.aspx?customerId=" + CurrentUserInfo.ClientID
                                 + "&applicationId=" + applicationId
                                 + "&goUrl=" + weixinDomain + "/HtmlApps/html/public/shop/goods_detail.html?goodsId="
                                 + itemId + "&scope=snsapi_userinfo";

                //  string itemUrl = "http://*****:*****@"/HeadImage/qrcodeBack.jpg", imageURL, itemName);
                }

                //把下载下来的图片的地址存到ObjectImages
                objectImagesBLL.Create(new ObjectImagesEntity()
                {
                    ImageId    = Utils.NewGuid(),
                    CustomerId = CurrentUserInfo.ClientID,
                    ImageURL   = imageURL,
                    ObjectId   = itemId,
                    Title      = itemName
                    ,
                    Description = "自动生成的产品二维码"
                });

                Loggers.Debug(new DebugLogInfo()
                {
                    Message = "二维码已生成,imageURL:" + imageURL
                });
            }
            else
            {
                imageURL = objectImagesEntityArray[0].ImageURL;
            }
            string imagePath = "";

            if (imageURL.IndexOf("HeadImage") > -1)
            {
                string dirPath   = System.AppDomain.CurrentDomain.BaseDirectory;
                var    imageName = imageURL.Substring(imageURL.IndexOf("HeadImage")).Replace("/", @"\");
                imagePath = dirPath + imageName;//整个
            }
            else
            {  //兼容老的存放地址
                imagePath = targetPath + imageURL.Substring(imageURL.LastIndexOf("/"));
            }

            Loggers.Debug(new DebugLogInfo()
            {
                Message = "二维码路径,imagePath:" + imageURL
            });

            try
            {
                //要下载的文件名
                FileInfo DownloadFile = new FileInfo(imagePath);

                if (DownloadFile.Exists)
                {
                    CurrentContext.Response.Clear();
                    CurrentContext.Response.AddHeader("Content-Disposition", "attachment;filename=\"" + System.Web.HttpUtility.UrlEncode(itemName, System.Text.Encoding.UTF8) + ".jpg" + "\"");
                    CurrentContext.Response.AddHeader("Content-Length", DownloadFile.Length.ToString());
                    CurrentContext.Response.ContentType = "application/octet-stream";
                    CurrentContext.Response.TransmitFile(DownloadFile.FullName);
                    CurrentContext.Response.Flush();
                }
                else
                {
                    Loggers.Debug(new DebugLogInfo()
                    {
                        Message = "二维码未找到"
                    });
                }
            }
            catch (Exception ex)
            {
                CurrentContext.Response.ContentType = "text/plain";
                CurrentContext.Response.Write(ex.Message);
            }
            finally
            {
                CurrentContext.Response.End();
            }
        }