Esempio n. 1
0
        /// <summary>
        /// 设置用户token信息
        /// </summary>
        /// <param name="UserId">用户标识</param>
        /// <param name="AccessToken">token不存在</param>
        private void SetAccessToken(string UserId, string AccessToken, LoggingSessionInfo loggingSessionInfo, string resultErrorUrl)
        {
            try
            {
                if (UserId == null || UserId.Trim().Equals(""))
                {
                    Loggers.Debug(new DebugLogInfo()
                    {
                        Message = string.Format("新浪回调页面2-用户标识为空")
                    });
                }
                Response.Write("设置用户token信息1");
                #region 处理业务
                #region 判断用户是否存在会员表中
                VipBLL    vipServer = new VipBLL(loggingSessionInfo);
                VipEntity vipInfo   = vipServer.GetByID(UserId);
                if (vipInfo == null || vipInfo.VIPID == null || vipInfo.VIPID.Equals(""))
                {
                    vipInfo.VIPID    = UserId;
                    vipInfo.VipCode  = vipServer.GetVipCode();
                    vipInfo.ClientID = loggingSessionInfo.CurrentUser.customer_id;
                    vipInfo.Status   = 1;
                    vipServer.Create(vipInfo);
                }
                #endregion
                #region 判断用户是否存在会员的新浪微博扩展表中
                VipExpandSinaWbBLL    vipSinaWbServer = new VipExpandSinaWbBLL(loggingSessionInfo);
                VipExpandSinaWbEntity vipSinaWbInfo   = new VipExpandSinaWbEntity();
                vipSinaWbInfo = vipSinaWbServer.GetByID(UserId);
                if (vipSinaWbInfo != null && vipSinaWbInfo.VipId != null && !vipSinaWbInfo.VipId.Equals(""))
                {
                    vipSinaWbInfo.AccessToken = AccessToken;
                    vipSinaWbServer.Update(vipSinaWbInfo, false);
                }
                else
                {
                    VipExpandSinaWbEntity vipSinaWbInfo1 = new VipExpandSinaWbEntity();
                    vipSinaWbInfo1.VipId       = UserId;
                    vipSinaWbInfo1.AccessToken = AccessToken;
                    vipSinaWbServer.Create(vipSinaWbInfo1);
                }
                #endregion
                #endregion

                Loggers.Debug(new DebugLogInfo()
                {
                    Message = string.Format("新浪回调页面3-设置用户信息成功.")
                });
            }
            catch (Exception ex)
            {
                Loggers.Debug(new DebugLogInfo()
                {
                    Message = string.Format("新浪回调页面4-错误信息提示 {0}:" + ex.ToString())
                });
                Response.Write(ex.ToString());
            }
        }
Esempio n. 2
0
 public void GetUserInfo(string UserId, string AccessToken, LoggingSessionInfo loggingSessionInfo, string uid)
 {
     try
     {
         //string uid = "1036433880";
         Sina = new Client(new OAuth(ConfigurationManager.AppSettings["AppKey"], ConfigurationManager.AppSettings["AppSecret"], AccessToken, null)); //用cookie里的accesstoken来实例化OAuth,这样OAuth就有操作权限了
         var    user     = Sina.API.Dynamic.Users.Show(uid);
         string strUser  = user.ToString();
         var    userInfo = strUser.DeserializeJSONTo <SinaWeiBoUserInfo>();
         #region 更新用户信息
         VipExpandSinaWbBLL    vipSinaWbServer = new VipExpandSinaWbBLL(loggingSessionInfo);
         VipExpandSinaWbEntity vipSinaWbInfo   = new VipExpandSinaWbEntity();
         vipSinaWbInfo.VipId = UserId;
         if (userInfo != null && userInfo.id != null && !userInfo.id.Equals(""))
         {
             vipSinaWbInfo.ScreenName      = userInfo.screen_name;
             vipSinaWbInfo.LabelName       = userInfo.name;
             vipSinaWbInfo.Province        = userInfo.province;
             vipSinaWbInfo.City            = userInfo.city;
             vipSinaWbInfo.Location        = userInfo.location;
             vipSinaWbInfo.Description     = userInfo.description;
             vipSinaWbInfo.Url             = userInfo.url;
             vipSinaWbInfo.ProfileImageUrl = userInfo.profile_image_url;
             vipSinaWbInfo.ProfileUrl      = userInfo.profile_url;
             vipSinaWbInfo.Gender          = userInfo.gender;
             vipSinaWbInfo.Weihao          = userInfo.weihao;
             vipSinaWbServer.Update(vipSinaWbInfo, false);
         }
         #endregion
         //Response.Write(string.Format("{0}", user));
         Response.Write("设置新浪微博用户信息成功.");
     }
     catch (Exception ex)
     {
         Loggers.Debug(new DebugLogInfo()
         {
             Message = string.Format("设置新浪微博用户信息失败:" + ex.ToString())
         });
         Response.Write(ex.ToString());
     }
 }
Esempio n. 3
0
        /// <summary>
        /// 授权查询
        /// </summary>
        private void GetAccessToken(string UserId, string AccessToken, LoggingSessionInfo loggingSessionInfo, string resultErrorUrl)
        {
            try
            {
                #region 获取授权信息
                var uriString = "https://api.weibo.com/oauth2/get_token_info";

                var postData = "access_token=" + AccessToken + "";
                Loggers.Debug(new DebugLogInfo()
                {
                    Message = string.Format("支付跳转-链接字符串: {0}", postData)
                });
                WebClient myWebClient = new WebClient();
                // 注意这种拼字符串的ContentType
                myWebClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
                // 转化成二进制数组
                byte[] byteArray = Encoding.UTF8.GetBytes(postData);
                // 上传数据,并获取返回的二进制数据.
                byte[] responseArray = myWebClient.UploadData(uriString, "POST", byteArray);
                var    data          = System.Text.Encoding.UTF8.GetString(responseArray);
                var    tokenInfo     = data.DeserializeJSONTo <TokenInfo>();
                if (tokenInfo == null)
                {
                    Loggers.Debug(new DebugLogInfo()
                    {
                        Message = string.Format("授权查询3-授权成功--但是没有返回信息:" + data.ToString())
                    });
                    return;
                }
                #endregion
                #region 更新授权信息
                VipExpandSinaWbBLL    vipSinaWbServer = new VipExpandSinaWbBLL(loggingSessionInfo);
                VipExpandSinaWbEntity vipSinaWbInfo   = new VipExpandSinaWbEntity();
                vipSinaWbInfo = vipSinaWbServer.GetByID(UserId);
                if (vipSinaWbInfo != null && vipSinaWbInfo.VipId != null && !vipSinaWbInfo.VipId.Equals(""))
                {
                    vipSinaWbInfo.AccessToken = AccessToken;
                    if (tokenInfo != null)
                    {
                        vipSinaWbInfo.UID      = ToStr(tokenInfo.uid);
                        vipSinaWbInfo.Appkey   = ToStr(tokenInfo.appkey);
                        vipSinaWbInfo.Scope    = ToStr(tokenInfo.scope);
                        vipSinaWbInfo.CreateAt = ToStr(tokenInfo.create_at);
                        vipSinaWbInfo.ExpireIn = ToStr(tokenInfo.expire_in);
                    }
                    vipSinaWbServer.Update(vipSinaWbInfo, false);
                }
                else
                {
                    VipExpandSinaWbEntity vipSinaWbInfo1 = new VipExpandSinaWbEntity();
                    vipSinaWbInfo1.VipId = UserId;
                    if (tokenInfo != null)
                    {
                        vipSinaWbInfo1.UID      = ToStr(tokenInfo.uid);
                        vipSinaWbInfo1.Appkey   = ToStr(tokenInfo.appkey);
                        vipSinaWbInfo1.Scope    = ToStr(tokenInfo.scope);
                        vipSinaWbInfo1.CreateAt = ToStr(tokenInfo.create_at);
                        vipSinaWbInfo1.ExpireIn = ToStr(tokenInfo.expire_in);
                    }
                    vipSinaWbServer.Create(vipSinaWbInfo1);
                }
                #endregion

                Loggers.Debug(new DebugLogInfo()
                {
                    Message = string.Format("授权查询3-授权成功:")
                });
                //设置新浪微博用户信息
                GetUserInfo(UserId, AccessToken, loggingSessionInfo, ToStr(tokenInfo.uid));
            }
            catch (Exception ex) {
                Loggers.Debug(new DebugLogInfo()
                {
                    Message = string.Format("授权查询4-错误信息提示 {0}:" + ex.ToString())
                });
                Response.Write(ex.ToString());
            }
        }
Esempio n. 4
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public string setSinaWbShare()
        {
            string content  = string.Empty;
            var    respData = new setSinaWbShareRespData();

            try
            {
                string reqContent = Request["ReqContent"];

                Loggers.Debug(new DebugLogInfo()
                {
                    Message = string.Format("setSinaWbShare: {0}", reqContent)
                });

                //解析请求字符串
                var reqObj = reqContent.DeserializeJSONTo <setSinaWbShareReqData>();
                reqObj = reqObj == null ? new setSinaWbShareReqData() : reqObj;
                if (reqObj.special == null)
                {
                    reqObj.special = new setSinaWbShareReqSpecialData();
                }
                if (reqObj.special == null)
                {
                    respData.code        = "2201";
                    respData.description = "特殊参数不能为空";
                    return(respData.ToJSON().ToString());
                }

                if (reqObj.special.resultUrl == null || reqObj.special.resultUrl.Equals(""))
                {
                    respData.code        = "2201";
                    respData.description = "返回地址不能为空";
                    return(respData.ToJSON().ToString());
                }

                //判断客户ID是否传递
                if (!string.IsNullOrEmpty(reqObj.common.customerId))
                {
                    customerId = reqObj.common.customerId;
                }
                var loggingSessionInfo = Default.GetBSLoggingSession(customerId, "1");

                #region
                VipExpandSinaWbBLL    server = new VipExpandSinaWbBLL(loggingSessionInfo);
                VipExpandSinaWbEntity info   = server.GetByID(reqObj.common.userId);
                if (info == null || info.AccessToken == null)
                {
                    respData.code        = "103";
                    respData.description = "不存在对应的token";
                    return(respData.ToJSON().ToString());
                }

                Sina = new Client(new OAuth(ConfigurationManager.AppSettings["AppKey"]
                                            , ConfigurationManager.AppSettings["AppSecret"]
                                            , info.AccessToken
                                            , null));
                string imageUrl = reqObj.special.imageUrl;
                string Text     = reqObj.special.text;
                if ((imageUrl == null || imageUrl.Equals("")) && (Text == null || Text.Equals("")))
                {
                    respData.code        = "103";
                    respData.description = "分享信息为空";
                    return(respData.ToJSON().ToString());
                }
                VipWeiboShareLogBLL    logServer = new VipWeiboShareLogBLL(loggingSessionInfo);
                VipWeiboShareLogEntity logInfo   = new VipWeiboShareLogEntity();
                logInfo.LogId       = BaseService.NewGuidPub();
                logInfo.AccessToken = info.AccessToken;
                logInfo.VipId       = info.VipId;
                logInfo.ImageUrl    = imageUrl;
                logInfo.Text        = Text;
                logInfo.ShareType   = "Sina";
                if (imageUrl == null || imageUrl.Equals(""))
                {
                    try
                    {
                        dynamic result = Sina.API.Dynamic.Statuses.Update(Text); //分享微博文本
                        logInfo.IsSuccess = 1;
                    }
                    catch (Exception ex1) {
                        logInfo.IsSuccess = 0;
                        if (ex1.ToString().Length > 200)
                        {
                            logInfo.FailureResason = ex1.ToString().Substring(0, 199);
                        }
                        else
                        {
                            logInfo.FailureResason = ex1.ToString();
                        }
                        respData.code        = "103";
                        respData.description = ex1.ToString();
                    }
                }
                else
                {
                    JIT.CPOS.BS.BLL.WX.CommonBLL serverBLL = new BS.BLL.WX.CommonBLL();
                    string urlx = serverBLL.DownloadFile(imageUrl);
                    try
                    {
                        dynamic r = Sina.API.Dynamic.Statuses.Upload(Text, byteImage(urlx));    //分享微博内容
                        logInfo.IsSuccess = 1;
                    }
                    catch (Exception ex)
                    {
                        Response.Write(ex.ToString());
                        logInfo.IsSuccess = 0;
                        if (ex.ToString().Length > 200)
                        {
                            logInfo.FailureResason = ex.ToString().Substring(0, 199);
                        }
                        else
                        {
                            logInfo.FailureResason = ex.ToString();
                        }
                        respData.code        = "103";
                        respData.description = ex.ToString();
                    }
                }
                logServer.Create(logInfo);
                #endregion
            }
            catch (Exception ex)
            {
                respData.code        = "103";
                respData.description = "数据库操作错误";
                respData.exception   = ex.ToString();
            }
            content = respData.ToJSON();
            return(content);
        }
Esempio n. 5
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public string getWeiboUserInfo()
        {
            string content  = string.Empty;
            var    respData = new getWeiboUserInfoRespData();

            try
            {
                string reqContent = Request["ReqContent"];

                Loggers.Debug(new DebugLogInfo()
                {
                    Message = string.Format("getWeiboUserInfo: {0}", reqContent)
                });

                //解析请求字符串
                var reqObj = reqContent.DeserializeJSONTo <getWeiboUserInfoReqData>();
                reqObj = reqObj == null ? new getWeiboUserInfoReqData() : reqObj;

                //判断客户ID是否传递
                if (!string.IsNullOrEmpty(reqObj.common.customerId))
                {
                    customerId = reqObj.common.customerId;
                }
                var loggingSessionInfo = Default.GetBSLoggingSession(customerId, "1");
                respData.content = new getWeiboUserInfoRespContentData();

                #region
                VipExpandSinaWbBLL    server = new VipExpandSinaWbBLL(loggingSessionInfo);
                VipExpandSinaWbEntity info   = server.GetByID(reqObj.common.userId);
                if (info == null || info.AccessToken == null)
                {
                    respData.content.isSinaWb      = "0";
                    respData.content.isAccessToken = "0";
                }
                else
                {
                    DateTime dt       = DateTime.Parse("01/01/1970");
                    TimeSpan ts       = DateTime.Now - dt;
                    int      sec      = ts.Seconds; // 秒数
                    int      createAt = 0;          //创建时间
                    int      expireIn = 0;          //剩余有效时间
                    if (info.CreateAt != null && !info.CreateAt.Equals(""))
                    {
                        createAt = Convert.ToInt32(info.CreateAt);
                    }
                    if (info.ExpireIn != null && !info.ExpireIn.Equals(""))
                    {
                        expireIn = Convert.ToInt32(info.ExpireIn);
                    }
                    respData.content.isSinaWb = "1";
                    if (sec - createAt > expireIn)
                    {
                        respData.content.isAccessToken = "1";
                    }
                    else
                    {
                        respData.content.isAccessToken = "0";
                    }
                }

                #endregion
            }
            catch (Exception ex)
            {
                respData.code        = "103";
                respData.description = "数据库操作错误";
                respData.exception   = ex.ToString();
            }
            content = respData.ToJSON();
            return(content);
        }
Esempio n. 6
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="pEntity">实体实例</param>
 /// <param name="pTran">事务实例,可为null,如果为null,则不使用事务来更新</param>
 public void Update(VipExpandSinaWbEntity pEntity, IDbTransaction pTran)
 {
     Update(pEntity, true, pTran);
 }
Esempio n. 7
0
 public void Update(VipExpandSinaWbEntity pEntity, bool pIsUpdateNullField, IDbTransaction pTran)
 {
     _currentDAO.Update(pEntity, pIsUpdateNullField, pTran);
 }
Esempio n. 8
0
 /// <summary>
 /// 创建一个新实例
 /// </summary>
 /// <param name="pEntity">实体实例</param>
 public void Create(VipExpandSinaWbEntity pEntity)
 {
     _currentDAO.Create(pEntity);
 }
Esempio n. 9
0
 /// <summary>
 /// 在事务内创建一个新实例
 /// </summary>
 /// <param name="pEntity">实体实例</param>
 /// <param name="pTran">事务实例,可为null,如果为null,则不使用事务来更新</param>
 public void Create(VipExpandSinaWbEntity pEntity, IDbTransaction pTran)
 {
     _currentDAO.Create(pEntity, pTran);
 }
Esempio n. 10
0
 /// <summary>
 /// 分页根据实体条件查询实体
 /// </summary>
 /// <param name="pQueryEntity">以实体形式传入的参数</param>
 /// <param name="pOrderBys">排序组合</param>
 /// <returns>符合条件的实体集</returns>
 public PagedQueryResult <VipExpandSinaWbEntity> PagedQueryByEntity(VipExpandSinaWbEntity pQueryEntity, OrderBy[] pOrderBys, int pPageSize, int pCurrentPageIndex)
 {
     return(_currentDAO.PagedQueryByEntity(pQueryEntity, pOrderBys, pPageSize, pCurrentPageIndex));
 }
Esempio n. 11
0
 /// <summary>
 /// 根据实体条件查询实体
 /// </summary>
 /// <param name="pQueryEntity">以实体形式传入的参数</param>
 /// <param name="pOrderBys">排序组合</param>
 /// <returns>符合条件的实体集</returns>
 public VipExpandSinaWbEntity[] QueryByEntity(VipExpandSinaWbEntity pQueryEntity, OrderBy[] pOrderBys)
 {
     return(_currentDAO.QueryByEntity(pQueryEntity, pOrderBys));
 }
Esempio n. 12
0
 /// <summary>
 /// 删除
 /// </summary>
 /// <param name="pEntity"></param>
 public void Delete(VipExpandSinaWbEntity pEntity)
 {
     _currentDAO.Delete(pEntity);
 }
Esempio n. 13
0
 public void Update(VipExpandSinaWbEntity pEntity, bool pIsUpdateNullField)
 {
     _currentDAO.Update(pEntity, pIsUpdateNullField);
 }
Esempio n. 14
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="pEntity">实体实例</param>
 public void Update(VipExpandSinaWbEntity pEntity)
 {
     Update(pEntity, true);
 }