Guest User

Untitled

a guest
Feb 16th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. $item_menu_query = $db->select(true,"name","menu","name_menu='$text'");
  2. $text = "";
  3. for ($menucount=0; $menucount < 1; $menucount++) {
  4. $text .= $item_menu_query[$menucount]['name']." &,& ";
  5. }
  6. $text = str_replace('"',"",$text);
  7. $params['keyboard'] = BtnBuild($text, $btn_lvl = 1, $params=[]);
  8. $params['peer_id'] = 137534777;
  9. Send($params, true);
  10. function Send($params=[],$debug = false) {
  11. $token = 'токен';
  12. if ($params['keyboard'] == NULL) {
  13. $request_params = array(
  14. 'message' => $params['answer_text'],
  15. 'peer_id' => $params['peer_id'],
  16. 'access_token' => $token,
  17. 'v' => '5.92',
  18. 'random_id' => rand(0,1000000),
  19. );
  20. }else{
  21. $request_params = array(
  22. 'message' => $params['answer_text'],
  23. 'peer_id' => $params['peer_id'],
  24. 'access_token' => $token,
  25. 'v' => '5.92',
  26. 'keyboard' => json_encode($params['keyboard'], JSON_UNESCAPED_UNICODE),
  27. 'random_id' => rand(0,1000000),
  28. );
  29. print_r($request_params);
  30. }
  31. $get_params = http_build_query($request_params);
  32. if ($debug == true) {
  33. file_put_contents('bot.txt','https://api.vk.com/method/messages.send?'. $get_params);
  34. }
  35. file_get_contents('https://api.vk.com/method/messages.send?'. $get_params, FILE_TEXT);
  36. }
  37.  
  38. function BtnBuild($btn_text, $btn_lvl = 2, $params=[]) {
  39. $btns_text_array = explode("&,&", $btn_text);
  40. for ($i=0;$i<count($btns_text_array);$i++) {
  41. switch($btn_lvl) {
  42. case "1":
  43. $btns[$i]=[['action' =>['type' => 'text','label' => $btns_text_array[$i],],'color' => 'primary']];
  44. break;
  45.  
  46. case "2":
  47. $btns[$i]=['action' =>['type' => 'text','label' => $btns_text_array[$i],],'color' => 'primary'];
  48. break;
  49. }
  50. }
  51. switch($btn_lvl) {
  52. case "1":
  53. $keyboard =
  54. array(
  55. 'one_time' => true,
  56. 'buttons' =>$btns
  57. );
  58. break;
  59.  
  60. case "2":
  61. $keyboard =
  62. array(
  63. 'one_time' => true,
  64. 'buttons' =>
  65. array(
  66. $btns
  67. ),
  68. );
  69. break;
  70. }
  71.  
  72. return $keyboard;
  73. }
Add Comment
Please, Sign In to add comment