PHPackages                             codek365/zalo-php-sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. codek365/zalo-php-sdk

ActiveProject[API Development](/categories/api)

codek365/zalo-php-sdk
=====================

sdk for zalo developers

2.0.1(6y ago)05Zalo PlatformPHPPHP &gt;=5.4

Since Oct 24Pushed 6y agoCompare

[ Source](https://github.com/Codek365/zalo-php-sdk-fix-bugs)[ Packagist](https://packagist.org/packages/codek365/zalo-php-sdk)[ RSS](/packages/codek365-zalo-php-sdk/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (8)Used By (0)

Zalo SDK for PHP (v2.0.0)
=========================

[](#zalo-sdk-for-php-v200)

Landing page: [](https://developers.zalo.me/)
**Blog:** there are lots of great tutorials and guides published in our [Official Zalo Platform Blog](https://developers.zalo.me/docs/) and we are adding new content regularly.
**Community:** If you are having trouble using some feature, the best way to get help is the [Zalo Community](https://developers.zalo.me/community/)
**Support:** We are also available to answer short questions on Zalo at [Official Account Zalo For Developers](https://zalo.me/zalo4developers)

Installation
------------

[](#installation)

The Zalo PHP SDK can be installed with [Composer](https://getcomposer.org/). Run this command:

```
composer require codek365/zalo-php-sdk-fix-bugs
```

How To Use
----------

[](#how-to-use)

**Import Autoload**

```
require_once __DIR__ . '/vendor/autoload.php';
```

**Khởi tạo**

```
use Zalo\Zalo;

$config = array(
    'app_id' => '1234567890987654321',
    'app_secret' => 'AbC123456XyZ',
    'callback_url' => 'https://www.callback.com'
);
$zalo = new Zalo($config);
```

Social API
----------

[](#social-api)

***Lấy link đăng nhập***

```
$helper = $zalo -> getRedirectLoginHelper();
$callbackUrl = "https://www.callbackack.com";
$loginUrl = $helper->getLoginUrl($callBackUrl); // This is login url
```

**Lấy access token**

> Khi người dùng click vào link đăng nhập, Hệ thống sẽ thực hiện xử lý đăng nhập cho người dùng và chuyển hướng về link callback đã đăng ký với app, OAuth code sẽ được trả về và hiển thị trên đường dẫn của link callback , Hãy đặt đoạn mã dưới tại link callback bạn đã đăng ký với app, đoạn mã sẽ thực hiện lấy oauth code từ link callback và gửi yêu cầu lên hệ thống để lấy access token.

```
$callBackUrl = "www.put_your_call_backack_url_here.com";
$oauthCode = isset($_GET['code']) ? $_GET['code'] : "THIS NOT CALLBACK PAGE !!!"; // get oauthoauth code from url params
$accessToken = $helper->getAccessToken($callBackUrl); // get access token
if ($accessToken != null) {
    $expires = $accessToken->getExpiresAt(); // get expires time
}
```

**Lấy thông tin người dùng**

```
$accessToken = 'put_your_access_token_here';
$params = ['fields' => 'id,name,birthday,gender,picture'];
$response = $zalo->get(ZaloEndpoint::API_GRAPH_ME, $accessToken, $params);
$result = $response->getDecodedBody(); // result
```

**Lấy danh sách bạn bè**

```
$accessToken = 'put_your_access_token_here';
$params = ['offset' => 0, 'limit' => 10, 'fields' => "id, name"];
$response = $zalo->get(ZaloEndpoint::API_GRAPH_FRIENDS, $accessToken, $params);
$result = $response->getDecodedBody(); // result
```

**Lấy danh sách bạn bè chưa sử dụng ứng dụng và có thể nhắn tin mời sử dụng ứng dụng**

```
$accessToken = 'put_your_access_token_here';
$params = ['offset' => 0, 'limit' => 10, 'fields' => "id, name"];
$response = $zalo->get(ZaloEndpoint::API_GRAPH_INVITABLE_FRIENDS, $accessToken, $params);
$result = $response->getDecodedBody(); // result
```

**Đăng bài viết**

```
$accessToken = 'put_your_access_token_here';
$params = ['message' => 'put_your_text_here', 'link' => 'put_your_link_here'];
$response = $zalo->post(ZaloEndpoint::API_GRAPH_POST_FEED, $accessToken, $params);
$result = $response->getDecodedBody(); // result
```

**Mời sử dụng ứng dụng**

```
$accessToken = 'put_your_access_token_here';
$params = ['message' => 'put_your_message_here', 'to' => 'put_user_id_receive_here'];
$response = $zalo->post(ZaloEndpoint::API_GRAPH_APP_REQUESTS, $accessToken, $params);
$result = $response->getDecodedBody(); // result
```

**Gửi tin nhắn tới bạn bè**

```
$accessToken = 'put_your_access_token_here';
$params = ['message' => 'put_your_message_here', 'to' => 'put_user_id_receive_here', 'link' => 'put_your_link_here'];
$response = $zalo->post(ZaloEndpoint::API_GRAPH_MESSAGE, $accessToken, $params);
$result = $response->getDecodedBody(); // result
```

Official Account Open API
-------------------------

[](#official-account-open-api)

**Tạo link Offical Account ủy quyền cho ứng dụng**

```
$callbackPageUrl = "https://www.callbackPage.com"
$linkOAGrantPermission2App = $helper->getLoginUrlByPage($callbackPageUrl); // This is url for admin OA grant permission to app
```

**Gửi tin nhắn text**

```
// build data
$msgBuilder = new MessageBuilder('text');
$msgBuilder->withUserId('494021888309207992');
$msgBuilder->withText('Message Text');

// add buttons (only support 5 buttons - optional)
$actionOpenUrl = $msgBuilder->buildActionOpenURL('https://wwww.google.com'); // build action open link
$msgBuilder->withButton('Open Link', $actionOpenUrl);

$actionQueryShow = $msgBuilder->buildActionQueryShow('query_show'); // build action query show
$msgBuilder->withButton('Query Show', $actionQueryShow);

$actionQueryHide = $msgBuilder->buildActionQueryHide('query_hide'); // build action query hide
$msgBuilder->withButton('Query Hide', $actionQueryHide);

$actionOpenPhone = $msgBuilder->buildActionOpenPhone('0919018791'); // build action open phone
$msgBuilder->withButton('Open Phone', $actionOpenPhone);

$actionOpenSMS = $msgBuilder->buildActionOpenSMS('0919018791', 'sms text'); // build action open sms
$msgBuilder->withButton('Open SMS', $actionOpenSMS);

$msgText = $msgBuilder->build();
// send request
$response = $zalo->post(ZaloEndpoint::API_OA_SEND_MESSAGE, $accessToken, $msgText);
$result = $response->getDecodedBody(); // result
```

**Gửi tin nhắn hình**

```
// build data
$msgBuilder = new MessageBuilder('media');
$msgBuilder->withUserId('494021888309207992');
$msgBuilder->withText('Message Image');
$msgBuilder->withAttachment('cb2ab1696b688236db79');

// add buttons (only support 5 buttons - optional)
$actionOpenUrl = $msgBuilder->buildActionOpenURL('https://wwww.google.com'); // build action open link
$msgBuilder->withButton('Open Link', $actionOpenUrl);

$actionQueryShow = $msgBuilder->buildActionQueryShow('query_show'); // build action query show
$msgBuilder->withButton('Query Show', $actionQueryShow);

$actionQueryHide = $msgBuilder->buildActionQueryHide('query_hide'); // build action query hide
$msgBuilder->withButton('Query Hide', $actionQueryHide);

$actionOpenPhone = $msgBuilder->buildActionOpenPhone('0919018791'); // build action open phone
$msgBuilder->withButton('Open Phone', $actionOpenPhone);

$actionOpenSMS = $msgBuilder->buildActionOpenSMS('0919018791', 'sms text'); // build action open sms
$msgBuilder->withButton('Open SMS', $actionOpenSMS);

$msgImage = $msgBuilder->build();
$response = $zalo->post(ZaloEndpoint::API_OA_SEND_MESSAGE, $accessToken, $msgImage);
$result = $response->getDecodedBody(); // result
```

**Gửi tin nhắn list**

```
$msgBuilder = new MessageBuilder('list');
$msgBuilder->withUserId('494021888309207992');

$actionOpenUrl = $msgBuilder->buildActionOpenURL('https://www.google.com');
$msgBuilder->withElement('Open Link Google', 'https://img.icons8.com/bubbles/2x/google-logo.png', 'Search engine', $actionOpenUrl);

$actionQueryShow = $msgBuilder->buildActionQueryShow('query_show');
$msgBuilder->withElement('Query Show', 'https://www.computerhope.com/jargon/q/query.jpg', '', $actionQueryShow);

$actionQueryHide = $msgBuilder->buildActionQueryHide('query_hide');
$msgBuilder->withElement('Query Hide', 'https://www.computerhope.com/jargon/q/query.jpg', '', $actionQueryHide);

$actionOpenPhone = $msgBuilder->buildActionOpenPhone('0919018791');
$msgBuilder->withElement('Open Phone', 'https://cdn.iconscout.com/icon/premium/png-256-thumb/phone-275-123408.png', '', $actionOpenPhone);

$actionOpenSMS = $msgBuilder->buildActionOpenSMS('0919018791', 'sms text');
$msgBuilder->withElement('Open SMS', 'https://cdn0.iconfinder.com/data/icons/new-design/512/42-Chat-512.png', '', $actionOpenSMS);

$msgList = $msgBuilder->build();
$response = $zalo->post(ZaloEndpoint::API_OA_SEND_MESSAGE, $accessToken, $msgList);
$result = $response->getDecodedBody(); // result
```

**Gửi tin nhắn dạng Gif**

```
$msgBuilder = new MessageBuilder('media');
$msgBuilder->withUserId('494021888309207992');
$msgBuilder->withText('Message Image');
$msgBuilder->withAttachment('PWhbF13YGGi9VTkG/vHcTyoskajfj5Ve/EGsTK80XYo=');
$msgBuilder->withMediaType('gif');
$msgBuilder->withMediaSize(120, 120);
$msgImage = $msgBuilder->build();

$response = $zalo->post(ZaloEndpoint::API_OA_SEND_MESSAGE, $accessToken, $msgImage);
$result = $response->getDecodedBody(); // result
```

**Gửi File**

```
$msgBuilder = new MessageBuilder('file');
$msgBuilder->withUserId('494021888309207992');
$msgBuilder->withFileToken('call_upload_file_api_to_get_file_token');
$msgFile = $msgBuilder->build();
$response = $zalo->post(ZaloEndPoint::API_OA_SEND_MESSAGE, $accessToken, $msgFile);
$result = $response->getDecodedBody(); // result
```

**Gửi tin nhắn mời quan tâm**

```
// build data
$msgBuilder = new MessageBuilder('template');
$msgBuilder->withPhoneNumber('0919018791');
$msgBuilder->withTemplate('87efbc018044691a3055', []);
$msgInvite = $msgBuilder->build();
// send request
$response = $zalo->post(ZaloEndPoint::API_OA_SEND_MESSAGE, $accessToken, $msgInvite);
$result = $response->getDecodedBody();
```

**Upload hình**

```
$data = array('file' => new ZaloFile($filePath));
$response = $zalo->post(ZaloEndpoint::API_OA_UPLOAD_PHOTO, $accessToken, $data);
$result = $response->getDecodedBody(); // result
```

**Upload hình Gif**

```
$data = array('file' => new ZaloFile($filePath));
$response = $zalo->post(ZaloEndpoint::API_OA_UPLOAD_GIF, $accessToken, $data);
$result = $response->getDecodedBody(); // result
```

**Upload file PDF**

```
$data = array('file' => new ZaloFile($filePath));
$response = $zalo->post(ZaloEndpoint::API_OA_UPLOAD_FILE, $accessToken, $data);
$result = $response->getDecodedBody(); // result
```

**Lấy danh sách nhãn**

```
$response = $zalo->get(ZaloEndpoint::API_OA_GET_LIST_TAG, $accessToken, []);
$result = $response->getDecodedBody();
```

**Xóa nhãn**

```
// build data
$data = array('tag_name' => 'vip');
// send request
$response = $zalo->post(ZaloEndpoint::API_OA_REMOVE_TAG, $accessToken, $data);
$result = $response->getDecodedBody();
```

**Gỡ người quan tâm khỏi nhãn**

```
// build data
$data = array(
        'user_id' => '494021888309207992',
        'tag_name' => 'vip'
);
// send request
$response = $zalo->post(ZaloEndpoint::API_OA_REMOVE_USER_FROM_TAG, $accessToken, $data);
$result = $response->getDecodedBody();
```

**Gán nhãn người quan tâm**

```
// build data
$data = array(
        'user_id' => '494021888309207992',
        'tag_name' => 'vip'
);
// send request
$response = $zalo->post(ZaloEndpoint::API_OA_TAG_USER, $accessToken, $data);
$result = $response->getDecodedBody();
```

**Lấy thông tin người quan tâm**

```
$data = ['data' => json_encode(array(
            'user_id' => '494021888309207992'
        ))];
$response = $zalo->get(ZaloEndpoint::API_OA_GET_USER_PROFILE, $accessToken, $data);
$result = $response->getDecodedBody(); // result
```

**Lấy thông tin OA**

```
$response = $zalo->get(ZaloEndPoint::API_OA_GET_PROFILE, $accessToken, []);
$result = $response->getDecodedBody(); // result
```

**Lấy danh sách người quan tâm**

```
$data = ['data' => json_encode(array(
                'offset' => 0,
                'count' => 10
            ))];
$response = $this->zalo->get(ZaloEndPoint::API_OA_GET_LIST_FOLLOWER, $accessToken, $data);
$result = $response->getDecodedBody(); // result
```

**Lấy danh sách tin nhắn gần nhất**

```
$data = ['data' => json_encode(array(
                'offset' => 0,
                'count' => 10
            ))];
$response = $zalo->get(ZaloEndPoint::API_OA_GET_LIST_RECENT_CHAT, $accessToken, $data);
$result = $response->getDecodedBody(); // result
```

**Lấy danh sách tin nhắn với người quan tâm**

```
$data = ['data' => json_encode(array(
                'user_id' => 494021888309207992,
                'offset' => 0,
                'count' => 10
            ))];
$response = $zalo->get(ZaloEndPoint::API_OA_GET_CONVERSATION, $accessToken, $data);
$result = $response->getDecodedBody(); // result
```

Versioning
----------

[](#versioning)

Current version is 2.0.0. We will update more features in next version.

Authors
-------

[](#authors)

- **Zalo's Developer**

License
-------

[](#license)

This project is licensed under the MIT License.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 54.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~131 days

Recently: every ~157 days

Total

6

Last Release

2462d ago

Major Versions

1.0.3 → 2.0.02019-07-29

### Community

Maintainers

![](https://www.gravatar.com/avatar/85ae62add1e1da0565ede1aa8ecc588922ed65c6a3cc4851f9d98fbe71242ded?d=identicon)[Codek365](/maintainers/Codek365)

---

Top Contributors

[![zaloplatform](https://avatars.githubusercontent.com/u/32472863?v=4)](https://github.com/zaloplatform "zaloplatform (13 commits)")[![nirvana369](https://avatars.githubusercontent.com/u/5562143?v=4)](https://github.com/nirvana369 "nirvana369 (6 commits)")[![Codek365](https://avatars.githubusercontent.com/u/14676526?v=4)](https://github.com/Codek365 "Codek365 (4 commits)")[![nguoianhcuanui](https://avatars.githubusercontent.com/u/8149021?v=4)](https://github.com/nguoianhcuanui "nguoianhcuanui (1 commits)")

---

Tags

composersdkzalozalosdk

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/codek365-zalo-php-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/codek365-zalo-php-sdk/health.svg)](https://phpackages.com/packages/codek365-zalo-php-sdk)
```

###  Alternatives

[zaloplatform/zalo-php-sdk

sdk for zalo developers

69119.0k1](/packages/zaloplatform-zalo-php-sdk)[mocking-magician/coinbase-pro-sdk

Library for coinbase pro API calls

233.2k](/packages/mocking-magician-coinbase-pro-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
