IP 和 KEY 都配置了,接口调用时候老是提示 Valid API key required。
查询代码发现,IP地址从 $_SERVER['REMOTE_ADDR'] 取的,我们都在云服务器,取出来的 IP 你都不认识。
修改代码 upload\include\class.api.php 172~195行:
function requireApiKey() { # Validate the API key -- required to be sent via the X-API-Key # header // if(!($key=$this->getApiKey())) // return $this->exerr(401, __('Valid API key required')); // elseif (!$key->isActive() || $key->getIPAddr()!=$_SERVER['REMOTE_ADDR']) // return $this->exerr(401, __('API key not found/active or source IP not authorized')); $key=$this->getApiKey(); return $key; } function getApiKey() { //2020-1-10 因为云服务 IP 混乱,无法确定IP,所以不验证 IP if (!$this->apikey && isset($_SERVER['HTTP_X_API_KEY'])) $this->apikey = API::lookupByKey($_SERVER['HTTP_X_API_KEY']); // if (!$this->apikey && isset($_SERVER['HTTP_X_API_KEY']) && isset($_SERVER['REMOTE_ADDR'])) // $this->apikey = API::lookupByKey($_SERVER['HTTP_X_API_KEY'], $_SERVER['REMOTE_ADDR']); return $this->apikey; }
绕开 IP 验证,就可以了,key 还是生效的,安全性有保证。
其他相关文档链接备注:
接口开发文档:https://docs.osticket.com/en/latest/Developer%20Documentation/API/Tickets.html
使用教程:https://tmib.net/using-the-osticket-1-8-1-2-api/