Browse Source

获取审核失败原因素材

dev_shibei_match
zhaoqifeng 5 years ago
parent
commit
829f542060
  1. 34
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/HttpClientManager.java
  2. 2
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/wxapi/service/impl/WxMaCodeServiceImpl.java

34
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/HttpClientManager.java

@ -6,6 +6,7 @@ import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.exception.RenException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.HttpStatus; import org.apache.http.HttpStatus;
@ -326,6 +327,23 @@ public class HttpClientManager {
} }
} }
public Result<byte[]> getMediaByteArray(String url, String json) {
try {
HttpPost httppost = new HttpPost(url);
httppost.setConfig(requestConfig);
httppost.addHeader("Content-Type", "application/json");
if (StringUtils.isNotEmpty(json)) {
StringEntity se = new StringEntity(json, "utf-8");
httppost.setEntity(se);
}
return executeToByte(httppost);
} catch (Exception e) {
log.error("sendGet exception", e);
return new Result<byte[]>().error(EpmetErrorCode.SERVER_ERROR.getCode(), EpmetErrorCode.SERVER_ERROR.getMsg());
}
}
private Result<byte[]> executeToByte(HttpRequestBase httpMethod) { private Result<byte[]> executeToByte(HttpRequestBase httpMethod) {
CloseableHttpResponse response = null; CloseableHttpResponse response = null;
try { try {
@ -334,14 +352,16 @@ public class HttpClientManager {
if (response != null && response.getStatusLine() != null) { if (response != null && response.getStatusLine() != null) {
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
InputStream in = response.getEntity().getContent(); InputStream in = response.getEntity().getContent();
ByteArrayOutputStream output = new ByteArrayOutputStream(); byte[] responseContent = IOUtils.toByteArray(in);
byte[] buffer = new byte[4096]; // ByteArrayOutputStream output = new ByteArrayOutputStream();
int n = 0; // byte[] buffer = new byte[4096];
while (-1 != (n = in.read(buffer))) { // int n = 0;
output.write(buffer, 0, n); // while (-1 != (n = in.read(buffer))) {
} // output.write(buffer, 0, n);
// }
// return new Result<byte[]>().ok(ArrayUtils.toObject(output.toByteArray())); // return new Result<byte[]>().ok(ArrayUtils.toObject(output.toByteArray()));
return new Result<byte[]>().ok(output.toByteArray()); // return new Result<byte[]>().ok(output.toByteArray());
return new Result<byte[]>().ok(responseContent);
} else { } else {
log.warn("execute http method fail,httpStatus:{0}", response.getStatusLine().getStatusCode()); log.warn("execute http method fail,httpStatus:{0}", response.getStatusLine().getStatusCode());
} }

2
epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/wxapi/service/impl/WxMaCodeServiceImpl.java

@ -204,7 +204,7 @@ public class WxMaCodeServiceImpl implements WxMaCodeService {
public WxResult<byte[]> getMaterial(String accessToken, WxMaNewsReq request) { public WxResult<byte[]> getMaterial(String accessToken, WxMaNewsReq request) {
WxResult<byte[]> result = new WxResult<>(); WxResult<byte[]> result = new WxResult<>();
String url = WxMaCodeConstant.GET_MATERIAL_URL + "?" + "access_token=" + accessToken; String url = WxMaCodeConstant.GET_MATERIAL_URL + "?" + "access_token=" + accessToken;
Result<byte[]> statusResult = HttpClientManager.getInstance().getByteArray(url, toMap(request)); Result<byte[]> statusResult = HttpClientManager.getInstance().getMediaByteArray(url, toJson(request));
if (!statusResult.success()) { if (!statusResult.success()) {
result.setErrorCode(statusResult.getCode()); result.setErrorCode(statusResult.getCode());
result.setErrorMsg(statusResult.getMsg()); result.setErrorMsg(statusResult.getMsg());

Loading…
Cancel
Save