upload() public static méthode

多媒体上传。上传图片、语音、视频等文件到微信服务器,上传后服务器会返回对应的media_id,公众号此后可根据该media_id来获取多媒体。 上传的多媒体文件有格式和大小限制,如下: 图片(image): 1M,支持JPG格式 语音(voice):2M,播放长度不超过60s,支持AMR\MP3格式 视频(video):10MB,支持MP4格式 缩略图(thumb):64KB,支持JPG格式 媒体文件在后台保存时间为3天,即3天后media_id失效。
public static upload ( $filename, $type ) : {"type":"TYPE","media_id":"MEDIA_ID","created_at":123456789}
Résultat {"type":"TYPE","media_id":"MEDIA_ID","created_at":123456789}
Exemple #1
0
 /**
  * 上传图片
  */
 public function uploadImg()
 {
     //'ybFlQ9kmPTgiCWZT8Mq_1YnKtBziwpbaVDaftpJckPtFzlwROlgXpKCd9Dbl_JRs'
     if (!empty($_FILES)) {
         $info = reset(upload());
         $data = Media::upload(realpath($info['file_save_path']), 'image');
         file_put_contents('./wx-test/uploadimg.txt', json_encode($data));
         dump($data);
     }
     //        dump(  Media::upload(realpath('./Public/Uploads/2015-09-23/560218d10525f.jpg'),'image' ));
 }
Exemple #2
0
//下载多媒体
\LaneWeChat\Core\Media::download($mediaId);
/**
 * 自定义菜单
 */
//设置菜单
$menuList = array(array('id' => '1', 'pid' => '', 'name' => '常规', 'type' => '', 'code' => 'key_1'), array('id' => '2', 'pid' => '1', 'name' => '点击', 'type' => 'click', 'code' => 'key_2'), array('id' => '3', 'pid' => '1', 'name' => '浏览', 'type' => 'view', 'code' => 'http://www.lanecn.com'), array('id' => '4', 'pid' => '', 'name' => '扫码', 'type' => '', 'code' => 'key_4'), array('id' => '5', 'pid' => '4', 'name' => '扫码带提示', 'type' => 'scancode_waitmsg', 'code' => 'key_5'), array('id' => '6', 'pid' => '4', 'name' => '扫码推事件', 'type' => 'scancode_push', 'code' => 'key_6'), array('id' => '7', 'pid' => '', 'name' => '发图', 'type' => '', 'code' => 'key_7'), array('id' => '8', 'pid' => '7', 'name' => '系统拍照发图', 'type' => 'pic_sysphoto', 'code' => 'key_8'), array('id' => '9', 'pid' => '7', 'name' => '拍照或者相册发图', 'type' => 'pic_photo_or_album', 'code' => 'key_9'), array('id' => '10', 'pid' => '7', 'name' => '微信相册发图', 'type' => 'pic_weixin', 'code' => 'key_10'), array('id' => '11', 'pid' => '1', 'name' => '发送位置', 'type' => 'location_select', 'code' => 'key_11'));
\LaneWeChat\Core\Menu::setMenu($menuList);
//获取菜单
\LaneWeChat\Core\Menu::getMenu();
//删除菜单
\LaneWeChat\Core\Menu::delMenu();
/**
 * 应用一:给粉丝群发发送消息
 */
//群发消息
//获取粉丝列表
$fansList = \LaneWeChat\Core\UserManage::getFansList();
//上传图片
$menuId = \LaneWeChat\Core\Media::upload('/var/www/baidu_jgylogo3.jpg', 'image');
if (empty($menuId['media_id'])) {
    die('error');
}
//上传图文消息
$list = array();
$list[] = array('thumb_media_id' => $menuId['media_id'], 'author' => '作者', 'title' => '标题', 'content_source_url' => 'www.lanecn.com', 'digest' => '摘要', 'show_cover_pic' => '1');
$list[] = array('thumb_media_id' => $menuId['media_id'], 'author' => '作者', 'title' => '标题', 'content_source_url' => 'www.lanecn.com', 'digest' => '摘要', 'show_cover_pic' => '0');
$list[] = array('thumb_media_id' => $menuId['media_id'], 'author' => '作者', 'title' => '标题', 'content_source_url' => 'www.lanecn.com', 'digest' => '摘要', 'show_cover_pic' => '0');
$mediaId = \LaneWeChat\Core\AdvancedBroadcast::uploadNews($list);
//给粉丝列表的用户群发图文消息
$result = \LaneWeChat\Core\AdvancedBroadcast::sentNewsByOpenId($fansList['data']['openid'], $mediaId);