PHP code example of hachi-zzq / alibaba
1. Go to this page and download the library: Download hachi-zzq/alibaba library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
hachi-zzq / alibaba example snippets
/**
* 阿里云参数配置
*/
return [
/**
* access_key_id
*/
'access_key_id' => 'access_key_id',
/**
* access_key_secret
*/
'access_key_secret' => 'access_key_secret',
'response_type' => 'collection',
/**
* 邮件推送服务
*/
'direct_mail' => [
/**
* 发信人,必须与阿里云后台配置的发信人一致
*/
'from' => '',
/**
* 发信人昵称
*/
'from_alias' => '',
/**
* 回信地址
*/
'reply_address' => false
]
];
### 初始化应用
$application = new \Hachi\Alibaba\Application([
/**
* access_key_id
*/
'access_key_id' => 'access_key_id',
/**
* access_key_secret
*/
'access_key_secret' => 'access_key_secret',
'response_type' => 'collection',
/**
* 邮件推送服务
*/
'direct_mail' => [
/**
* 发信人
*/
'from' => '[email protected] ',
/**
* 发信人昵称
*/
'from_alias' => '',
/**
* 回信地址
*/
'reply_address' => true
]
]);
### 调用邮件发送
#### 发送文本邮件
$textMessage = new \Hachi\Alibaba\DirectMail\TextMessage('这个是一个文本内容');
try {
$body = $application->direct_mail->singleSend('[email protected] ', $textMessage, '发送别名', '这个是主题');
} catch (\Hachi\Alibaba\Kernel\Exceptions\MailSendException $exception) {
dd($exception);
}
#### 发送HTML邮件
$html = "
<p>这个是段落</p>
";
$htmlMessage = new \Hachi\Alibaba\DirectMail\HtmlMessage($html);
try {
$body = $application->direct_mail->singleSend('[email protected] ', $htmlMessage, '发送别名', '这个是主题');
} catch (\Hachi\Alibaba\Kernel\Exceptions\MailSendException $exception) {
dd($exception);
}
dd($body);
### 调用语言合成
$outStream = $application->tts->speak('我是文本');
file_put_contents('/tmp/demo.mp3',$outStream);