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 lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
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) {
CloseableHttpResponse response = null;
try {
@ -334,14 +352,16 @@ public class HttpClientManager {
if (response != null && response.getStatusLine() != null) {
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
InputStream in = response.getEntity().getContent();
ByteArrayOutputStream output = new ByteArrayOutputStream();
byte[] buffer = new byte[4096];
int n = 0;
while (-1 != (n = in.read(buffer))) {
output.write(buffer, 0, n);
}
byte[] responseContent = IOUtils.toByteArray(in);
// ByteArrayOutputStream output = new ByteArrayOutputStream();
// byte[] buffer = new byte[4096];
// int n = 0;
// 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(output.toByteArray());
// return new Result<byte[]>().ok(output.toByteArray());
return new Result<byte[]>().ok(responseContent);
} else {
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) {
WxResult<byte[]> result = new WxResult<>();
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()) {
result.setErrorCode(statusResult.getCode());
result.setErrorMsg(statusResult.getMsg());

Loading…
Cancel
Save