本文整理匯總了PHP中Connector::_parseRecipient方法的典型用法代碼示例。如果您正苦於以下問題:PHP Connector::_parseRecipient方法的具體用法?PHP Connector::_parseRecipient怎麽用?PHP Connector::_parseRecipient使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Connector
的用法示例。
在下文中一共展示了Connector::_parseRecipient方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: pushFile
/**
* Push a file.
*
* @param string $recipient Recipient. Can be device_iden, email or channel #tagname.
* @param string $filePath The path of the file to push.
* @param string $mimeType The MIME type of the file. If null, we'll try to guess it.
* @param string $title The title of the push notification.
* @param string $body The body of the push notification.
* @param string $altFileName Alternative file name to use instead of the original one.
* For example, you might want to push 'someFile.tmp' as 'image.jpg'.
*
* @return object Response.
* @throws ApiException
*/
public function pushFile($recipient, $filePath, $mimeType = null, $title = null, $body = null, $altFileName = null)
{
$data = array();
$fullFilePath = realpath($filePath);
if (!is_readable($fullFilePath)) {
throw new ApiException('File: File does not exist or is unreadable.');
}
if (filesize($fullFilePath) > 25 * 1024 * 1024) {
throw new ApiException('File: File size exceeds 25 MB.');
}
$data['file_name'] = $altFileName === null ? basename($fullFilePath) : $altFileName;
// Try to guess the MIME type if the argument is NULL
$data['file_type'] = $mimeType === null ? mime_content_type($fullFilePath) : $mimeType;
// Request authorization to upload the file
$response = $this->_curlRequest(self::URL_UPLOAD_REQUEST, 'GET', $data);
$data['file_url'] = $response->file_url;
if (version_compare(PHP_VERSION, '5.5.0', '>=')) {
$response->data->file = new \CURLFile($fullFilePath);
} else {
$response->data->file = '@' . $fullFilePath;
}
// Upload the file
$this->_curlRequest($response->upload_url, 'POST', $response->data, false, false);
Connector::_parseRecipient($recipient, $data);
$data['type'] = 'file';
$data['title'] = $title;
$data['body'] = $body;
return $this->_curlRequest(self::URL_PUSHES, 'POST', $data);
}