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 string SetVipInfoByToken(string token, string openId, LoggingSessionInfo loggionSesionInfo, HttpResponse Response)
        {
            string vipId = string.Empty;
            var    url   = "https://api.weixin.qq.com/sns/userinfo?";

            var postData = "access_token=" + token + "&openid=" + openId + "&lang=zh_CN";

            // Response.Write(url + postData);

            string method = "GET";
            // var data = HttpWebClient.DoHttpRequest(url, postData);
            var data     = CommonBLL.GetRemoteData(url + postData, method, string.Empty);
            var openInfo = data.DeserializeJSONTo <WxOpenInfoResponse>();

            if (openInfo == null)
            {
                Loggers.Debug(new DebugLogInfo()
                {
                    Message = "获取微信用户信息失败:" + data.ToJSON()
                });
                return(vipId);
            }
            else
            {
                try
                {
                    //insert into vip
                    CPOS.Common.DownloadImage downloadServer = new DownloadImage();
                    string downloadImageUrl = ConfigurationManager.AppSettings["website_WWW"];
                    var    headimgurl       = downloadServer.DownloadFile(openInfo.headimgurl, downloadImageUrl);

                    vipId = BaseService.NewGuidPub();
                    VipBLL vipServiceUnion = new VipBLL(loggionSesionInfo);

                    var vipInfo = new VipEntity();
                    vipInfo.VIPID            = vipId;
                    vipInfo.WeiXinUserId     = openId;                        //openId微信提供
                    vipInfo.City             = openInfo.city;                 //城市,微信提供
                    vipInfo.Gender           = Convert.ToInt32(openInfo.sex); //性别,微信提供
                    vipInfo.VipName          = openInfo.nickname;             //微信昵称,微信提供
                    vipInfo.VipCode          = vipServiceUnion.GetVipCode();
                    vipInfo.UnionID          = openInfo.unionid;
                    vipInfo.VipSourceId      = "3";                                        //写死
                    vipInfo.HeadImgUrl       = headimgurl;                                 //注意,需要先传到我们本地服务器,可以参考(需要download下来)
                    vipInfo.ClientID         = loggionSesionInfo.ClientID;                 //客户标识
                    vipInfo.RegistrationTime = DateTime.Now;
                    vipInfo.Status           = 0;                                          //客户没有关注
                    vipInfo.VipPasswrod      = "e10adc3949ba59abbe56e057f20f883e";         //初始密码123456
                    UnitService unitServer = new UnitService(loggionSesionInfo);
                    vipInfo.CouponInfo = unitServer.GetUnitByUnitTypeForWX("总部", null).Id; //获取总部门店标识

                    var    wappBll    = new WApplicationInterfaceBLL(loggionSesionInfo);
                    string weixinId   = "";
                    var    wappEntity = wappBll.QueryByEntity(new WApplicationInterfaceEntity()
                    {
                        CustomerId = loggionSesionInfo.ClientID
                    }, null);
                    if (wappEntity.Length > 0)
                    {
                        weixinId = wappEntity[0].WeiXinID;
                    }
                    vipInfo.WeiXin = weixinId;          //微信号码,通过数据库可以查出


                    vipServiceUnion.Create(vipInfo);
                }
                catch (Exception ex)
                {
                    Loggers.Debug(new DebugLogInfo()
                    {
                        Message = "新增微信用户信息失败:" + ex.ToString()
                    });
                }

                return(vipId);
            }
        }