Gaoming13\WechatPhpSdk\Api::add_material PHP Method

add_material() public method

Examples: 新增图片素材 list($err, $res) = $api->add_material('image', '/website/me/data/img/fighting.jpg'); 新增音频素材 list($err, $res) = $api->add_material('voice', '/data/img/song.amr'); 新增视频素材 list($err, $res) = $api->add_material('video', '/website/me/data/video/2.mp4', '视频素材的标题', '视频素材的描述'); 新增略缩图素材 list($err, $res) = $api->add_material('thumb', '/data/img/sky.jpg'); Result: [ null, { media_id: "BZ-ih-dnjWDyNXjai6i6sbK8hTy_bs-PHtnLn8C-IAs", url: "https://mmbiz.qlogo.cn/mmbiz/InxuM0bx4ZWgxicicoy2tLibV2hyO5hWT4VlHNI6LticmppBiaG12cJ8icDoSR83zFSKDAz8qnY1miatZiaX8pZKUaIt7w/0?wx_fmt=jpeg" } ]
public add_material ( string $type, string $path, string $title = '', string $introduction = '' ) : array(err,
$type string 媒体文件类型,分别有图片(image)、语音(voice)、视频(video)和缩略图(thumb)
$path string 要上传文件的绝对路径
$title string 可选: 视频素材的标题(video)
$introduction string 可选: 视频素材的描述(video)
return array(err,
    public function add_material($type, $path, $title = '', $introduction = '')
    {
        $url = self::API_DOMAIN . 'cgi-bin/material/add_material?access_token=' . $this->get_access_token() . '&type=' . $type;
        $post_data = array('media' => '@' . $path);
        if ($type == 'video') {
            $post_data['description'] = sprintf('{"title":"%s","introduction":"%s"}', $title, $introduction);
        }
        $res = HttpCurl::post($url, $post_data, 'json');
        // 异常处理: 获取时网络错误
        if ($res === false) {
            return Error::code('ERR_POST');
        }
        // 判断是否调用成功
        if (isset($res->media_id)) {
            return array(null, $res);
        } else {
            return array($res, null);
        }
    }