php 微信开发之新增上传/获取下载临时素材 代码
function saveWeixinFile($filename, $filecontent)
{
$local_file = fopen($filename, 'w');
if (false !== $local_file){
if (false !== fwrite($local_file, $filecontent)) {
fclose($local_file);
}
}
}
function token(){
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".AppID."&secret=".AppSecret;
$data = json_decode(file_get_contents($url),true);
if($data['access_token']){
return $data['access_token'];
}else{
echo "Error";
exit();
}
}
?>
使用的注意事情。文件必须需要绝对的路径不能相对路径然后在路径前面加个@ (列子: @F:\\w.jpg) 这样才是正确的 然后type 类型自己定义一下。上传视频的为 video 图片为 image 音乐为 voice
图片(image): 1M,支持JPG格式
语音(voice):2M,播放长度不超过60s,支持AMR\MP3格式
视频(video):10MB,支持MP4格式
缩略图(thumb):64KB,支持JPG格式
各位记住了