此包最新版本(dev-master)没有可用的许可信息。

dev-master 2022-02-23 14:20 UTC

This package is not auto-updated.

Last update: 2024-09-23 19:18:17 UTC


README

API-клиент сервиса hh.ru на php.

安装

在文件 composer.json 中添加仓库和包名

"repositories": [
    ...
    {
        "type": "vcs",
        "url": "https://github.com/KirillMochalov/hh-client"
    }
],
"require": {
    ...
    "simple-hh-client/client": "dev-master"
}

执行命令

composer install

授权

为了执行对 hh.ru 的任何请求,需要获取求职者/应用程序的令牌。要获取求职者令牌,我们创建 OAuthClient 类的对象并调用 getAuthenticationUrl 方法,该方法将返回用于重定向用户的 URL。

$oauth_client = new OAuthClient('%client_id%', '%client_secret%', 'https:///hh');
$redirect_url = $oauth_client->getAuthenticationUrl();

用户在 hh.ru 网站上进行授权后,将被重定向到 OAuthClient 构造函数中作为第三个参数指定的地址。在示例中这是 https:///hh
https:///hh 页面上创建 OAuthClient 类的对象,并调用带有 code GET 参数的 oAuth 方法。

$oauth_client = new OAuthClient('%client_id%', '%client_secret%', 'https:///hh');
$access_token = $oauth_client->oAuth($_GET['code'])->getAccessToken();

获取的令牌需要保存在会话或数据库中,以便进一步使用。

求职者客户端的使用

使用之前获得的求职者令牌创建 ApplicantClient 类的对象。

$hh_client = new ApplicantClient($access_token);

搜索职位

$search_string = 'Кассир';
$vacancies = $hh_client->searchVacancies($search_string);

获取职位详细信息

$vacancy_id = 48759683;
$vacancy = $hh_client->getVacancy($vacancy_id);

求职者简历列表

$resumes = $hh_client->getResumes();

获取简历详细信息

$resume_id = '77ea924eff03bff13a0039ed1f465361344953';
$resume = $hh_client->getResume($resume_id);

更新简历

$resume_id = '77ea924eff03bff13a0039ed1f465361344953';
$resume = $hh_client->getResume($resume_id);
$resume['last_name'] = 'Иванов';
$hh_client->updateResume($resume_id, $resume);

发布简历

要发布新的简历,需要创建 Resume 类的对象并填写必填字段。然后,将对象传递给基本客户端的 createResume 方法。

$resume = new Resume();
$resume->setFirstName('Иван');
$resume->setLastName('Иванов');
$resume->setTitle('Кассир');
$resume->setArea([
    'id' => '4',
    'name' => 'Новосибирск',
    'url' => 'https://api.hh.ru/areas/4',
]);
$resume->setGender([
    'id' => 'male',
    'name' => 'Мужской',
]);
$resume->setResumeLocale([
    'id' => 'RU',
    'name' => 'Русский',
]);
$resume->setCitizenship([
    [
        'id' => '113',
        'name' => 'Россия',
        'url' => 'https://api.hh.ru/areas/113',
    ]
]);
$resume->setAccess([
    'type' => [
        'id' => 'direct',
        'name' => 'доступно только по прямой ссылке',
    ]
]);
...

$client->createResume($resume);

部分字段使用目录中的元素填充。有关详细信息,请参阅链接 https://github.com/hhru/api/blob/master/docs/resumes.md#create_edit

目录

用于获取目录的一组 ApplicantClient 类方法。
getDictionaries - 主要目录;
getAreas - 地区目录;
getSpecializations - 专业目录;
getLanguages - 语言目录;
getMetros - 地铁目录;
getLocales - 简历本地化目录。

ApplicantClient 类的额外方法

getNewResumeConditions - 创建简历字段的条件;
getResumeConditions - 更新简历字段的条件;
getApplicantAgreement - 劳动力就业服务协议;
deleteResume - 删除简历;
publishResume - 创建后发布简历。

ApplicationClient(应用程序客户端)

获取应用程序令牌

要调用 ApplicationClient 类的方法,需要获取应用程序令牌。应用程序令牌只需要生成一次。如果令牌被泄露,则需要再次请求。在此过程中,之前颁发的令牌将被撤销。

$application_client = new ApplicationClient('%client_id%', '%client_secret%');
$application_token = $application_client->generateApplicationToken();

注册新的求职者

注册用户使用 ApplicationClient 类。在构造函数中需要传递 client_id、client_secret 和应用程序令牌。

$application_client = new ApplicationClient('%client_id%', '%client_secret%', '%application_token%');

createUser 方法接受以下参数:电子邮件地址(用户名)、姓名、姓氏和名字(可选)。

$login = 'example@example.com';
$first_name = 'Иван';
$last_name = 'Иванов';
$middle_name = 'Иванович';
$application_client->createUser($login, $first_name, $last_name, $middle_name);

要求

  • php ^7.3|^8.0
  • ext-json *

HeadHunter API 文档

https://github.com/hhru/api