Example #1
0
        public ActionResult AuthorCallBackBaiChuan(string code, string state)
        {
            try
            {
                int           user_id       = int.Parse(state);
                dm_userEntity dm_UserEntity = dm_userIBLL.GetEntityByCache(user_id);

                dm_basesettingEntity dm_BasesettingEntity = dm_BaseSettingIBLL.GetEntityByCache(dm_UserEntity.appid);

                WebUtils webUtils = new WebUtils();
                IDictionary <string, string> pout = new Dictionary <string, string>();
                pout.Add("grant_type", "authorization_code");
                pout.Add("client_id", "29236073");
                pout.Add("client_secret", "29de7a8560d773736ef5bf568a7961bd");
                pout.Add("code", code);
                pout.Add("redirect_uri", HttpUtility.UrlEncode(CommonConfig.tb_auth_address));
                string output = webUtils.DoPost("http://oauth.taobao.com/token", pout);

                #region 获取出来用户信息
                Learun.Loger.Log log = LogFactory.GetLogger("workflowapi");
                log.Error(output);
                #endregion

                return(Success("授权成功", output));
            }
            catch (Exception ex)
            {
                return(Fail(ex.Message));
            }
        }
Example #2
0
        public ActionResult AuthorCallBack(string code, string state)
        {
            Learun.Loger.Log log = LogFactory.GetLogger("workflowapi");

            try
            {
                int           user_id       = int.Parse(state);
                dm_userEntity dm_UserEntity = dm_userIBLL.GetEntityByCache(user_id);

                dm_basesettingEntity dm_BasesettingEntity = dm_BaseSettingIBLL.GetEntityByCache(dm_UserEntity.appid);


                WebUtils webUtils = new WebUtils();
                IDictionary <string, string> pout = new Dictionary <string, string>();
                pout.Add("grant_type", "authorization_code");
                pout.Add("client_id", dm_BasesettingEntity.tb_appkey);
                pout.Add("client_secret", dm_BasesettingEntity.tb_appsecret);
                pout.Add("code", code);
                pout.Add("redirect_uri", HttpUtility.UrlEncode(CommonConfig.tb_auth_address));
                string output = webUtils.DoPost("http://oauth.taobao.com/token", pout);

                log.Error(output);

                AuthorInfo authorInfo = JsonConvert.DeserializeObject <AuthorInfo>(output);

                ITopClient client = new DefaultTopClient("http://gw.api.taobao.com/router/rest", dm_BasesettingEntity.tb_appkey, dm_BasesettingEntity.tb_appsecret);
                TbkScPublisherInfoSaveRequest req = new TbkScPublisherInfoSaveRequest();
                req.RelationFrom = "1";
                req.OfflineScene = "1";
                req.OnlineScene  = "1";
                req.InviterCode  = dm_BasesettingEntity.tb_relation_invitecode;
                req.InfoType     = 1L;
                req.Note         = "哆来米代理申请";
                req.RegisterInfo = "{\"phoneNumber\":\"18801088599\",\"city\":\"江苏省\",\"province\":\"南京市\",\"location\":\"玄武区花园小区\",\"detailAddress\":\"5号楼3单元101室\"}";
                TbkScPublisherInfoSaveResponse rsp = client.Execute(req, authorInfo.access_token);
                log.Error(rsp.Body);
                log.Error(HttpUtility.UrlDecode(authorInfo.taobao_user_nick));
                if (rsp.Data == null)
                {
                    throw new Exception(rsp.SubErrMsg);
                }
                else
                {
                    string relation_id = rsp.Data.RelationId.ToString();
                    if (dm_userIBLL.NoExistRelationID(relation_id, user_id))
                    {
                        string[] pids = dm_BasesettingEntity.tb_relation_pid.Split('_');
                        dm_UserEntity.tb_pid           = pids.Length == 4 ? pids[3] : "";
                        dm_UserEntity.tb_relationid    = relation_id;
                        dm_UserEntity.tb_nickname      = HttpUtility.UrlDecode(authorInfo.taobao_user_nick);
                        dm_UserEntity.isrelation_beian = 1;
                        dm_userIBLL.SaveEntity(user_id, dm_UserEntity);
                    }
                    else
                    {
                        string otherAccount = "其他账号";
                        if (!dm_UserEntity.IsEmpty() && !dm_UserEntity.phone.IsEmpty() && dm_UserEntity.phone.Length > 10)
                        {
                            otherAccount = "账号" + Regex.Replace(dm_UserEntity.phone, "(\\d{3})\\d{4}(\\d{4})", "$1****$2");
                        }
                        throw new Exception("当前淘宝账号已在" + otherAccount + "下授权,请更换账号!");
                    }
                }



                return(RedirectToAction("AuthorResult", new { IsSuccess = "授权成功", ErrorMessage = "" }));

                //return Success("授权成功", output);
            }
            catch (Exception ex)
            {
                return(RedirectToAction("AuthorResult", new { IsSuccess = "授权失败", ErrorMessage = ex.Message }));
            }
        }