This commit is contained in:
jinyu 2016-04-23 12:20:17 +08:00
parent 047ee5f5e1
commit a820a8855f
5 changed files with 24 additions and 7 deletions

View File

@ -8,7 +8,7 @@ JAVA_HOME="/usr/local/java"
RUNNING_USER=root RUNNING_USER=root
#App home #App home
APP_HOME="/path/to/java/app" APP_HOME="/path/to/weixin4j/service"
#Main class #Main class
APP_MAINCLASS=xx.xxx.mainClass.fullName APP_MAINCLASS=xx.xxx.mainClass.fullName

View File

@ -5,6 +5,8 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import com.foxinmy.weixin4j.http.weixin.WeixinRequestExecutor; import com.foxinmy.weixin4j.http.weixin.WeixinRequestExecutor;
import com.foxinmy.weixin4j.logging.InternalLogger;
import com.foxinmy.weixin4j.logging.InternalLoggerFactory;
/** /**
* API基础 * API基础
@ -18,6 +20,9 @@ import com.foxinmy.weixin4j.http.weixin.WeixinRequestExecutor;
*/ */
public abstract class BaseApi { public abstract class BaseApi {
protected final InternalLogger logger = InternalLoggerFactory
.getInstance(getClass());
protected final WeixinRequestExecutor weixinExecutor; protected final WeixinRequestExecutor weixinExecutor;
protected abstract ResourceBundle weixinBundle(); protected abstract ResourceBundle weixinBundle();

View File

@ -255,6 +255,8 @@ public class MediaApi extends MpApi {
} }
HttpParams params = weixinExecutor.getExecuteParams(); HttpParams params = weixinExecutor.getExecuteParams();
request.setParams(params); request.setParams(params);
logger.info("weixin request >> " + request.getMethod() + " "
+ request.getURI().toString());
HttpResponse response = weixinExecutor.getExecuteClient().execute( HttpResponse response = weixinExecutor.getExecuteClient().execute(
request); request);
byte[] content = IOUtil.toByteArray(response.getBody()); byte[] content = IOUtil.toByteArray(response.getBody());
@ -262,8 +264,12 @@ public class MediaApi extends MpApi {
String contentType = headers.getFirst(HttpHeaders.CONTENT_TYPE); String contentType = headers.getFirst(HttpHeaders.CONTENT_TYPE);
String disposition = headers String disposition = headers
.getFirst(HttpHeaders.CONTENT_DISPOSITION); .getFirst(HttpHeaders.CONTENT_DISPOSITION);
if (contentType logger.info("weixin response << " + response.getProtocol()
.contains(ContentType.APPLICATION_JSON.getMimeType()) + response.getStatus().toString() + "[" + contentType + "]->"
+ disposition);
if (contentType.contains(ContentType.TEXT_PLAIN.getMimeType())
|| contentType.contains(ContentType.APPLICATION_JSON
.getMimeType())
|| (disposition != null && disposition.indexOf(".json") > 0)) { || (disposition != null && disposition.indexOf(".json") > 0)) {
JsonResult jsonResult = JSON.parseObject(content, 0, JsonResult jsonResult = JSON.parseObject(content, 0,
content.length, Consts.UTF_8.newDecoder(), content.length, Consts.UTF_8.newDecoder(),

View File

@ -47,7 +47,7 @@ public class MediaTest extends TokenTest {
File file = new File("/Users/jy/Downloads/weixin4j.png"); File file = new File("/Users/jy/Downloads/weixin4j.png");
MediaUploadResult mediaId = mediaApi.uploadMedia(false, MediaUploadResult mediaId = mediaApi.uploadMedia(false,
new FileInputStream(file), file.getName()); new FileInputStream(file), file.getName());
// zloeIROuS3YJFZwugGNM5oGBolqJmU_8FKTUmJwTFbSjfky904S9OPly5Wq0BRn2 // fbyQZL96sK9evnTgDx21jPZgWAnw6YPgslNzcqLFp0lqPCD-XipoPfkwFU1OM9J_
Assert.assertNotNull(mediaId); Assert.assertNotNull(mediaId);
System.err.println(mediaId); System.err.println(mediaId);
} }
@ -56,7 +56,7 @@ public class MediaTest extends TokenTest {
public void download1() throws WeixinException, IOException { public void download1() throws WeixinException, IOException {
MediaDownloadResult content = mediaApi MediaDownloadResult content = mediaApi
.downloadMedia( .downloadMedia(
"BmzcrM2jaJXZCjBqxLwyC03kh5pge3CbrBqXP4XbYBCeKr7xz-rHuwPf4vYLVdL1", "fbyQZL96sK9evnTgDx21jPZgWAnw6YPgslNzcqLFp0lqPCD-XipoPfkwFU1OM9J_",
false); false);
Assert.assertTrue(content != null); Assert.assertTrue(content != null);
System.err.println(content); System.err.println(content);

View File

@ -216,6 +216,8 @@ public class MediaApi extends QyApi {
} }
HttpParams params = weixinExecutor.getExecuteParams(); HttpParams params = weixinExecutor.getExecuteParams();
request.setParams(params); request.setParams(params);
logger.info("weixin request >> " + request.getMethod() + " "
+ request.getURI().toString());
HttpResponse response = weixinExecutor.getExecuteClient().execute( HttpResponse response = weixinExecutor.getExecuteClient().execute(
request); request);
byte[] content = IOUtil.toByteArray(response.getBody()); byte[] content = IOUtil.toByteArray(response.getBody());
@ -223,8 +225,12 @@ public class MediaApi extends QyApi {
String contentType = headers.getFirst(HttpHeaders.CONTENT_TYPE); String contentType = headers.getFirst(HttpHeaders.CONTENT_TYPE);
String disposition = headers String disposition = headers
.getFirst(HttpHeaders.CONTENT_DISPOSITION); .getFirst(HttpHeaders.CONTENT_DISPOSITION);
if (contentType logger.info("weixin response << " + response.getProtocol()
.contains(ContentType.APPLICATION_JSON.getMimeType()) + response.getStatus().toString() + "[" + contentType
+ "]->" + disposition);
if (contentType.contains(ContentType.TEXT_PLAIN.getMimeType())
|| contentType.contains(ContentType.APPLICATION_JSON
.getMimeType())
|| (disposition != null && disposition.indexOf(".json") > 0)) { || (disposition != null && disposition.indexOf(".json") > 0)) {
JsonResult jsonResult = JSON.parseObject(content, 0, JsonResult jsonResult = JSON.parseObject(content, 0,
content.length, Consts.UTF_8.newDecoder(), content.length, Consts.UTF_8.newDecoder(),