21.云打印接口
<h3>功能描述</h3>
<ul>
<li>该接口用于:客户打印订单面单信息。支持打印130、150及210三种面单
<pre><code>注:
1.单次请求,最多20单,如需打印超过20单,可分批次进行打印;
2.测试数据请通过下方顾客编码下单后获取运单号进行测试,顾客编码请联系对接人员进行配置;
3.使用尾号校验的逻辑:
①.优先校验手机号;
②.当下单时手机、电话都填了,则仅校验手机,手机校验不通过则单号校验失败;
③.当下单仅填了电话时,才会校验电话;</code></pre></li>
<li>测试环境确认使用以下顾客编码(未使用此编码下单需要传入联系方式后6位做校验)
顾客编码:SFKDG9THJV4K
校验码:oZKP8OB5ruOsy9SXXqcWaMqhGTqcv1G5</li>
</ul>
<h3>接口定义</h3>
<table>
<thead>
<tr>
<th style="text-align: center;">服务名称</th>
<th style="text-align: center;">批量交易</th>
<th style="text-align: center;">接口类型</th>
<th style="text-align: center;">接口uri</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: center;">云打印接口</td>
<td style="text-align: center;">支持</td>
<td style="text-align: center;">接入/POST</td>
<td style="text-align: center;">/public/order/v2/print</td>
</tr>
</tbody>
</table>
<h3>元素<请求></h3>
<table>
<thead>
<tr>
<th style="text-align: center;">序号</th>
<th style="text-align: center;">字段名</th>
<th style="text-align: center;">类型(约束)</th>
<th style="text-align: center;">必填</th>
<th style="text-align: center;">默认值</th>
<th style="text-align: left;">描述</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: center;">1</td>
<td style="text-align: center;">companyId</td>
<td style="text-align: center;">String(20)</td>
<td style="text-align: center;">是</td>
<td style="text-align: center;">分配客户sendAppId</td>
</tr>
<tr>
<td style="text-align: center;">2</td>
<td style="text-align: center;">documents</td>
<td style="text-align: center;">List<BusinessData></td>
<td style="text-align: center;">是</td>
<td style="text-align: center;">业务数据。最多20条</td>
</tr>
<tr>
<td style="text-align: center;">3</td>
<td style="text-align: center;">printTemplate</td>
<td style="text-align: center;">Integer</td>
<td style="text-align: center;">否</td>
<td style="text-align: center;">1</td>
<td style="text-align: left;">打印模板,1:1联130 2:2联150 3:3联210,默认打印1联130</td>
</tr>
<tr>
<td style="text-align: center;">4</td>
<td style="text-align: center;">customTemplateCode</td>
<td style="text-align: center;">String</td>
<td style="text-align: center;">否</td>
<td style="text-align: center;">自定义模板编码。<br>测试环境:<br>fm_76130_standard_custom_10000742615_1(字体放大10pt)<br>fm_76130_standard_custom_10000742615_3(字体放大9pt)<br>生产环境:<br>fm_76130_standard_custom_10038640298_1(字体放大10pt)<br>fm_76130_standard_custom_10038640298_2(字体放大9pt)</td>
</tr>
</tbody>
</table>
<h4>请求元素 documents/List<BusinessData></h4>
<table>
<thead>
<tr>
<th>序号</th>
<th>属性名</th>
<th>类型(约束)</th>
<th>必填</th>
<th>值说明</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>masterWaybillNo</td>
<td>String</td>
<td>是</td>
<td></td>
<td>主运单号。</td>
</tr>
<tr>
<td>2</td>
<td>branchWaybillNo</td>
<td>String</td>
<td>条件</td>
<td>单票运单时不填</td>
<td>子运单号,单票运单时不填。注:如填写错误,将返回错误面单!</td>
</tr>
<tr>
<td>3</td>
<td>backWaybillNo</td>
<td>String</td>
<td>条件</td>
<td>签回单号</td>
<td>打印签回单时,masterWayBillNo和branchWaybillNo为空(使用自定义模版时需要传入主运单号)。注:测试环境无法测试签回单!</td>
</tr>
<tr>
<td>4</td>
<td>seq</td>
<td>String</td>
<td>条件</td>
<td>该运单号打印时对应的顺序号,母运单序号=1,子运单号时递增该值</td>
<td>单票运单时不填,当打印子母单时必填</td>
</tr>
<tr>
<td>5</td>
<td>sum</td>
<td>String</td>
<td>条件</td>
<td>子母件运单总数</td>
<td>单票运单时不填,当打印子母单时必填</td>
</tr>
<tr>
<td>6</td>
<td>isPrintLogo</td>
<td>String</td>
<td>否</td>
<td>如热敏贴纸上已印刷LOGO及服务电话则不需打印。如未印刷则需打印。 true:热敏纸上无印刷需要打印</td>
<td>不需要打印则不填</td>
</tr>
<tr>
<td>7</td>
<td>remark</td>
<td>String</td>
<td>否</td>
<td>自定义区域备注</td>
<td>注:面单中默认不会打印“寄方备注”信息,如需打印此信息,需将对应信息通过此字段传输</td>
</tr>
<tr>
<td>8</td>
<td>waybillNoCheckType</td>
<td>String</td>
<td>否</td>
<td>运单号权限校验类型 1:收方手机/电话后6位 2:寄方手机/电话后6位。优先校验客户编码,如果客户编码校验不通过,才使用其他方式校验,比如:“1”</td>
<td>第三方erp对接时,为必传,无法通过客户接入码校验运单号时,可以通过其他方式校验</td>
</tr>
<tr>
<td>9</td>
<td>waybillNoCheckValue</td>
<td>Strin</td>
<td>否</td>
<td>运单号合法校验具体值 比如:“123456”</td>
<td>与 waybillNoCheckType 参数对应。测试可用数据:主运单号-SF7444481622858,收方手机后6位-170848;寄方手机后6位-170848;</td>
</tr>
</tbody>
</table>
<h3>元素<响应></h3>
<table>
<thead>
<tr>
<th style="text-align: center;">序号</th>
<th style="text-align: center;">字段名</th>
<th style="text-align: center;">类型(约束)</th>
<th style="text-align: center;">必填</th>
<th style="text-align: center;">字段说明</th>
<th style="text-align: left;">描述</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: center;">1</td>
<td style="text-align: center;">msg</td>
<td style="text-align: center;">String (200)</td>
<td style="text-align: center;">否</td>
<td style="text-align: center;">信息</td>
<td style="text-align: left;">提示信息</td>
</tr>
<tr>
<td style="text-align: center;">2</td>
<td style="text-align: center;">succ</td>
<td style="text-align: center;">String (10)</td>
<td style="text-align: center;">是</td>
<td style="text-align: center;">状态码</td>
<td style="text-align: left;">返回成功或失败信息(ok/fail)</td>
</tr>
<tr>
<td style="text-align: center;">3</td>
<td style="text-align: center;">result</td>
<td style="text-align: center;">Object</td>
<td style="text-align: center;">是</td>
<td style="text-align: center;">数据</td>
<td style="text-align: left;">数据(集合),可能为空</td>
</tr>
</tbody>
</table>
<h4>响应元素 result/Object</h4>
<table>
<thead>
<tr>
<th>序号</th>
<th>属性名</th>
<th>类型(约束)</th>
<th>值说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>files</td>
<td>List<PrintFile></td>
<td>pdf文件集合</td>
</tr>
<tr>
<td>2</td>
<td>fileType</td>
<td>String</td>
<td>文件类型(pdf)</td>
</tr>
</tbody>
</table>
<h4>响应元素 files/List<PrintFile></h4>
<table>
<thead>
<tr>
<th>序号</th>
<th>属性名</th>
<th>类型(约束)</th>
<th>值说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>url</td>
<td>String</td>
<td>pdf文件的url下载地址</td>
</tr>
<tr>
<td>2</td>
<td>token</td>
<td>String</td>
<td>下载文件时需要的token,设置在请求头的 X-Auth-token 字段,有效期 24h</td>
</tr>
<tr>
<td>3</td>
<td>waybillNo</td>
<td>String</td>
<td>顺丰运单号(子母单为子单号)</td>
</tr>
<tr>
<td>4</td>
<td>seqNo</td>
<td>int</td>
<td>面单序号(批量打印场景,为documents的序号)</td>
</tr>
<tr>
<td>5</td>
<td>areaNo</td>
<td>int</td>
<td>联编号(大客户面单为固定值:1)</td>
</tr>
<tr>
<td>6</td>
<td>pageNo</td>
<td>int</td>
<td>每联的页号(大客户面单为固定值:1)</td>
</tr>
</tbody>
</table>
<h3>报文范例</h3>
<ul>
<li><strong>请求报文</strong>
<ul>
<li>请求报文-打印母单范例1
<pre><code>{
&quot;printTemplate&quot;:1,
&quot;documents&quot;:[
{
&quot;masterWaybillNo&quot;:&quot;SF7444440800774&quot;
}
],
&quot;companyId&quot;:201905140011898
}</code></pre></li>
<li>请求报文-打印子母单范例2
<pre><code>{
&quot;printTemplate&quot;:1,
&quot;documents&quot;:[
{
&quot;masterWaybillNo&quot;:&quot;SF7444441028154&quot;,
&quot;seq&quot;:&quot;1&quot;,
&quot;sum&quot;:&quot;3&quot;
},
{
&quot;masterWaybillNo&quot;:&quot;SF7444441028154&quot;,
&quot;branchWaybillNo&quot;:&quot;SF7444511383685&quot;,
&quot;seq&quot;:&quot;2&quot;,
&quot;sum&quot;:&quot;3&quot;
},
{
&quot;masterWaybillNo&quot;:&quot;SF7444441105102&quot;,
&quot;seq&quot;:&quot;3&quot;,
&quot;sum&quot;:&quot;3&quot;,
&quot;waybillNoCheckType&quot;:1,
&quot;waybillNoCheckValue&quot;:&quot;806057&quot;
}
],
&quot;companyId&quot;:201905140011898
}</code></pre></li>
<li>请求报文-打印运单+签回单范例3
<pre><code>{
&quot;printTemplate&quot;:1,
&quot;documents&quot;:[
{
&quot;masterWaybillNo&quot;:&quot;SF7444441028154&quot;
},
{
&quot;backWaybillNo&quot;:&quot;SF7444441028154&quot;,
}
],
&quot;companyId&quot;:201905140011898
}</code></pre></li>
</ul></li>
<li><strong>响应报文</strong>
<ul>
<li>成功报文-打印母单范例1
<pre><code>{
&quot;result&quot;: {
&quot;files&quot;: &quot;[{\&quot;areaNo\&quot;:1,\&quot;pageNo\&quot;:1,\&quot;seqNo\&quot;:1,\&quot;token\&quot;:\&quot;AUTH_tkv12_f146d1855480549d262b5c46ab0ab597ff20a97d9d0db45c16bedeb4fabd112b012deadd477ee524b1d690ce01baa3cdffbb125a6ccf69b73778dba2eb5157eb4829628a05a3fd4e39be90429e17530fae4926ae48db2c2142ff2bb6620b01a1e47c935e36be4326b4543563a2267c56097c246168bb396655e3f732ab74eb85beefbe02cd1faca23b3c16ac58ae679e988c85cb7de1dbc40d915705ddc53242df1e19588dfd04f498a1dc38fbee8dca0f901455a2573c4ece3e29565bfbba3690d42f7d7a0dd3ede9af37edf84e3830\&quot;,\&quot;url\&quot;:\&quot;https://eos-scp-core-shenzhen-futian1-oss.sf-express.com:443/v1.2/AUTH_EOS-SCP-CORE/print-file-sbox/QXZB6ldFrYN_54a12378-f861-4b9f-98b4-248407f0bc98_SF7444440800774_fm_76130_standard_QXZB6ldFrYN_1_1_1.pdf\&quot;,\&quot;waybillNo\&quot;:\&quot;SF7444440800774\&quot;}]&quot;,
&quot;fileType&quot;: &quot;pdf&quot;
},
&quot;succ&quot;: &quot;ok&quot;,
&quot;msg&quot;: null
}</code></pre></li>
<li>成功报文-打印子母单范例2
<pre><code>{
&quot;result&quot;: {
&quot;files&quot;: &quot;[{\&quot;areaNo\&quot;:1,\&quot;pageNo\&quot;:1,\&quot;seqNo\&quot;:2,\&quot;token\&quot;:\&quot;AUTH_tkv12_f146d1855480549d262b5c46ab0ab597ff20a97d9d0db45c16bedeb4fabd112b012deadd477ee524b1d690ce01baa3cdffbb125a6ccf69b73778dba2eb5157eb7b6690724f72aa2fb357ea739d0c3245c66e116f7fe74e459f020a7fc2df5b7912fea18276149a494a45834c8c9b793aff80b2c67b02fde234ad88f3a7577748afda158c21562246040f0a39fe6f3bc5270af1cc39c0e0e576781f2756cdeaf60ddc8a7fcd5198574c61439e437045b0b6efaf2c342c6fd891b92985942c57f06ab8a2017c03bc35cee3c3073214d8eb\&quot;,\&quot;url\&quot;:\&quot;https://eos-scp-core-shenzhen-futian1-oss.sf-express.com:443/v1.2/AUTH_EOS-SCP-CORE/print-file-sbox/QXZB6ldFrYN_c269ff3d-ebc9-4501-b93d-510fbb2cc779_SF7444511383685_fm_76130_standard_QXZB6ldFrYN_2_1_1.pdf\&quot;,\&quot;waybillNo\&quot;:\&quot;SF7444511383685\&quot;},{\&quot;areaNo\&quot;:1,\&quot;pageNo\&quot;:1,\&quot;seqNo\&quot;:1,\&quot;token\&quot;:\&quot;AUTH_tkv12_f146d1855480549d262b5c46ab0ab597ff20a97d9d0db45c16bedeb4fabd112b012deadd477ee524b1d690ce01baa3cdffbb125a6ccf69b73778dba2eb5157eb9f55a86ed23332b10df4f0ea9fcdfee23145dabc78d1335610f16e78cdcb2f12594dd373370ed15f2586910b52b0a2b4b1cb0f2b1d4bec120b513ffb3ffb8003c2370f4b2338774f2173ad9f6bfbb8bd20c3bcc9beeeb0730d04a1e17b381ded36e6472c0c681b5fde3963c721855070e5f5487b3784ea87ac41eed9502ce88b74ca2f4f7961eed4536e9c02f189f45f\&quot;,\&quot;url\&quot;:\&quot;https://eos-scp-core-shenzhen-futian1-oss.sf-express.com:443/v1.2/AUTH_EOS-SCP-CORE/print-file-sbox/QXZB6ldFrYN_c269ff3d-ebc9-4501-b93d-510fbb2cc779_SF7444441028154_fm_76130_standard_QXZB6ldFrYN_1_1_1.pdf\&quot;,\&quot;waybillNo\&quot;:\&quot;SF7444441028154\&quot;},{\&quot;areaNo\&quot;:1,\&quot;pageNo\&quot;:1,\&quot;seqNo\&quot;:3,\&quot;token\&quot;:\&quot;AUTH_tkv12_f146d1855480549d262b5c46ab0ab597ff20a97d9d0db45c16bedeb4fabd112b012deadd477ee524b1d690ce01baa3cdffbb125a6ccf69b73778dba2eb5157eb9f55a86ed23332b10df4f0ea9fcdfee23145dabc78d1335610f16e78cdcb2f12594dd373370ed15f2586910b52b0a2b4b1cb0f2b1d4bec120b513ffb3ffb8003c2370f4b2338774f2173ad9f6bfbb8bdde1aedbf7f20a1fd8014034805542a7d6bcbdd05c2a6813d15486f9413cce2d74d0186e1acc23a08adb194988f667de6c7bdb3e90b986195fa6910af2c596af6\&quot;,\&quot;url\&quot;:\&quot;https://eos-scp-core-shenzhen-futian1-oss.sf-express.com:443/v1.2/AUTH_EOS-SCP-CORE/print-file-sbox/QXZB6ldFrYN_c269ff3d-ebc9-4501-b93d-510fbb2cc779_SF7444441105102_fm_76130_standard_QXZB6ldFrYN_3_1_1.pdf\&quot;,\&quot;waybillNo\&quot;:\&quot;SF7444441105102\&quot;}]&quot;,
&quot;fileType&quot;: &quot;pdf&quot;
},
&quot;succ&quot;: &quot;ok&quot;,
&quot;msg&quot;: null
}</code></pre></li>
<li>失败报文-范例1
<pre><code>{
&quot;result&quot;: null,
&quot;succ&quot;: &quot;fail&quot;,
&quot;msg&quot;: &quot;顾客编码未配置,无法提供此服务&quot;
}</code></pre></li>
<li>失败报文-范例2
<pre><code>{
&quot;result&quot;: null,
&quot;succ&quot;: &quot;fail&quot;,
&quot;msg&quot;: &quot;无对应服务权限&quot;
}</code></pre></li>
</ul></li>
</ul>
<h3>pdf下载范例</h3>
<p>注:(外网环境下载pdf需要在header中传X-Auth-token,value为返回token)</p>
<ul>
<li>
<p><strong>Java下载pdf</strong></p>
<pre><code class="language-java">public static void main(String[] args) {
try{
downLoadByUrl(&quot;https://eos-scp-core-shenzhen-futian1-oss.sf-express.com:443/v1.2/AUTH_EOS-SCP-CORE/print-file-sbox/QXZB6ldFrYN_26228d6e-e831-43db-8b78-bc503de63b6a_SF7444440800774_fm_76130_standard_QXZB6ldFrYN_1_1_1.pdf&quot;,
&quot;md.pdf&quot;,&quot;D:\\&quot;);
}catch (Exception e) {
// TODO: handle exception
}
}
/**
* 从网络Url中下载文件
* @param urlStr
* @param fileName
* @param savePath
* @throws IOException
*/
public static void downLoadByUrl(String urlStr,String fileName,String savePath) throws IOException {
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
//设置超时间为3秒
conn.setConnectTimeout(3*1000);
//防止屏蔽程序抓取而返回403错误
conn.setRequestProperty(&quot;User-Agent&quot;, &quot;Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)&quot;);
conn.setRequestProperty(&quot;X-Auth-token&quot;, &quot;AUTH_tkv12_f146d1855480549d262b5c46ab0ab597ff20a97d9d0db45c16bedeb4fabd112b012deadd477ee524b1d690ce01baa3cdffbb125a6ccf69b73778dba2eb5157eb96ef4098f98f0de7ea97beb57727d6af6794205c1a18e7c9d6e8ebe5260786a7898c061a4a11ccaccc44f8dc2cb000b120006192125efffd29199ea8bba4fefbcdfb1caaa30f342292aadd1aa3bc52c9e0789a1c1fb83e11fc952962bb23ca9d4f4a637729b9fe0f9025f864a1c12c05796a40317a1b5a20953194e378d028f7634932b3913b0d1805a4cd15f33941f1&quot;);
//得到输入流
InputStream inputStream = conn.getInputStream();
//获取自己数组
byte[] getData = readInputStream(inputStream);
//文件保存位置
File saveDir = new File(savePath);
if(!saveDir.exists()){
saveDir.mkdir();
}
File file = new File(saveDir+File.separator+fileName);
FileOutputStream fos = new FileOutputStream(file);
fos.write(getData);
if(fos!=null){
fos.close();
}
if(inputStream!=null){
inputStream.close();
}
System.out.println(&quot;info:&quot;+url+&quot; download success&quot;);
}
/**
* 从输入流中获取字节数组
* @param inputStream
* @return
* @throws IOException
*/
public static byte[] readInputStream(InputStream inputStream) throws IOException {
byte[] buffer = new byte[1024];
int len = 0;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
while((len = inputStream.read(buffer)) != -1) {
bos.write(buffer, 0, len);
}
bos.close();
return bos.toByteArray();
}</code></pre>
</li>
<li>
<p><strong>javascript下载pdf</strong></p>
<pre><code class="language-javascript">const url = &#039;https://eos-scp-core-shenzhen-futian1-oss.sf-express.com/v1.2/AUTH_EOS-SCP-CORE/print-file-sbox/QXZB6ldFrYN_54a12378-f861-4b9f-98b4-248407f0bc98_SF7444440800774_fm_76130_standard_QXZB6ldFrYN_1_1_1.pdf&#039;
this.downLoadByUrl(url)
downLoadByUrl(url){
var token = &#039;AUTH_tkv12_f146d1855480549d262b5c46ab0ab597ff20a97d9d0db45c16bedeb4fabd112b012deadd477ee524b1d690ce01baa3cdffbb125a6ccf69b73778dba2eb5157eb4829628a05a3fd4e39be90429e17530fae4926ae48db2c2142ff2bb6620b01a1e47c935e36be4326b4543563a2267c56097c246168bb396655e3f732ab74eb85beefbe02cd1faca23b3c16ac58ae679e988c85cb7de1dbc40d915705ddc53242df1e19588dfd04f498a1dc38fbee8dca0f901455a2573c4ece3e29565bfbba3690d42f7d7a0dd3ede9af37edf84e3830&#039;
var xhr = new XMLHttpRequest();
//GET请求,请求路径url,async(是否异步)
xhr.open(&#039;GET&#039;, url, true);
//设置请求头参数的方式,如果没有可忽略此行代码
xhr.setRequestHeader(&quot;X-Auth-token&quot;, token);
//设置响应类型为 blob
xhr.responseType = &#039;blob&#039;;
//关键部分
xhr.onload = function (e) {
//如果请求执行成功
if (this.status == 200) {
var blob = this.response;
var filename = &quot;我是文件名.pdf&quot;;//如123.xls
var a = document.createElement(&#039;a&#039;);
//创键临时url对象
var url = URL.createObjectURL(blob);
a.href = url;
a.download=filename;
a.click();
//释放之前创建的URL对象
window.URL.revokeObjectURL(url);
}
};
//发送请求
xhr.send();
},</code></pre>
</li>
<li>
<p><strong>php下载pdf</strong></p>
<pre><code class="language-php">class Demo {
public function download($url, $token)
{
if (trim($url) == &#039;&#039;) {
return false;
}
$save_dir = &#039;pdf/&#039;;
//创建保存目录
if (!file_exists($save_dir) &amp;&amp; !mkdir($save_dir, 0777, true)) {
mkdir($save_dir);
}
$filename = time() . &#039;.pdf&#039;;
ob_start();
header(&quot;x-auth-token:$token&quot;);
readfile($url);
$content = ob_get_contents();
ob_end_clean();
echo &quot;下载文件路径:&quot; . $save_dir . $filename;
//文件大小
$fp2 = @fopen($save_dir . $filename, &#039;a&#039;);
fwrite($fp2, $content);
fclose($fp2);
$a = [
&#039;url&#039;=&gt;$url,
&#039;file_name&#039; =&gt; $filename,
&#039;save_path&#039; =&gt; $save_dir . $filename
];
unset($content, $url);
// $this-&gt;log(&#039;download&#039;,$a,[]);
return $a;
}
}
$demo = new Demo();
$demo-&gt;download(&quot;https://eos-scp-core-shenzhen-futian1-oss.sf-express.com:443/v1.2/AUTH_EOS-SCP-CORE/print-file-sbox/AAABjyMV8xxB4Cxa52NIAINtWrb1F76J_SF7444481622858_fm_76130_standard_QXZB6ldFrYN_1_1.pdf&quot;, &quot;AUTH_tkvXXXX&quot;);</code></pre>
</li>
</ul>