如题,今天用到了 就分享一波给大家咯
token可以自行获取缓存里的,下面我只用一次 就直接获取token了
//新增永久图文素材
public function upload_article()
{
$res = file_get_contents('https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=appid&secret=secret');
$res = json_decode($res, true);
$token = $res['access_token'];
$url = "https://api.weixin.qq.com/cgi-bin/material/add_news?access_token=$token";
$data = '{
"articles": [{
"title": "这是个标题",
"thumb_media_id":"上传获取的图片素材ID",
"show_cover_pic":"1",
"content": "内容",
"content_source_url": "链接",
}]
}';
$result = $this->https_post($url, $data);
dump($result);
//$result = http_url($url, $data);
$res = json_decode($result, true);
//unlink($path);
}
function https_post($url, $post_data = null)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// post数据
curl_setopt($ch, CURLOPT_POST, 1);
// post的变量
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。