带有 InlineKeyboardMarkup 的 Telegram API 请求不显示带有消息的键盘

问题描述

我正在尝试通过 Telegram API 发送 POST 请求,但它不适用于内联键盘。虽然发送了消息文本,但没有显示键盘

这是我的功能

mov rax,qword ptr [rbp - 0x28]    ; gets the QWORD pointer of the object from the local variable at RBP-40 (which is the 64-bit address of the object)
mov rax,qword ptr [rax]           ; dereferences the QWORD pointer to set RAX to point to the beginning of the object
mov eax,dword ptr [rax]           ; retrieves the value of the first DWORD of the object (often this is the pointer to the DESTRUCTOR of the object,but in this case this makes no sense)
mov dword ptr [rbp - 0x10],eax    ; copies the DWORD value in EAX to the DWORD variable at RBP-16
mov rax,qword ptr [rbp - 0x28]    ; again,same object as above
mov rax,qword ptr [rax]           ; again,dereference
mov rax,qword ptr [rax + 8]       ; retrieve the QWORD value at position +8 (often this is a pointer to a method,this depends on the object structure - but in this case it seems to be the pointer to another object,see below)
mov qword ptr [rbp - 8],rax       ; copies the QWORD value to the local variable at RBP-8

请求中的 Json 是:

mov rax,dword ptr [rbp - 8]     ; Get the QWORD variable (the second from the above code)
mov eax,dword ptr [rax]         ; dereference it (see above)
mov dword ptr [rbp - 0x10],eax  ; and copy it to the local variable at RBP-16 (notice that the value from the above code is overwritten!!!)
mov rax,qword ptr [rbp - 8]     ; again,get the object PTR
mov rax,qword ptr [rax + 8]     ; again,dereference it
mov qword ptr [rbp - 8],rax     ; and replace the value of the local variable at RBP-8 (the old object PTR) with the address of the (first?) (QWORD) value/address of the object (also overwritten!!!)

请求的响应是 public static void ApiToOpponent(InlineKeyboardMarkup keyboardMarkup,long chat_id,String text) throws IOException { HttpClient httpclient = HttpClients.createDefault(); List<List<InlineKeyboardButton>> keyboard = keyboardMarkup.getKeyboard(); URL url = new URL ("https://api.telegram.org/bot1778589497:AAE2CGovQ67.......bk/sendMessage"); HttpURLConnection con = (HttpURLConnection)url.openConnection(); con.setRequestMethod("POST"); con.setRequestProperty("Content-Type","application/json; utf-8"); con.setRequestProperty("Accept","application/json"); con.setDoOutput(true); JSONObject params = new JSONObject(); params.put("chat_id",Long.toString(chat_id)); params.put("text",text); JSONArray field_of_buttons = new JSONArray(); JSONArray row_of_buttons; for( List<InlineKeyboardButton> row : keyboard) { row_of_buttons = new JSONArray(); for(InlineKeyboardButton button : row){ JSONObject button_json = new JSONObject(); JSONArray param_aray = new JSONArray(); JSONObject button_param = new JSONObject(); button_param.put("text",button.getText()); button_param.put("callback_data",button.getCallbackData()); param_aray.put(button_param); button_json.put("InlineKeyboardButton",param_aray); row_of_buttons.put(button_json); } field_of_buttons.put(row_of_buttons); } JSONObject last_json = new JSONObject(); last_json.put("InlineKeyboardMarkup",field_of_buttons); params.put("reply_markup",last_json); try(OutputStream os = con.getoutputStream()) { byte[] input = params.toString().getBytes("utf-8"); os.write(input,input.length); } try(BufferedReader br = new BufferedReader( new InputStreamReader(con.getInputStream(),"utf-8"))) { StringBuilder response = new StringBuilder(); String responseLine = null; while ((responseLine = br.readLine()) != null) { response.append(responseLine.trim()); } System.out.println(response.toString()); } }

对任何回复都会非常高兴:)

解决方法

在这种情况下,正确的 json 请求是:

{"text":"你的对手已被找到。移动","re​​ply_markup":{"inline_keyboard":[[{"text":"⬜","callback_data":"Tic_tac_move:0,X"},{"text":"⬜",1,2,X"}],[{"text":"⬜","callback_data":"Tic_tac_move:1,{"text":"❌","callback_data":"Tic_tac_move :2,"callback_data":"Tic_tac_move:2,{"text":"⭕",X"}]]},"chat_id":"177114... "}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...