farit-slv / vk-execute-builder
使用 Vk PHP SDK 的 Vk Execute Builder
0.0.1
2020-12-23 01:33 UTC
Requires
- ext-json: *
- monolog/monolog: ^1.24
- vkcom/vk-php-sdk: ^5.101
This package is auto-updated.
Last update: 2024-09-23 09:42:29 UTC
README
使用库
该库旨在在 JavaScript execute 代码中构造 VK 请求。
连接
require __DIR__.'/../vendor/autoload.php'; use SMITExecute\Library\ExecuteRequest; $builder = new ExecuteRequest(); // Конструктор ваших execut'ов
使用示例
// Добавляем в запросы execut'a messages.getConversations $builder->add( $builder->create() ->setMainMethod("messages") ->setSubMethod("getConversations") ->setParams([ "user_id" => 89481221 ]) ); // Добавляем ещё один запрос users.get $builder->add( $builder->create() ->setMainMethod("users") ->setSubMethod("get") ->setParams([ "user_id" => 89481221, ]) ); $code_strings = $builder->convertToJS(); // Конвертируем код в javascript (Возвращает массив строк javascript'a) $code = implode(PHP_EOL, $code_strings); // Преобразовываем массив в строки. $vk = new VKApiClient('5.00'); $response = $vk->getRequest()->post('execute', "token", [ 'code' => $code, ]);
解析服务器响应。
库会将您的请求转换为对象并分组,该对象通过键 主要方法_子方法 返回。
以上示例的响应示例
{
"messages_getConversations": [
{
"count" : 1,
"items" : [
{
"conversation" : {
"peer" : {
"id" : 89481221,
"type" : "user",
"local_id" : 89481221
},
"in_read" : 5,
"out_read":5,
"last_message_id":5,
"can_write":
{
"allowed" : true
},
"current_keyboard" : {
"one_time":true,
"author_id":-184452841,
"buttons":[
["Over 9 levels deep, aborting normalization"]
]
}
},
"last_message" : {
"date" : 1564532387,
"from_id" : -184452841,
"id" : 5,
"out" : 1,
"peer_id" : 89481221,
"text" : "хай",
"conversation_message_id" : 5,
"fwd_messages" : [],
"keyboard": {
"one_time":true,
"author_id":-184452841,
"buttons": [
["Over 9 levels deep, aborting normalization"]
]
},
"important":false,
"random_id":0,
"attachments":[],
"is_hidden":false
}
}
]
}
],
"users_get":[
[
{
"id":89481221,
"first_name":"Андрей",
"last_name":"Кутин"
}
]
]
}
如您所见,您的请求将按类型分组,所有请求都将由来自 VK 的服务器响应数组表示。
具体使用示例请参阅 此处。