예제 #1
0
        public IActionResult GetToken(string appId, string secret)
        {
            long logId = 0;

            try
            {
                logId = BaseApiManager.SaveLogs(appId);
                if (string.IsNullOrWhiteSpace(appId))
                {
                    return(Error(logId, "appid not empty!"));
                }
                if (string.IsNullOrWhiteSpace(secret))
                {
                    return(Error(logId, "secret not empty!"));
                }

                int    tokenTotalNumber = InterfaceAccessTokenService.GetInterfaceAccessTokenTotalNumberPro(SystemID, appId);
                string token            = new Common.Token.TokenHelper(appId, secret).GetToken(tokenTotalNumber);
                int    expiresIn        = AccessTokenExpiresIn;
                string ipAddress        = Net.Ip;
                int    createTimestamp  = TimeHelper.GetUnixTimestamp();

                bool IsIpAddress = InterfaceAccessWhiteListService.VerifyInterfaceAccessWhiteListByAppIdPro(SystemID, appId, ipAddress);
                if (!IsIpAddress)
                {
                    return(Error(logId, "ip verify fail!"));
                }

                bool createResult = InterfaceAccessTokenService.SaveInterfaceAccessTokenAutoPro(token, SystemID, appId, secret, expiresIn, ipAddress, createTimestamp);
                if (createResult)
                {
                    return(Result(logId, new { token, expiresin = expiresIn }));
                }
                else
                {
                    return(Error(logId, "fail"));
                }
            }
            catch (Exception ex)
            {
                return(Error(logId, ex.Message));
            }
        }