導航:首頁 > 編程語言 > discuz整合java項目

discuz整合java項目

發布時間:2023-12-02 19:46:29

⑴ 如何用java實現模擬登錄Discuz!論壇並下載返回的html代碼

package org.shaw;

import org.apache.commons.httpclient.Cookie;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;

public class BaiyouBBS {
static final String LOGON_SITE = "www.qiluyiyou.com";

static final int LOGON_PORT = 80;

public Cookie[] login(String name, String pas) {
try {
HttpClient client = new HttpClient();
client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT);
PostMethod post = new PostMethod("/logging.php?action=login");

client.executeMethod(post);
String responseString = new String(post.getResponseBody(), "gbk");
post.releaseConnection();
String formhash = getFormHash(responseString);
System.out.println(formhash);

post = new PostMethod("/logging.php?action=login&");
NameValuePair[] params = new NameValuePair[11];
params[0] = new NameValuePair("loginfield", "username");
params[1] = new NameValuePair("username", name);
params[2] = new NameValuePair("password", pas);
params[3] = new NameValuePair("referer", "index.php");
params[4] = new NameValuePair("questionid", "0");
params[5] = new NameValuePair("answer", "");
params[6] = new NameValuePair("cookietime", "2592000");
params[7] = new NameValuePair("formhash", formhash);
params[8] = new NameValuePair("loginmode", "");
params[9] = new NameValuePair("loginsubmit", "true");
params[10] = new NameValuePair("styleid", "");
post.setRequestBody(params);

client.executeMethod(post);
// responseString = new String(post.getResponseBody(), "gbk");
post.releaseConnection();

GetMethod get = new GetMethod("/index.php");
client.executeMethod(get);
responseString = new String(get.getResponseBody(), "gbk");
get.releaseConnection();

System.out.println(responseString);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

public String getFormHash(String htmlContent) {
try {
int start = htmlContent.indexOf("name=\"formhash\"");
start = htmlContent.indexOf("value=\"", start) + 7;
int end = htmlContent.indexOf("\"", start);
String formhash = htmlContent.substring(start, end);
return formhash;
} catch (RuntimeException e) {
throw e;
}
}

public static void main(String[] args) {
new BaiyouBBS().login("zzzxxxzzz", "zzzxxxzzz");
}

}

⑵ org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; 前言中不允許有內容。

首先,第一步,安裝好apache和

第三步,配置我們自己的程序,也就是客戶端。

1.拷貝開源項目里的jar包https://code.google.com/p/discuz-ucenter-api-for-java/downloads/list

2.配置一個用於與UCenter對接的servlet

復制代碼 代碼如下:


<servlet>
<servlet-name>connect_discuz</servlet-name>
<servlet-class>com.fivestars.interfaces.bbs.api.UC</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>connect_discuz</servlet-name>
<url-pattern>/api/uc.php</url-pattern>
</servlet-mapping>

3.把配置文件(config.properties)復制到src目錄下

復制代碼 代碼如下:


#
# ================================================
# * Discuz! Ucenter API for JAVA
# ================================================
# UC comunication settings
#
#
#uc server url如果是全新安裝的模式,ucenter可以隨discuz一起安裝,路徑是
UC_API = http://{discuz根目錄}/uc_server
#uc ip address
UC_IP = 127.0.0.1

#key
UC_KEY = yunstudio

#appid
UC_APPID = 2

#connect mode: default value is ""
UC_CONNECT =

4.把開源項目中的demo(jsp_demo.jsp)復制到應用的根目錄中。原來作者的jsp文件編碼和文件頭都有點小問題,所以我稍微的修改了一下。

復制代碼 代碼如下:


<%
/**
* ================================================
* Discuz! Ucenter API for JAVA
* ================================================
* JSP 調用示例
*
* 更多信息:http://code.google.com/p/discuz-ucenter-api-for-java/

*/
%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.fivestars.interfaces.bbs.util.XMLHelper"%>
<%@ page import="com.fivestars.interfaces.bbs.client.Client"%>
<%
Client uc = new Client();
String result = uc.uc_user_login("admin", "yun");

LinkedList<String> rs = XMLHelper.uc_unserialize(result);
if(rs.size()>0){
int $uid = Integer.parseInt(rs.get(0));
String $username = rs.get(1);
String $password = rs.get(2);
String $email = rs.get(3);
if($uid > 0) {
response.addHeader("P3P"," CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"");

out.println("登錄成功");
out.println($username);
out.println($password);
out.println($email);

String $ucsynlogin = uc.uc_user_synlogin($uid);
out.println("登錄成功"+$ucsynlogin);

//本地登陸代碼
//TODO ... ....

Cookie auth = new Cookie("auth", uc.uc_authcode($password+" "+$uid, "ENCODE"));
auth.setMaxAge(31536000);
//auth.setDomain("localhost");
response.addCookie(auth);

Cookie user = new Cookie("uchome_loginuser", $username);
response.addCookie(user);

} else if($uid == -1) {
out.println("用戶不存在,或者被刪除");
} else if($uid == -2) {
out.println("密碼錯");
} else {
out.println("未定義");
}
}else{
out.println("Login failed");
System.out.println(result);
}
%>

⑶ 請求有沒有什麼java開源的論壇,像php的discuz這種。不是什麼java論壇網站哈,之前問別人給我說csdn之類的

java軟體開源社區
http://www.oschina.net/project/lang/19/java

Java開源大全
www.open-open.com.com

閱讀全文

與discuz整合java項目相關的資料

熱點內容
華為應用裡面有了app說明什麼 瀏覽:801
資料庫中xy是什麼意思 瀏覽:893
u盤打不開提示找不到應用程序 瀏覽:609
網站功能介紹怎麼寫 瀏覽:954
word在試圖打開文件時錯誤 瀏覽:108
主板無vga插槽怎麼連接編程器 瀏覽:521
錄視頻文件在哪裡刪除 瀏覽:881
word2013如何插入文件 瀏覽:233
proe教程百度網盤 瀏覽:197
如何控制遠程linux伺服器 瀏覽:740
it教學app有哪些 瀏覽:34
怎麼在ps摳的圖變成矢量文件 瀏覽:405
口袋妖怪銀魂安卓v11 瀏覽:1
網站上芒果tv的賬號都是什麼 瀏覽:104
帶公式的表格如何刷新數據 瀏覽:81
數據標注語音和2d哪個好 瀏覽:145
保存excel文件的方法 瀏覽:655
手機上看不到電腦上的文件 瀏覽:626
關於ps的微信公眾號 瀏覽:612
矩陣論教程 瀏覽:971

友情鏈接