Skip to content

Commit ac1ae5f

Browse files
author
pjy
committed
v1.3.2:Increase language parameter & modify watermark annotation.
1 parent 14ee299 commit ac1ae5f

File tree

4 files changed

+67
-18
lines changed

4 files changed

+67
-18
lines changed

src/Client/CPDFClient.php

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,17 @@ public function getAuthorization(){
8989

9090
/**
9191
* @param $fileKey
92+
* @param null $language 1:English, 2:Chinese
9293
* @return mixed
9394
* @throws CPDFException
9495
*/
95-
public function getFileInfoByKey($fileKey){
96-
return $this->httpClient->send(CPDFURL::HTTP_METHOD_GET, CPDFURL::API_V1_FILE_INFO, $this->getAuthorization(), ['fileKey'=>$fileKey]);
96+
public function getFileInfoByKey($fileKey, $language = null){
97+
$options = ['fileKey'=>$fileKey];
98+
if($language){
99+
$options['language'] = $language;
100+
}
101+
102+
return $this->httpClient->send(CPDFURL::HTTP_METHOD_GET, CPDFURL::API_V1_FILE_INFO, $this->getAuthorization(), $options);
97103
}
98104

99105
/**
@@ -118,13 +124,20 @@ public function getTaskList($page, $size){
118124

119125
/**
120126
* @param $executeType
127+
* @param int $language 1:English, 2:Chinese
121128
* @return CPDFClient
122129
* @throws CPDFException
123130
*/
124-
public function createTask($executeType){
131+
public function createTask($executeType, $language = null){
125132
$url = str_replace('{executeTypeUrl}', $executeType, CPDFURL::API_V1_CREATE_TASK);
126133

127-
$result = $this->httpClient->send(CPDFURL::HTTP_METHOD_GET, $url, $this->getAuthorization());
134+
$options = [];
135+
136+
if($language){
137+
$options['language'] = $language;
138+
}
139+
140+
$result = $this->httpClient->send(CPDFURL::HTTP_METHOD_GET, $url, $this->getAuthorization(), $options);
128141
$taskId = $result['taskId'];
129142

130143
$this->taskResource = new CPDFTaskResource($taskId);
@@ -148,10 +161,11 @@ public function addFile($filepath){
148161
* @param $filePath
149162
* @param null $password
150163
* @param array $params
164+
* @param int $language
151165
* @return mixed
152166
* @throws CPDFException
153167
*/
154-
public function uploadFile($taskId, $filePath, $password = null, $params = []){
168+
public function uploadFile($taskId, $filePath, $password = null, $params = [], $language = null){
155169
if(!file_exists($filePath)){
156170
throw new CPDFException('uploadFile', 'File does not exist.');
157171
}
@@ -193,25 +207,43 @@ public function uploadFile($taskId, $filePath, $password = null, $params = []){
193207
$options['multipart'][] = ['name' => 'parameter', 'contents' => json_encode($params)];
194208
}
195209

210+
if($language){
211+
$options['multipart'][] = ['name' => 'language', 'contents' => $language];
212+
}
213+
196214
return $this->httpClient->send(CPDFURL::HTTP_METHOD_POST, CPDFURL::API_V1_UPLOAD_FILE, $this->getAuthorization(), $options);
197215
}
198216

199217
/**
200218
* @param $taskId
219+
* @param null $language 1:English, 2:Chinese
201220
* @return CPDFClient
202221
* @throws CPDFException
203222
*/
204-
public function executeTask($taskId){
205-
$this->httpClient->send(CPDFURL::HTTP_METHOD_GET, CPDFURL::API_V1_EXECUTE_TASK, $this->getAuthorization(), ['taskId'=>$taskId]);
223+
public function executeTask($taskId, $language = null){
224+
$options = ['taskId' => $taskId];
225+
226+
if($language){
227+
$options['language'] = $language;
228+
}
229+
230+
$this->httpClient->send(CPDFURL::HTTP_METHOD_GET, CPDFURL::API_V1_EXECUTE_TASK, $this->getAuthorization(), $options);
206231
return $this;
207232
}
208233

209234
/**
210235
* @param $taskId
236+
* @param null $language 1:English, 2:Chinese
211237
* @return mixed
212238
* @throws CPDFException
213239
*/
214-
public function getTaskInfo($taskId){
215-
return $this->httpClient->send(CPDFURL::HTTP_METHOD_GET, CPDFURL::API_V1_TASK_INFO, $this->getAuthorization(), ['taskId'=>$taskId]);
240+
public function getTaskInfo($taskId, $language = null){
241+
$options = ['taskId' => $taskId];
242+
243+
if($language){
244+
$options['language'] = $language;
245+
}
246+
247+
return $this->httpClient->send(CPDFURL::HTTP_METHOD_GET, CPDFURL::API_V1_TASK_INFO, $this->getAuthorization(), $options);
216248
}
217249
}

src/Client/CPDFHttpClient.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ public function send($method, $url, $headers = [], $options = []){
3434
if(!empty($options)){
3535
if(isset($options['multipart'])){
3636
$body['multipart'] = $options['multipart'];
37-
}elseif($method == CPDFURL::HTTP_METHOD_POST){
38-
$body['headers']['Content-Type'] = 'application/json';
39-
$body['json'] = $options;
40-
}elseif($method == CPDFURL::HTTP_METHOD_GET){
41-
$body['headers']['Content-Type'] = 'application/json';
42-
$body['query'] = $options;
37+
}else{
38+
if($method == CPDFURL::HTTP_METHOD_POST){
39+
$body['headers']['Content-Type'] = 'application/json';
40+
$body['json'] = $options;
41+
}elseif($method == CPDFURL::HTTP_METHOD_GET){
42+
$body['headers']['Content-Type'] = 'application/json';
43+
$body['query'] = $options;
44+
}
4345
}
4446
}
4547

src/Constant/CPDFLanguage.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
4+
namespace ComPDFKit\Constant;
5+
6+
7+
class CPDFLanguage
8+
{
9+
const ENGLISH = 1;
10+
const CHINESE = 2;
11+
}

src/Resource/CPDFFileResource.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,10 @@ public function setTextColor($textColor){
144144
}
145145

146146
/**
147-
* @param string $front Is it at the front
147+
* @param string $front Setting watermark layer
148+
* "0" false: No need to pin it to the top
149+
* "1" true: Pin it to the top
150+
* null No need to pin it to the top
148151
* @return $this
149152
*/
150153
public function setFront($front){
@@ -345,11 +348,12 @@ public function setImgDpi($imgDpi){
345348
/**
346349
* @param $taskId
347350
* @param null $password
351+
* @param null $language 1:English, 2:Chinese
348352
* @return CPDFClient
349353
* @throws CPDFException
350354
*/
351-
public function uploadFile($taskId, $password = null){
352-
$fileInfo = $this->client->uploadFile($taskId, $this->filepath, $password, $this->options);
355+
public function uploadFile($taskId, $password = null, $language = null){
356+
$fileInfo = $this->client->uploadFile($taskId, $this->filepath, $password, $this->options, $language);
353357
$this->fileKey = $fileInfo['fileKey'];
354358
$this->fileUrl = $fileInfo['fileUrl'];
355359

0 commit comments

Comments
 (0)