// 獲取訂閱者串列
public final static String GETUID = "https://m.api.weibo.com/2/messages/subscribers/get.json?access_token=ACCESS_TOKEN";
// 群發訊息介面
public final static String SENDMSG = "https://m.api.weibo.com/2/messages/sendall.json?access_token=ACCESS_TOKEN";
//access_token 有效時長1年
public final static String access_token = "這里獲取好了";
public static String post(JSONObject json, String URL) {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(URL);
post.setHeader("Content-Type", "application/x-www-form-urlencoded");
// post.addHeader("Authorization", "Basic YWRtaW46");
String result = "";
try {
StringEntity s = new StringEntity(json.toString(), "utf-8");
s.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,
"x-www-form-urlencoded"));
post.setEntity(s);
// 發送請求
HttpResponse httpResponse = client.execute(post);
// 獲取回應輸入流
InputStream inStream = httpResponse.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(
inStream, "utf-8"));
StringBuilder strber = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
strber.append(line + "\n");
inStream.close();
result = strber.toString();
System.out.println(result);
if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
System.out.println("請求服務器成功,做相應處理");
} else {
System.out.println("請求服務端失敗");
}
} catch (Exception e) {
System.out.println("請求例外");
throw new RuntimeException(e);
}
return result;
}
public static JSONArray getuid() {
String requestUrl = GETUID.replace("ACCESS_TOKEN", access_token);
JSONObject json = WeixinUtil.httpRequest(requestUrl, "GET", null);
JSONArray jsonArray = JSONArray.fromObject(JSONObject.fromObject(json.getString("data")).getString("uids"));
return jsonArray;
}
// 這里是呼叫群發介面的方法
public static String sendMsg(JSONObject outputStr) {
String requestUrl = SENDMSG.replace("ACCESS_TOKEN", access_token);
String sb = SinaUtil.post(outputStr, requestUrl);
return sb;
}
這里是json資料
{"touser":["1067095364","1659162414","1743030982","1770812821"],"articles":[{"summary":"測驗群發","image":"http://images.csdn.net/20170601/timg-2_副本.jpg","display_name":"測驗群發","url":"http://www.whjjyun.gov.cn/Frontpage/details-cultureinfo.html?id=592fd1f79fd1342c8ad12d6f&type=information"},{"summary":"活動","image":"http://jcjjwhy.oss-cn-hangzhou.aliyuncs.com/a53f6807671430ffeb4cd152cb7b9f8a.png","display_name":"測驗測驗測驗","url":"https://passport.csdn.net/account/login?from=http://my.csdn.net/my/mycsdn"}],"msgtype":"articles"}

我理解的是用POST JSON資料 呼叫這個介面
{"error":"Param error, see doc for more info","error_code":10008,"request":"/2/messages/sendall.json"}
試了好多次,都會給我報錯引數錯誤,很疑惑 這是為啥?
這個介面到底應該咋用啊? 求各位大神解答!
uj5u.com熱心網友回復:
我也調不通。。轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/113219.html
標籤:Java SE
