推荐公众号
==有彩蛋哦!!!==(或者公众号内点击网赚获取彩蛋)
程序员探索之路
服务商
在网上兜兜转转没有找到免费的网络传真API,只好付费服务商bnetfax
代码
有了API后那其他的就是按照文档开发了没什么难度
发送代码
public static void main(String[] args) throws IOException, ServiceException {
收件人号码
String destnumbers = "********";
发送主题
String title = "代码测试发送传真";
FaxConfig faxConfig = FaxConfig.builder()
企业账号
.bnetaccount("********")
密码
.password("********")
发送者号码
.sendnumber("********")
用户账号
.useraccount("********")
区号
.areaid("********")
.build();
List paths = Lists.newArrayList("test.pdf");
FaxResultDTO faxResultDTO = sendFax(faxConfig, title, destnumbers, paths);
log.info("faxResultDTO=[{}]", faxResultDTO);
}
public static FaxResultDTO sendFax(FaxConfig faxConfig, String title, String destnumbers, List filePath) throws IOException, ServiceException {
Map fileBuffer = getFileBuffer(filePath);
//生成访问Soap传真服务接口的UserTest实例
SoapFaxClient soapFaxClient = new SoapFaxClient();
//通过UserTest.upload()把字节大小和文件名传过去以访问Soap传真服务接口
String xml = soapFaxClient.doSendFax(fileBuffer,
faxConfig.getSendnumber(), title, faxConfig.getUseraccount(), faxConfig.getBnetaccount(),
faxConfig.getPassword(), destnumbers, faxConfig.getAreaid());
//将发送与返回的xml包分开
String[] xmls = xml.split("@@");
// System.out.println("保存服务端返回的xml到request域中" + xmls[0]);
// System.out.println("保存客户端发送的xml到request域中" + xmls[1]);
//xml包解析
FaxResultDTO faxResultDTO = parseFaxResultXml(xmls[0]);
String resultCode = faxResultDTO.getResultCode();
String faxid = faxResultDTO.getFaxid();
Str