小程序
小游戏
企业微信
微信支付
扫描小程序码分享
发票为数电发票,是数电发票pdf格式有误吗,技术老师帮忙看下,谢谢。
1 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
最简单的测试发票pdf是否正常的方式:
打开微信发票助手,选择这个pdf文件,能导入成功就是正常的,不能就说明pdf有问题
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
/**
* 将电子发票PDF文件上传至微信
*/
public static String uploadPdfFile(String accessToken, File file) {
HttpPost httpPost = new HttpPost("https://api.weixin.qq.com/card/invoice/platform/setpdf?access_token=" + accessToken);
CloseableHttpResponse response = null;
CloseableHttpClient httpClient = HttpClients.createDefault();
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(5000).setConnectTimeout(5000).build();
httpPost.setConfig(requestConfig);
HttpEntity httpEntity = MultipartEntityBuilder.create().addPart("pdf", new FileBody(file, ContentType.create("multipart/form-data", Consts.UTF_8), file.getName())).build();
httpPost.setEntity(httpEntity);
try {
response = httpClient.execute(httpPost, new BasicHttpContext());
log.info("上传PDF文件至微信返回参数:{}", JSON.toJSONString(response));
if (response.getStatusLine().getStatusCode() != 200) {
log.info("上传PDF文件至微信,请求失败");
}
HttpEntity entity = response.getEntity();
if (entity != null) {
String resultStr = EntityUtils.toString(entity, "utf-8");
log.info("上传PDF文件至微信返回参数:{}", resultStr);
JSONObject result = JSON.parseObject(resultStr);
int errcode = (Integer)result.get("errcode");
if (errcode != 0) {
log.info("上传PDF文件至微信失败");
return result.getString("s_media_id");
} catch (IOException e) {
e.printStackTrace();
} finally {
if (response != null)
response.close();
return null;
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
最简单的测试发票pdf是否正常的方式:
打开微信发票助手,选择这个pdf文件,能导入成功就是正常的,不能就说明pdf有问题
/**
* 将电子发票PDF文件上传至微信
*/
public static String uploadPdfFile(String accessToken, File file) {
HttpPost httpPost = new HttpPost("https://api.weixin.qq.com/card/invoice/platform/setpdf?access_token=" + accessToken);
CloseableHttpResponse response = null;
CloseableHttpClient httpClient = HttpClients.createDefault();
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(5000).setConnectTimeout(5000).build();
httpPost.setConfig(requestConfig);
HttpEntity httpEntity = MultipartEntityBuilder.create().addPart("pdf", new FileBody(file, ContentType.create("multipart/form-data", Consts.UTF_8), file.getName())).build();
httpPost.setEntity(httpEntity);
try {
response = httpClient.execute(httpPost, new BasicHttpContext());
log.info("上传PDF文件至微信返回参数:{}", JSON.toJSONString(response));
if (response.getStatusLine().getStatusCode() != 200) {
log.info("上传PDF文件至微信,请求失败");
}
HttpEntity entity = response.getEntity();
if (entity != null) {
String resultStr = EntityUtils.toString(entity, "utf-8");
log.info("上传PDF文件至微信返回参数:{}", resultStr);
JSONObject result = JSON.parseObject(resultStr);
int errcode = (Integer)result.get("errcode");
if (errcode != 0) {
log.info("上传PDF文件至微信失败");
}
return result.getString("s_media_id");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (response != null)
try {
response.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}