You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
< ? php
namespace tencent\wechat\weixin ;
use EasyWeChat\Factory ;
class Media extends Base
{
/**
* 将前台录音文件的MediaId( 即serverId) 文件下载到服务器
* @param string $media_id 媒体ID
* @param string $file_dirname 保存目录
* @param string $file_name 保存文件名,不带后缀
* @date 2022-08-14
*/
public function getMeidaIdFileToServer ( $media_id , $file_dirname , $file_name = '' )
{
// 公众号
$app = Factory :: officialAccount ( $this -> weixinConfig );
// 获取临时素材内容
$stream = $app -> media -> get ( $media_id );
if ( $stream instanceof \EasyWeChat\Kernel\Http\StreamResponse ) {
if ( $file_name ) {
// 自定义文件名,不需要带后缀
$result = $stream -> saveAs ( $file_dirname , $file_name );
} else {
// 以内容 md5 为文件名存到本地
$result = $stream -> save ( $file_dirname );
}
// 返回为文件名,拼接保存目录
return $file_dirname . '/' . $result ;
} else {
return $stream ;
}
}
}