conghau/zalo-php-sdk

conghau 从 zalo sdk 分支出来

安装: 68

依赖者: 0

建议者: 0

安全性: 0

星标: 0

关注者: 4

分支: 41

类型:项目

1.0.5 2018-12-27 05:19 UTC

This package is not auto-updated.

Last update: 2024-09-29 08:11:45 UTC


README

安装

可以使用 Composer 安装 Zalo PHP SDK。运行以下命令

composer require zaloplatform/zalo-php-sdk

如何使用

导入自动加载 

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

配置

配置文件 -> ZaloConfig.php

/** config your app id here */
const ZALO_APP_ID_CFG = "put_your_app_id_here";
    
/** config your app secret key here */
const ZALO_APP_SECRET_KEY_CFG = "put_your_secret_key_here";

/** config your offical account id here */
const ZALO_OA_ID_CFG = "put_your_oa_id_here";

/** config your offical account secret key here */
const ZALO_OA_SECRET_KEY_CFG = "put_your_oa_secret_key_here";

创建 Zalo 类的实例

use Zalo\Zalo;
use Zalo\ZaloConfig;

$zalo = new Zalo(ZaloConfig::getInstance()->getConfig());

社交API

获取登录链接

$helper = $zalo -> getRedirectLoginHelper();
$callBackUrl = "www.put_your_call_backack_url_here.com";
$loginUrl = $helper->getLoginUrl($callBackUrl); // This is login url

获取访问令牌

当用户点击登录链接时,系统将处理用户登录并将用户重定向到与app注册的回调链接,OAuth代码将被返回并显示在回调链接的路径上。请将以下代码放置在您与app注册的回调链接中,该代码将从回调链接中获取OAuth代码并将请求发送到系统以获取访问令牌。

$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
}

获取用户信息

$accessToken = 'put_your_access_token_here';
$params = [];
$response = $zalo->get(ZaloEndpoint::API_GRAPH_ME, $params, $accessToken);
$result = $response->getDecodedBody(); // result

获取朋友列表

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

获取未使用应用的朋友列表和可能发送邀请使用应用的朋友

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

发布文章

$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, $params, $accessToken);
$result = $response->getDecodedBody(); // result

邀请使用应用

$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, $params, $accessToken);
$result = $response->getDecodedBody(); // result

向朋友发送消息

$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, $params, $accessToken);
$result = $response->getDecodedBody(); // result

官方账号开放API

发送关注邀请消息

$templateData = array(
    'template_key' => "template_value"
);
$data = array(
    'phone' => 84912345678,
    'templateid' => "put_template_id_here",
    'templatedata' => $templateData,
    'callbackdata' => "put_your_call_back_link_here"
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_SEND_FOLLOW_MSG, $params);
$result = $response->getDecodedBody();

获取标签列表

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

删除标签

$data = array(
    'tagName' => "put_tag_name_here"
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_REMOVE_TAG, $params);
$result = $response->getDecodedBody();

从标签中移除关注者

$data = array(
    'uid' => 0,
    'tagName' => "put_tag_name_here"
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_REMOVE_USER_FROM_TAG, $params);
$result = $response->getDecodedBody();

给关注者添加标签

$data = array(
    'uid' => 0,
    'tagName' => "put_tag_name_here"
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_TAG_USER, $params);
$result = $response->getDecodedBody();

发送文本消息

$data = array(
    'uid' => 1785179753369910605, // user id
    'message' => 'put_your_text_message_here'
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_SEND_TEXT_MSG, $params);
$result = $response->getDecodedBody(); // result

发送图片消息

 $data = array(
    'uid' => 1785179753369910605, // user id
    'imageid' => 'put_your_uploaded_image_id',
    'message' => 'put_your_text_message_here'
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_SEND_PHOTO_MSG, $params);
$result = $response->getDecodedBody(); // result

发送链接消息

$firstLink = array('link' => 'put_url_here',
    'linktitle' => 'put_title_here',
    'linkdes' => 'put_description_here',
    'linkthumb' => 'put_thumbnail_url_here');
    
$secondLink = array('link' => 'put_url_here',
    'linktitle' => 'put_title_here',
    'linkdes' => 'put_description_here',
    'linkthumb' => 'put_thumbnail_url_here');
    
$data = array(
    'uid' => 1785179753369910605, // uid
    'links' => [$firstLink, $secondLink],
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_SEND_LINK_MSG, $params);
$result = $response->getDecodedBody(); // result

发送交互消息

$firstAction = array('action' => 'oa.query.show',
    'title' => 'put_title_here',
    'description' => 'put_description_here',
    'data' => 'reply_message_when_user_click',
    'href' => 'put_url_here',
    'thumb' => 'put_thumbnail_url_here');

$popupForSecondAction = array('title' => 'put_title_here',
    'desc' => 'put_description_here',
    'ok' => 'title_of_ok_button',
    'cancel' => 'title_of_cancel_button'
);
$secondAction = array('action' => 'oa.query.show',
    'title' => 'put_title_here',
    'description' => 'put_description_here',
    'data' => 'reply_message_when_user_click',
    'href' => 'put_url_here',
    'thumb' => 'put_thumbnail_url_here',
    'popup' => $popupForSecondAction);

$data = array(
    'uid' => 1785179753369910605, // user id
    'actionlist' => [$firstAction, $secondAction],
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_SEND_ACTION_MSG, $params);
$result = $response->getDecodedBody(); // result

发送Gif消息

$data = array(
    'uid' => 1785179753369910605, // put_user_id_here
    'imageid' => "put_image_id_here",
    'width' => 200,
    'height' => 200
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_SEND_GIF_MSG, $params);
$result = $response->getDecodedBody(); // result

获取关注者信息

$params = ['uid' => 1785179753369910605]; // put user id here
$response = $zalo->get(ZaloEndpoint::API_OA_GET_PROFILE, $params);
$result = $response->getDecodedBody(); // result

上传图片

$filePath = 'path_to_image';
$params = ['file' => new ZaloFile($filePath)];
$response = $zalo->post(ZaloEndpoint::API_OA_UPLOAD_PHOTO, $params);
$result = $response->getDecodedBody(); // result

上传Gif图片

$filePath = 'path_to_image';
$params = ['file' => new ZaloFile($filePath)];
$response = $zalo->post(ZaloEndpoint::API_OA_UPLOAD_GIF, $params);
$result = $response->getDecodedBody(); // result

获取消息状态

$params = ['msgid' => 'put_message_id_here'];
$response = $zalo->get(ZaloEndpoint::API_OA_GET_MSG_STATUS, $params);
$result = $response->getDecodedBody(); // result

发送客服消息

$templateData = array(
    'username' => 'put_your_template_data_here', // request Offical Account Admin to get template data
    'invitename' => 'put_your_template_data_here'
);
$data = array(
    'uid' => 1785179753369910605, // user id
    'templateid' => 'put_your_template_id_here', // request Offical Account Admin to get template id
    'templatedata' => $templateData
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_SEND_CUSTOMER_CARE_MSG, $params);
$result = $response->getDecodedBody(); // result

通过电话发送客服消息

$templateData = array(
    'username' => 'put_your_template_data_here', // request Offical Account Admin to get template data
    'invitename' => 'put_your_template_data_here'
);
$data = array(
    'phone' => 84919018791, // phone number or user id
    'templateid' => 'put_your_template_id_here', // request Offical Account Admin to get template id
    'templatedata' => $templateData
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_SEND_CUSTOMER_CARE_MSG_BY_PHONE, $params);
$result = $response->getDecodedBody(); // result

以文本形式回复消息

$data = array(
    'msgid' => "put_message_id_here",
    'message' => "put_message_here"
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_REPLY_TEXT_MSG, $params);
$result = $response->getDecodedBody(); // result

以图片形式回复消息

$data = array(
    'msgid' => "put_message_id_here",
    'imageid' => "put_image_id_here",
    'message' => "put_message_here"
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_REPLY_PHOTO_MSG, $params);
$result = $response->getDecodedBody(); // result

以链接形式回复消息

$firstLink = array('link' => 'put_link_here',
    'linktitle' => 'put_title_here',
    'linkdes' => 'put_description_here',
    'linkthumb' => 'put_thumnail_link_here');
$secondLink = array('link' => 'https://developers.zalo.me/docs/',
    'linktitle' => 'Documents for zalo developers',
    'linkdes' => 'Zalo for developer comunity',
    'linkthumb' => 'https://cms.developers.zalo.me/wp-content/uploads/2017/06/Oauth2.jpg');
$data = array(
    'msgid' => "put_message_id_here",
    'links' => [$firstLink, $secondLink],
);
$params = ['data' => $data];
$response = $this->zalo->post(ZaloEndpoint::API_OA_REPLY_LINK_MSG, $params);
$result = $response->getDecodedBody(); // result

创建二维码

$data = array(
    'qrdata' => "put_data_here",
    'size' => 1000, // put_size_here
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_CREATE_QR_CODE, $params);
$result = $response->getDecodedBody(); // result

官方账号开放API Onbehalf

当用户点击登录链接时,系统将处理用户登录,并请求授权访问官方账号的信息,当用户同意授权后,系统将重定向到与app注册的回调链接,系统将返回访问令牌并显示在回调链接上。

获取登录链接

$helper = $zalo -> getRedirectLoginHelper();
$callBackUrl = "www.put_your_call_backack_url_here.com";
$loginUrl = $helper->getLoginUrlByPage($callBackUrl); // This is login url

获取关注者信息

$accessToken = "put_access_token_here";
$data = array(
    'uid' => 0 // put user id here
);
$params = ['data' => $data];
$response = $zalo->get(ZaloEndpoint::API_OA_ONBEHALF_GET_PROFILE, $params, $accessToken);
$result = $response->getDecodedBody(); // result

获取OA信息

$accessToken = "put_access_token_here";
$params = [];
$response = $zalo->get(ZaloEndpoint::API_OA_ONBEHALF_GET_OA, $params, $accessToken);
$result = $response->getDecodedBody(); // result

获取关注者与OA之间的对话

$accessToken = "put_access_token_here";
$data = array(
    'uid' => 0, // put user id here
    'offset' => 0,
    'count' => 10
);
$params = ['data' => $data];
$response = $zalo->get(ZaloEndpoint::API_OA_ONBEHALF_CONVERSATION, $params, $accessToken);
$result = $response->getDecodedBody(); // result

获取刚刚与OA聊过天的关注者列表

$accessToken = "put_access_token_here";
$data = array(
    'offset' => 0,
    'count' => 10
);
$params = ['data' => $data];
$response = $zalo->get(ZaloEndpoint::API_OA_ONBEHALF_RECENT_CHAT, $params, $accessToken);
$result = $response->getDecodedBody(); // result

发送文本消息

$accessToken = "put_access_token_here";
$data = array(
    'uid' => 0, // put user id here
    'message' => "put_message_here"
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_ONBEHALF_SEND_TEXT_MSG, $params, $accessToken);
$result = $response->getDecodedBody(); // result

发送图片消息

$accessToken = "put_access_token_here";
$data = array(
    'uid' => 0, // put user id here
    'message' => "put_message_here",
    'imageid' => "put_image_id_here"
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_ONBEHALF_SEND_PHOTO_MSG, $params, $accessToken);
$result = $response->getDecodedBody(); // result

发送链接消息

$accessToken = "put_access_token_here";
$firstLink = array('link' => 'put_url_here',
    'linktitle' => 'put_title_here',
    'linkdes' => 'put_description_here',
    'linkthumb' => 'put_thumbnail_url_here');
    
$secondLink = array('link' => 'put_url_here',
    'linktitle' => 'put_title_here',
    'linkdes' => 'put_description_here',
    'linkthumb' => 'put_thumbnail_url_here');
    
$data = array(
    'uid' => 0, // uid
    'links' => [$firstLink, $secondLink],
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_ONBEHALF_SEND_LINK_MSG, $params, $accessToken);
$result = $response->getDecodedBody(); // result

发送交互消息

$accessToken = "put_access_token_here";
$firstAction = array('action' => 'oa.query.show',
    'title' => 'put_title_here',
    'description' => 'put_description_here',
    'data' => 'reply_message_when_user_click',
    'href' => 'put_url_here',
    'thumb' => 'put_thumbnail_url_here');

$popupForSecondAction = array('title' => 'put_title_here',
    'desc' => 'put_description_here',
    'ok' => 'title_of_ok_button',
    'cancel' => 'title_of_cancel_button'
);
$secondAction = array('action' => 'oa.query.show',
    'title' => 'put_title_here',
    'description' => 'put_description_here',
    'data' => 'reply_message_when_user_click',
    'href' => 'put_url_here',
    'thumb' => 'put_thumbnail_url_here',
    'popup' => $popupForSecondAction
);
$data = array(
    'uid' => 0, // user id
    'actionlist' => [$firstAction, $secondAction],
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_ONBEHALF_SEND_ACTION_MSG, $params, $accessToken);
$result = $response->getDecodedBody(); // result

发送Gif消息

$accessToken = "put_access_token_here";
$data = array(
    'uid' => 0, // put user id here
    'imageid' => "put_image_id_here",
    'width' => 0, // put image width
    'height' => 0 // put image height
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_ONBEHALF_SEND_GIF_MSG, $params, $accessToken);
$result = $response->getDecodedBody(); // result

上传图片

$accessToken = "put_access_token_here";
$filePath = 'path_to_image';
$params = ['file' => new ZaloFile($filePath)];
$response = $zalo->post(ZaloEndpoint::API_OA_ONBEHALF_UPLOAD_PHOTO, $params, $accessToken);
$result = $response->getDecodedBody(); // result

上传Gif图片

$accessToken = "put_access_token_here";
$filePath = 'path_to_image';
$params = ['file' => new ZaloFile($filePath)];
$response = $zalo->post(ZaloEndpoint::API_OA_ONBEHALF_UPLOAD_GIF, $params, $accessToken);
$result = $response->getDecodedBody(); // result

以文本形式回复消息

$accessToken = "put_access_token_here";
$data = array(
    'msgid' => "put_message_id_here",
    'message' => "put_message_id_here"
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_ONBEHALF_REPLY_TEXT_MSG, $params, $accessToken);
$result = $response->getDecodedBody(); // result

以图片形式回复消息

$accessToken = "put_access_token_here";
$data = array(
    'msgid' => "put_message_id_here",
    'imageid' => "put_image_id_here",
    'message' => "put_message_id_here"
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_ONBEHALF_REPLY_PHOTO_MSG, $params, $accessToken);
$result = $response->getDecodedBody(); // result

以链接形式回复消息

$accessToken = "put_access_token_here";
$firstLink = array('link' => 'put_link_here',
    'linktitle' => 'put_title_here',
    'linkdes' => 'put_description_here',
    'linkthumb' => 'put_thumbnail_link_here'
);
$secondLink = array('link' => 'https://developers.zalo.me/docs/',
    'linktitle' => 'Documents for zalo developers',
    'linkdes' => 'Zalo for developer comunity',
    'linkthumb' => 'https://cms.developers.zalo.me/wp-content/uploads/2017/06/Oauth2.jpg'
);
$data = array(
    'msgid' => "put_message_id_here",
    'links' => [$firstLink, $secondLink],
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_ONBEHALF_REPLY_LINK_MSG, $params, $accessToken);
$result = $response->getDecodedBody(); // result

商店API

编辑变体

$variation = array(
    'variationid' => "put_variation_id_here",
    'default' => 1, // 1 (enable), 2 (disable)
    'price' => 0.5,
    'name' => "put_variation_name_here",
    'status' => 2  // 2: Enable, 3: Disable
);
$data = array(
    'variation' => $variation
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_STORE_UPDATE_VARIATION, $params);
$result = $response->getDecodedBody();

将变体添加到产品

$variationOne = array(
    'default' => 1, // 1 (enable), 2 (disable)
    'price' => 4,
    'name' => "put_variation_name_here",
    'attributes' => ["put_attribute_id_x1_here", "put_attribute_id_x2_here", "put_attribute_id_x3_here", "put_attribute_id_x4_here"]
);
$variationTwo = array(
    'default' => 2,
    'price' => 5,
    'name' => "put_variation_name_here",
    'attributes' => ["put_attribute_id_y1_here", "put_attribute_id_y2_here", "put_attribute_id_y3_here", "put_attribute_id_y4_here"]
);
$data = array(
    'productid' => "put_product_id_here",
    'variations' => [$variationOne, $variationTwo]
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_STORE_ADD_VARIATION, $params);
$result = $response->getDecodedBody();

获取产品属性信息

$data = array(
    'attributeids' => ["put_attribute_id_1_here", "put_attribute_id_2_here"]
);
$params = ['data' => $data];
$response = $zalo->get(ZaloEndpoint::API_OA_STORE_GET_ATTRIBUTE_INFO, $params);
$result = $response->getDecodedBody();

获取产品属性列表

$data = array(
    'offset' => 0,
    'count' => 10
);
$params = ['data' => $data];
$response = $zalo->get(ZaloEndpoint::API_OA_STORE_GET_SLICE_ATTRIBUTE, $params);
$result = $response->getDecodedBody();

编辑产品属性

$data = array(
    'attributeid' => "put_attribute_id_here",
    'name' => "put_attribute_name_here"
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_STORE_UPDATE_ATTRIBUTE, $params);
$result = $response->getDecodedBody();

创建产品属性

$data = array(
    'name' => "put_attribute_name_here",
    'type' => "put_attribute_type_id_here" // get from end point -> ZaloEndpoint::API_OA_STORE_GET_SLICE_ATTRIBUTE_TYPE
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_STORE_CREATE_ATTRIBUTE, $params);
$result = $response->getDecodedBody();

获取属性类型列表

$data = array(
    'offset' => 0,
    'count' => 10
);
$params = ['data' => $data];
$response = $zalo->get(ZaloEndpoint::API_OA_STORE_GET_SLICE_ATTRIBUTE_TYPE, $params);
$result = $response->getDecodedBody();

创建产品

$cate = array('cateid' => 'put_your_cate_id_here');
$cates = [$cate];
$photo = array('id' => 'put_your_image_id_here');
$photos = [$photo];
$data = array(
    'cateids' => $cates,
    'name' => 'put_your_product_name_here',
    'desc' => 'put_your_description_here',
    'code' => 'put_your_code_number_here',
    'price' => 15000,
    'photos' => $photos,
    'display' => 'show', // show | hide
    'payment' => 2 // 2 - enable | 3 - disable
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_STORE_CREATE_PRODUCT, $params);
$result = $response->getDecodedBody(); // result

编辑产品

$cate = array('cateid' => 'put_your_cate_id_here');
$cates = [$cate];
$photo = array('id' => 'put_your_image_id_here');
$photos = [$photo];
$productUpdate = array(
    'cateids' => $cates,
    'name' => 'put_your_product_name_here',
    'desc' => 'put_your_description_here',
    'code' => 'put_your_code_number_here',
    'price' => 15000,
    'photos' => $photos,
    'display' => 'show', // show | hide
    'payment' => 2 // 2 - enable | 3 - disable
);
$data = array(
    'productid' => 'put_your_product_id_here',
    'product' => $productUpdate
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_STORE_UPDATE_PRODUCT, $params);
$result = $response->getDecodedBody(); // result

删除产品

$params = ['productid' => 'put_product_id_here'];
$response = $zalo->post(ZaloEndpoint::API_OA_STORE_REMOVE_PRODUCT, $params);
$result = $response->getDecodedBody(); // result

获取产品信息

$data = array(
    'productid' => 'put_your_product_id_here'
);
$params = ['data' => $data];
$response = $zalo->get(ZaloEndpoint::API_OA_STORE_GET_PRODUCT, $params);
$result = $response->getDecodedBody(); // result

产品列表

$data = array(
    'offset' => '0',
    'count' => '10'
);
$params = ['data' => $data];
$response = $zalo->get(ZaloEndpoint::API_OA_STORE_GET_SLICE_PRODUCT, $params);
$result = $response->getDecodedBody(); // result

上传产品图片

$filePath = 'path_to_your_image';
$params = ['file' => new ZaloFile($filePath)];
$response = $zalo->post(ZaloEndpoint::API_OA_STORE_UPLOAD_PRODUCT_PHOTO, $params);
$result = $response->getDecodedBody(); // result

创建分类

$data = array(
    'name' => 'put_your_category_name_here',
    'desc' => 'put_your_description_here',
    'photo' => 'put_your_photo_id_here',
    'status' => 0 // 0 - show | 1 - hide
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_STORE_CREATE_CATEGORY, $params);
$result = $response->getDecodedBody(); // result

编辑分类

$categoryUpdate = array(
    'name' => 'put_your_category_name_here',
    'desc' => 'put_your_description_here',
    'photo' => 'put_your_photo_id_here',
    'status' => 1 // 0 - show | 1 - hide
);
$data = array(
    'categoryid' => 'put_your_category_id_here',
    'category' => $categoryUpdate
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_STORE_UPDATE_CATEGORY, $params);
$result = $response->getDecodedBody(); // result

分类列表

$data = array(
    'offset' => '0',
    'count' => '10'
);
$params = ['data' => $data];
$response = $zalo->get(ZaloEndpoint::API_OA_STORE_GET_SLICE_CATEGORY, $params);
$result = $response->getDecodedBody(); // result

上传分类图片

$filePath = 'path_to_your_image';
$params = ['file' => new ZaloFile($filePath)];
$response = $zalo->post(ZaloEndpoint::API_OA_STORE_UPLOAD_CATEGORY_PHOTO, $params);
$result = $response->getDecodedBody(); // result

编辑订单

$data = array(
    'orderid' => 'put_your_order_id_here',
    'status' => 2,
    'reason' => 'put_your_reason_here',
    'cancelReason' => 'put_your_reason_here'
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_STORE_UPDATE_ORDER, $params);
$result = $response->getDecodedBody(); // result

订单列表

$data = array(
    'offset' => 0,
    'count' => 10,
    'filter' => 0
);
$params = ['data' => $data];
$response = $zalo->get(ZaloEndpoint::API_OA_STORE_GET_SLICE_ORDER, $params);
$result = $response->getDecodedBody(); // result

获取订单信息

$params = ['orderid' => 'put_your_order_id_here'];
$response = $zalo->get(ZaloEndpoint::API_OA_STORE_GET_ORDER, $params);
$result = $response->getDecodedBody(); // result

商店API Onbehalf

当用户点击登录链接时,系统将处理用户登录,并请求授权访问官方账号的信息,当用户同意授权后,系统将重定向到与app注册的回调链接,系统将返回访问令牌并显示在回调链接上。

获取登录链接

$helper = $zalo -> getRedirectLoginHelper();
$callBackUrl = "www.put_your_call_backack_url_here.com";
$loginUrl = $helper->getLoginUrlByPage($callBackUrl); // This is login url

创建产品

$accessToken = "put_access_token_here";
$cate = array('cateid' => 'put_your_cate_id_here');
$cates = [$cate];
$photo = array('id' => 'put_your_image_id_here');
$photos = [$photo];
$data = array(
    'cateids' => $cates,
    'name' => 'put_your_product_name_here',
    'desc' => 'put_your_description_here',
    'code' => 'put_your_code_number_here',
    'price' => 15000,
    'photos' => $photos,
    'display' => 'show', // show | hide
    'payment' => 2 // 2 - enable | 3 - disable
);
$product = array('product' => $data);
$params = ['data' => $product];
$response = $zalo->post(ZaloEndpoint::API_OA_STORE_ONBEHALF_CREATE_PRODUCT, $params, $accessToken);
$result = $response->getDecodedBody(); // result

编辑产品

$accessToken = "put_access_token_here";
$cate = array('cateid' => 'put_your_cate_id_here');
$cates = [$cate];
$photo = array('id' => 'put_your_image_id_here');
$photos = [$photo];
$productUpdate = array(
    'cateids' => $cates,
    'name' => 'put_your_product_name_here',
    'desc' => 'put_your_description_here',
    'code' => 'put_your_code_number_here',
    'price' => 15000,
    'photos' => $photos,
    'display' => 'show', // show | hide
    'payment' => 2 // 2 - enable | 3 - disable
);
$data = array(
    'productid' => 'put_your_product_id_here',
    'product' => $productUpdate
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_STORE_ONBEHALF_UPDATE_PRODUCT, $params, $accessToken);
$result = $response->getDecodedBody(); // result

删除产品

$accessToken = "put_access_token_here";
$data = array(
    'productid' => 'put_your_product_id_here'
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_STORE_ONBEHALF_REMOVE_PRODUCT, $params, $accessToken);
$result = $response->getDecodedBody(); // result

获取产品信息

$accessToken = "put_access_token_here";
$data = array(
    'productid' => 'put_your_product_id_here'
);
$params = ['data' => $data];
$response = $zalo->get(ZaloEndpoint::API_OA_STORE_ONBEHALF_GET_PRODUCT, $params, $accessToken);
$result = $response->getDecodedBody(); // result

产品列表

$accessToken = "put_access_token_here";
$data = array(
    'offset' => '0',
    'count' => '10'
);
$params = ['data' => $data];
$response = $zalo->get(ZaloEndpoint::API_OA_STORE_ONBEHALF_GET_SLICE_PRODUCT, $params, $accessToken);
$result = $response->getDecodedBody(); // result

上传产品图片

$accessToken = "put_access_token_here";
$filePath = 'path_to_your_image';
$params = ['file' => new ZaloFile($filePath)];
$response = $zalo->post(ZaloEndpoint::API_OA_STORE_ONBEHALF_UPLOAD_PRODUCT_PHOTO, $params, $accessToken);
$result = $response->getDecodedBody(); // result

创建分类

$accessToken = "put_access_token_here";
$data = array(
    'name' => 'put_your_category_name_here',
    'desc' => 'put_your_description_here',
    'photo' => 'put_your_photo_id_here',
    'status' => 0 // 0 - show | 1 - hide
);
$category = array('category' => $data);
$params = ['data' => $category];
$response = $zalo->post(ZaloEndpoint::API_OA_STORE_ONBEHALF_CREATE_CATEGORY, $params, $accessToken);
$result = $response->getDecodedBody(); // result

编辑分类

$accessToken = "put_access_token_here";
$categoryUpdate = array(
    'name' => 'put_your_category_name_here',
    'desc' => 'put_your_description_here',
    'photo' => 'put_your_photo_id_here',
    'status' => 1 // 0 - show | 1 - hide
);
$data = array(
    'categoryid' => 'put_your_category_id_here',
    'category' => $categoryUpdate
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_STORE_ONBEHALF_UPDATE_CATEGORY, $params, $accessToken);
$result = $response->getDecodedBody(); // result

分类列表

$accessToken = "put_access_token_here";
$data = array(
    'offset' => '0',
    'count' => '10'
);
$params = ['data' => $data];
$response = $zalo->get(ZaloEndpoint::API_OA_STORE_ONBEHALF_GET_SLICE_CATEGORY, $params, $accessToken);
$result = $response->getDecodedBody(); // result

上传分类图片

$accessToken = "put_access_token_here";
$filePath = 'path_to_your_image';
$params = ['file' => new ZaloFile($filePath)];
$response = $zalo->post(ZaloEndpoint::API_OA_STORE_ONBEHALF_UPLOAD_CATEGORY_PHOTO, $params, $accessToken);
$result = $response->getDecodedBody(); // result

编辑订单

$accessToken = "put_access_token_here";
$data = array(
    'orderid' => 'put_your_order_id_here',
    'status' => 2,
    'reason' => 'put_your_reason_here',
    'cancelReason' => 'put_your_reason_here'
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_STORE_ONBEHALF_UPDATE_ORDER, $params, $accessToken);
$result = $response->getDecodedBody(); // result

订单列表

$accessToken = "put_access_token_here";
$data = array(
    'offset' => 0,
    'count' => 10,
    'filter' => 0
);
$params = ['data' => $data];
$response = $zalo->get(ZaloEndpoint::API_OA_STORE_ONBEHALF_GET_SLICE_ORDER, $params, $accessToken);
$result = $response->getDecodedBody(); // result

获取订单信息

$accessToken = "put_access_token_here";
$data = ['orderid' => 'put_your_order_id_here'];
$params = ['data' => $data];
$response = $zalo->get(ZaloEndpoint::API_OA_STORE_ONBEHALF_GET_ORDER, $params, $accessToken);
$result = $response->getDecodedBody(); // result

文章API

创建文章

$cover = array(
    'coverType' => 1, //  0 (photo) | 1 (video)
    'coverView' => 1, // 1 (horizontal), 2 (vertical), 3 (square)
    'videoId' => 'put_your_video_id_here',
    'status' => 'show'
);
$actionLink = array(
    'type' => 2, // 0 (link to web), 1 (link to image), 2 (link to video), 3 (link to audio)
    'label' => 'put_label_here',
    'url' => 'https://www.youtube.com/watch?v=jp3xBWgii8A&list=RDjp3xBWgii8A'
);
$paragraphText = array(
    'type' => 0,
    'content' => 'put_content_here'
);
$paragraphImage = array(
    'type' => 1,
    'url' => 'https://upload.wikimedia.org/wikipedia/commons/7/71/2010-kodiak-bear-1.jpg',
    'caption' => 'put_caption_here',
    'width' => 500,
    'height' => 300
);
$paragraphVideo = array(
    'type' => 3,
    'url' => 'https://www.youtube.com/watch?v=jp3xBWgii8A&list=RDjp3xBWgii8A',
    'category' => 'youtube',
    'caption' => 'put_caption_here'
);
$relatedArticle = array(
    'id' => 'put_media_id_here' // related article
);
$media = array(
    'title' => 'put_title_here',
    'author' => 'put_author_here',
    'cover' => $cover,
    'desc' => 'put_description_here',
    'actionLink' => $actionLink,
    'body' => [$paragraphText, $paragraphImage, $paragraphVideo],
    'relatedMedias' => [$relatedArticle],
    'status' => 'show'
);
$params = ['media' => $media];
$response = $zalo->post(ZaloEndpoint::API_OA_ARTICLE_CREATE_MEDIA, $params);
$result = $response->getDecodedBody(); // result

获取文章ID

$params = ['token' => 'put_token_here'];
$response = $zalo->post(ZaloEndpoint::API_OA_ARTICLE_GET_MEDIA_ID, $params);
$result = $response->getDecodedBody(); // result

编辑文章

$cover = array(
    'coverType' => 1, //  0 (photo) | 1 (video)
    'coverView' => 1, // 1 (horizontal), 2 (vertical), 3 (square)
    'videoId' => 'put_your_video_id_here',
    'status' => 'show'
);
$actionLink = array(
    'type' => 2, // 0 (link to web), 1 (link to image), 2 (link to video), 3 (link to audio)
    'label' => 'put_label_here',
    'url' => 'https://www.youtube.com/watch?v=jp3xBWgii8A&list=RDjp3xBWgii8A'
);
$paragraphText = array(
    'type' => 0,
    'content' => 'put_content_here'
);
$paragraphImage = array(
    'type' => 1,
    'url' => 'https://upload.wikimedia.org/wikipedia/commons/7/71/2010-kodiak-bear-1.jpg',
    'caption' => 'put_caption_here',
    'width' => 500,
    'height' => 300
);
$paragraphVideo = array(
    'type' => 3,
    'url' => 'https://www.youtube.com/watch?v=jp3xBWgii8A&list=RDjp3xBWgii8A',
    'category' => 'youtube',
    'caption' => 'put_caption_here'
);
$relatedArticle = array(
    'id' => 'put_media_id_here' // related article
);
$media = array(
    'title' => 'put_title_here',
    'author' => 'put_author_here',
    'cover' => $cover,
    'desc' => 'put_description_here',
    'actionLink' => $actionLink,
    'body' => [$paragraphText, $paragraphImage, $paragraphVideo],
    'relatedMedias' => [$relatedArticle],
    'status' => 'show'
);
$data = array(
    'mediaid' => 'put_media_id_here',
    'media' => $media
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_ARTICLE_UPDATE_MEDIA, $params);
$result = $response->getDecodedBody(); // result

删除文章

$params = ['mediaid' => 'put_media_id_here'];
$response = $zalo->post(ZaloEndpoint::API_OA_ARTICLE_REMOVE_MEDIA, $params);
$result = $response->getDecodedBody(); // result

获取文章列表

$data = array(
    'offset' => 0,
    'count' => 10
);
$params = ['data' => $data];
$response = $zalo->get(ZaloEndpoint::API_OA_ARTICLE_GET_SLICE_MEDIA, $params);
$result = $response->getDecodedBody(); // result

广播文章

$target = array(
    'gender' => '1',
    'ages' => '1,2,3'
);
$firstArticle = array(
    'id' => 'put_article_id_here'
);
$secondArticle = array(
    'id' => 'put_article_id_here'
);
$data = array(
    'mediaIds' => [$firstArticle, $secondArticle],
    'target' => $target
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_ARTICLE_BROADCAST_MEDIA, $params);
$result = $response->getDecodedBody(); // result

为文章上传视频

$filePath = "path_to_video";
// Step 1 - Lấy link upload
$video = new ZaloFile($filePath);
$data = array(
    'videoName' => $video->getFileName(),
    'videoSize' => $video->getSize(),
);
$params = ['data' => $data];
$responseStepOne = $zalo->post(ZaloEndpoint::API_OA_ARTICLE_UPLOAD_VIDEO, $params);
$resultStepOne = $responseStepOne->getDecodedBody(); // result

// Step 2 - Upload file và lấy token
// get params from step 1
$uploadLink = $resultStepOne['data']['uploadLink'];
$timestamp = $resultStepOne['data']['time'];
$sig = $resultStepOne['data']['sig'];
$appId = $resultStepOne['data']['appId'];

$params = array(
    'appId' => $appId,
    'file' => $video,
    'timestamp' => $timestamp,
    'sig' => $sig
);
$responseStepTwo = $zalo->uploadVideo($uploadLink, $params);
$resultStepTwo = $responseStepTwo->getDecodedBody(); // result

// Step 3 - Lấy id của video
$token = $resultStepTwo['data']['token'];
$data = array(
    'token' => $token, // from step 2
    'videoName' => $video->getFileName(),
    'videoSize' => $video->getSize(),
    'time' => $timestamp, // from step 1
    'sig' => $sig // from step 1
);
$params = ['data' => $data];
$responseStepThree = $zalo->get(ZaloEndpoint::API_OA_ARTICLE_GET_VIDEO_ID, $params);
$resultStepThree = $responseStepThree->getDecodedBody();

// step 4 - Kiểm tra trạng thái của video
$videoId = $resultStepThree['data']['videoId'];
$data = array(
    'videoId' => $videoId // get from step 3
);
$params = ['data' => $data];
$responseStepFour = $zalo->get(ZaloEndpoint::API_OA_ARTICLE_GET_VIDEO_STATUS, $params);
$resultStepFour = $responseStepFour->getDecodedBody(); // result

获取视频文章列表

$data = array(
    'offset' => 0,
    'count' => 10
);
$params = ['data' => $data];
$response = $zalo->get(ZaloEndpoint::API_OA_ARTICLE_GET_SLICE_VIDEO, $params);
$result = $response->getDecodedBody();

编辑视频文章

$relatedArticle = array(
    'id' => 'put_related_article_id_here'
);
$media = array(
    'title' => 'update_video_article',
    'desc' => 'put_description_here',
    'avatar' => 'put_avatar_here',
    'videoId' => 'put_video_id_here',
    'relatedMedias' => [$relatedArticle],
    'status' => 'show'
);
$data = array(
    'mediaid' => 'put_media_id_here',
    'media' => $media
);
$params = ['data' => $data];
$response = $zalo->post(ZaloEndpoint::API_OA_ARTICLE_UPDATE_VIDEO, $params);
$result = $response->getDecodedBody();

创建视频帖子

$relatedArticle = array(
    'id' => 'put_related_article_id_here'
);
$media = array(
    'title' => 'create_video_article',
    'desc' => 'put_description_here',
    'avatar' => 'put_avatar_here',
    'videoId' => 'put_video_id_here',
    'relatedMedias' => [$relatedArticle],
    'status' => 'show'
);
$params = ['media' => $media];
$response = $zalo->post(ZaloEndpoint::API_OA_ARTICLE_CREATE_VIDEO, $params);
$result = $response->getDecodedBody();

版本控制

当前版本为1.0.3。我们将在下一个版本中更新更多功能。

作者

  • Zalo开发者

许可证

本项目遵循MIT许可证。