Skip to content

Commit 0ff1684

Browse files
committed
增加日志打印
1 parent f22ec44 commit 0ff1684

3 files changed

Lines changed: 19 additions & 11 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
### 说明
1111

12-
此项目移植自[https://code.google.com/archive/p/discuz-ucenter-api-for-java](https://code.google.com/archive/p/discuz-ucenter-api-for-java),感谢原作者```梁平 (no_ten@163.com)```将他的代码开源。
12+
此项目移植自[https://code.google.com/archive/p/discuz-ucenter-api-for-java](https://code.google.com/archive/p/discuz-ucenter-api-for-java) / [https://github.com/liangping/dzclient4j](https://github.com/liangping/dzclient4j),感谢原作者[梁平 (no_ten@163.com)](https://github.com/liangping)将他的代码开源。
1313

1414
由于原有项目已经非常古老了,看时间应该是2009年的产物,但现在的项目都使用```Maven``````SpringBoot```进行构建,里面直接配置```servlet```的方式不太适合现代项目集成,我就拿来进行了一些修改,让使用```Maven``````SpringBoot```的程序更容易集成进去。
1515

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>net.renfei</groupId>
88
<artifactId>discuz-ucenter-api-for-java</artifactId>
9-
<version>1.0.2</version>
9+
<version>1.0.3</version>
1010
<packaging>jar</packaging>
1111
<name>discuz-ucenter-api-for-java</name>
1212
<url>https://github.com/renfei/discuz-ucenter-api-for-java</url>

src/main/java/net/renfei/discuz/ucenter/client/Client.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,10 @@ public String ucAuthcode(String string, String operation, String key, int expiry
275275
}
276276

277277
if (operation.equals("DECODE")) {
278-
String result= result1.toString();
279-
try{
280-
result=new String(result.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
281-
}catch (Exception e) {
278+
String result = result1.toString();
279+
try {
280+
result = new String(result.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
281+
} catch (Exception e) {
282282
result = result1.substring(0, result1.length());
283283
}
284284
if ((Integer.parseInt(substr(result, 0, 10)) == 0 || Long.parseLong(substr(result, 0, 10)) - time() > 0) && substr(result, 10, 16).equals(substr(md5(substr(result, 26) + keyb), 0, 16))) {
@@ -315,7 +315,7 @@ protected String ucFopen2(String url, int limit, String post, String cookie, boo
315315
}
316316

317317
protected String ucFopen(String url, int limit, String post, String cookie, boolean bysocket, String ip, int timeout, boolean block) {
318-
String returnString = "";
318+
StringBuilder returnString = new StringBuilder();
319319

320320
URL matches;
321321
String host = "";
@@ -360,6 +360,8 @@ protected String ucFopen(String url, int limit, String post, String cookie, bool
360360
try {
361361
Socket fp = new Socket(ip != null && ip.length() > 10 ? ip : host, port);
362362
if (!fp.isConnected()) {
363+
System.out.println("net.renfei.discuz.ucenter.client.Client.ucFopen:\n"
364+
+ "Socket Not Connected\n");
363365
return "";//note errstr : errno \r\n
364366
} else {
365367

@@ -369,10 +371,13 @@ protected String ucFopen(String url, int limit, String post, String cookie, bool
369371
InputStream ins = fp.getInputStream();
370372

371373
BufferedReader reader = new BufferedReader(new InputStreamReader(ins));
374+
StringBuilder header = new StringBuilder();
372375
while (true) {
373-
String header = reader.readLine();
374-
if (header == null || header.equals("") || header == "\r\n" || header == "\n") {
376+
String data = reader.readLine();
377+
if (data == null || "".equals(data) || "\r\n".equals(data) || "\n".equals(data)) {
375378
break;
379+
} else {
380+
header.append(data);
376381
}
377382
}
378383

@@ -381,16 +386,19 @@ protected String ucFopen(String url, int limit, String post, String cookie, bool
381386
if (data == null || data.equals("")) {
382387
break;
383388
} else {
384-
returnString += data;
389+
returnString.append(data);
385390
}
386391
}
392+
System.out.println("net.renfei.discuz.ucenter.client.Client.ucFopen:\n"
393+
+ header.toString() + "\n\n"
394+
+ returnString + "\n");
387395

388396
fp.close();
389397
}
390398
} catch (IOException e) {
391399
e.printStackTrace();
392400
}
393-
return returnString;
401+
return returnString.toString();
394402
}
395403

396404
public String ucAppLs() {

0 commit comments

Comments
 (0)