notm / vk-execute-builder
该包已被废弃,不再维护。作者建议使用 farit-slv/vk-execute-builder 包代替。
此包最新版本(dev-master)没有可用的许可证信息。
使用 vk php sdk 的 Vk Execute Builder
dev-master
2019-07-31 01:06 UTC
Requires
- ext-json: *
- monolog/monolog: ^1.24
- vkcom/vk-php-sdk: ^5.100
This package is not auto-updated.
Last update: 2021-09-16 11:44:39 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 的服务器响应数组表示
具体的使用示例可以查看 这里。