吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 4919|回复: 1
收起左侧

[其他转载] Discuz!NT 自动发送短消息 Java部分代码

 关闭 [复制链接]
my26929 发表于 2010-6-12 21:12

获取用户名单的,我没发上来。

真有需要的可以加我QQ 15524841


import java.io.IOException;
import java.io.UnsupportedEncodingException;
import org.apache.commons.httpclient.Cookie;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
public class BBS {
static final String LOGON_SITE = "bbs.***0.com";
static final int LOGON_PORT = 80;
@SuppressWarnings("deprecation")

public Cookie[] login(String name, String pas) {

//登陆模块
HttpClient client = new HttpClient();
client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT);
PostMethod post = new PostMethod("http://bbs.***.com/login.aspx");
NameValuePair username = new NameValuePair("username", name);
NameValuePair password = new NameValuePair("password", pas);
post.setRequestBody(new NameValuePair[] { username, password});
try {
   client.executeMethod(post);
} catch (HttpException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
} catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
}
String responseString = null;
try {
   responseString = new String(post.getResponseBodyAsString().getBytes("gb2312"));
} catch (UnsupportedEncodingException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
} catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
}
Cookie[] cookies = client.getState().getCookies();
client.getState().addCookies(cookies);
post.releaseConnection();
// 判断是否登陆成功
if (responseString.lastIndexOf("登录成功, 返回登录前页面") > -1) {
   
   String newUrl = "http://bbs.***0.com/index.aspx";
   
   // 实施转跳
   GetMethod get = new GetMethod(newUrl);
   get.setRequestHeader("User-Agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0;)");
   get.setRequestHeader("Cookie", cookies.toString());
   try {
    client.executeMethod(get);
   } catch (HttpException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
   try {
    System.out.println(get.getResponseBodyAsString().lastIndexOf("退出"));
   } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
   get.releaseConnection();
   //提交短消息
   post = new UTF8PostMethod("http://bbs.***0.com/usercppostpm.aspx");
   NameValuePair names = new NameValuePair("msgto","接收人ID");
   NameValuePair biaoti = new NameValuePair("subject","标题");
   NameValuePair neirong = new NameValuePair("message","内容");
   NameValuePair sendmsg = new NameValuePair("sendmsg","%E7%AB%8B%E5%8D%B3%E5%8F%91%E9%80%81");
   post.setRequestBody(new NameValuePair[] { names, biaoti,neirong,sendmsg});
   post.setRequestHeader("Referer", "http://bbs.***0.com/usercppostpm.aspx");
   post.setRequestHeader("Accept-Language", "zh-cn");
   try {
    System.out.println("aaa");
    client.getState().addCookies(cookies);
    client.executeMethod(post);
    responseString = new String(post.getResponseBodyAsString().getBytes("gb2312"));
    System.out.println(responseString);
   } catch (HttpException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
   } catch (IOException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
   }
   return client.getState().getCookies();
}
return null;
}
public static void main(String[] args) {
new BaiyouBBS().login("论坛账号", "论坛密码");
}

}

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

抠抠屁眼闻闻手 发表于 2012-11-20 20:36
discuz 论坛消息有一套工具吗?
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-16 14:47

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表