public static String sendMessage(String message_text,String userIdStr) throws UnsupportedEncodingException{
String url = OAPI_DOMAIN + "/gettoken?corpid=" + CLIENT_ID+ "&corpsecret=" + CLIENT_SECRET;
//發(fā)送文本消息開始
// Message是用戶發(fā)送消息的定義類,可以定義各種不同類型消息的消息類進(jìn)行處理
url = OAPI_DOMAIN + "/message/send?access_token=" + accessToken;
Message message = new Message();
message.setAgentid(OURAPP_AGENT_ID);//
message.setMsgtype("text");
// 發(fā)送用戶id
message.setTouser(userIdStr);
Map<String, String> text = new HashMap<String, String>();
text.put("content", message_text);
message.setText(text);
//發(fā)送文本,并返回錯(cuò)誤的用戶ID
String invalidUser = httpPost(url, message, "invaliduser", String.class);
System.out.println("invalidUser=" + invalidUser);
return invalidUser;
} |