PFinal\Wechat\Service\MaterialService::uploadFile PHP Method

uploadFile() public static method

新增永久素材 媒体文件类型别有图片(image)、语音(voice) 、视频(video)和缩略图(thumb)
public static uploadFile ( string $filename, string $type, string $title = null, string $introduction = null ) : array
$filename string
$type string
$title string 视频素材的标题 只对类型为video有效
$introduction string 视频素材的描述 只对类型为video有效
return array
    public static function uploadFile($filename, $type, $title = null, $introduction = null)
    {
        $filename = realpath($filename);
        if (class_exists('\\CURLFile')) {
            $data['media'] = new \CURLFile($filename);
        } else {
            $data['media'] = '@' . $filename;
        }
        $data['type'] = $type;
        if ($type === 'video') {
            $data['description'] = Json::encode(array('title' => $title, 'introduction' => $introduction));
        }
        $url = 'https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=ACCESS_TOKEN';
        return parent::request($url, $data, false);
    }

Usage Example

Example #1
0
File: mp.php Project: pfinal/wechat
if (isset($_GET['user'])) {
    $user = \PFinal\Wechat\Service\OAuthService::getUser();
    var_dump($user);
    exit;
}
if (isset($_GET['send'])) {
    $result = \PFinal\Wechat\Service\MessageService::send($openid2, new \PFinal\Wechat\Message\Text('test'));
    var_dump($result);
    exit;
}
if (isset($_GET['preview'])) {
    //$result = \PFinal\Wechat\Service\MessageService::previewWithWxname('rainphp',new \PFinal\Wechat\Message\Text('test'));
    //$result = \PFinal\Wechat\Service\MessageService::previewWithWxname('rainphp',new \PFinal\Wechat\Message\Image($imageMediaId));
    //$result = \PFinal\Wechat\Service\MessageService::previewWithWxname('rainphp',new \PFinal\Wechat\Message\Voice($voiceMediaId));
    //$result = \PFinal\Wechat\Service\MessageService::previewWithWxname('rainphp',new \PFinal\Wechat\Message\MpNews($newsMediaId));
    $result = \PFinal\Wechat\Service\MaterialService::uploadFile('./voice.mp3', 'music');
    var_dump($result);
    exit;
}
if (isset($_GET['redpack'])) {
    //o0N6bt-9GESHZIqAaxvlZvjW5Rwk
    //o0N6bt40edruwOR2OoOZDpj7slPY
    $result = \PFinal\Wechat\Service\RedPackService::send('o0N6bt2Ikobz0SY35sd76rubkOvc', 1.01);
    var_dump($result);
}
if (isset($_GET['qr'])) {
    //临时
    $result = \PFinal\Wechat\Service\QrcodeService::temporary(1000001, 60 * 60 * 24);
    $url = \PFinal\Wechat\Service\QrcodeService::url($result['ticket']);
    echo "<img src='{$url}'>";
    //永久 数字key