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 app\base\logic\weixin ;
use EasyWeChat\Factory ;
class Material extends Base
{
/**
* 获取全部素材列表
* @param string $type 素材的类型, 图片( image) 、视频( video) 、语音 ( voice) 、图文( news)
* @date 2022-12-01
*/
public function listMaterial ( $type )
{
$weixin_param = get_weixin_config ();
$material_logic = new \tencent\wechat\weixin\material\Material ( $weixin_param );
// 统计素材数量
$number = $material_logic -> countMaterial ();
// 相关类型素材数量
$total_number = $number [ $type . '_count' ];
// 每次加载数量
$per_page_number = 20 ;
// 向上取整获取页数
$page = ceil ( $total_number / $per_page_number );
$data_list = [];
for ( $i = 0 ; $i <= $page ; $i ++ ) {
$offset = $i * $per_page_number ;
$result = $material_logic -> listMaterial ( $type , $offset , $per_page_number );
$data_list = array_merge ( $data_list , $result [ 'item' ]);
}
return $data_list ;
}
}