通过接口获取公众号发布文章

2022-07-16

获取access_token

$appid ="wx7********c6b5";
$secret = "1075***********1531"; //不能放在代码中,如何存储???
function getAccessToken($appid,$secret){
$curl = curl_init(); // 启动一个CURL会话
$url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret; //access_token有效2小时,如何处理???
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
$tmpInfo = curl_exec($curl); //返回api的json对象
//关闭URL请求
curl_close($curl);
return json_decode($tmpInfo)->{'access_token'}; //返回
}
$appid ="wx7********c6b5"; $secret = "1075***********1531"; //不能放在代码中,如何存储??? function getAccessToken($appid,$secret){ $curl = curl_init(); // 启动一个CURL会话 $url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret; //access_token有效2小时,如何处理??? curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在 $tmpInfo = curl_exec($curl); //返回api的json对象 //关闭URL请求 curl_close($curl); return json_decode($tmpInfo)->{'access_token'}; //返回 }
$appid ="wx7********c6b5";
$secret = "1075***********1531";   //不能放在代码中,如何存储???
function getAccessToken($appid,$secret){
	$curl = curl_init(); // 启动一个CURL会话
	$url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret;  //access_token有效2小时,如何处理???
	curl_setopt($curl, CURLOPT_URL, $url);
	curl_setopt($curl, CURLOPT_HEADER, 0);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
	curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);  // 从证书中检查SSL加密算法是否存在

	$tmpInfo = curl_exec($curl);     //返回api的json对象
	//关闭URL请求
	curl_close($curl);
	return json_decode($tmpInfo)->{'access_token'};    //返回
}

通过接口获取文章

function getArticleList($appid,$secret,$offset,$length=5,$noc=1){
$data = array(
'offset'=>$offset,
'count'=>$length,
'no_content'=>$noc
);
$data2 = json_encode($data);
$ch = curl_init();
$AccessToken = getAccessToken($appid,$secret);
curl_setopt($ch, CURLOPT_URL, 'https://api.weixin.qq.com/cgi-bin/draft/batchget?access_token='.$AccessToken);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data2);
$output = curl_exec($ch);
curl_close($ch);
return json_decode($output);
}
$op = getArticleList($appid,$secret,0);
print_r($op);
function getArticleList($appid,$secret,$offset,$length=5,$noc=1){ $data = array( 'offset'=>$offset, 'count'=>$length, 'no_content'=>$noc ); $data2 = json_encode($data); $ch = curl_init(); $AccessToken = getAccessToken($appid,$secret); curl_setopt($ch, CURLOPT_URL, 'https://api.weixin.qq.com/cgi-bin/draft/batchget?access_token='.$AccessToken); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch,CURLOPT_POST,1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data2); $output = curl_exec($ch); curl_close($ch); return json_decode($output); } $op = getArticleList($appid,$secret,0); print_r($op);
function getArticleList($appid,$secret,$offset,$length=5,$noc=1){
	$data = array(
        'offset'=>$offset,
        'count'=>$length,
		'no_content'=>$noc
    );
	$data2 = json_encode($data);
    $ch = curl_init();
	$AccessToken = getAccessToken($appid,$secret);
    curl_setopt($ch, CURLOPT_URL, 'https://api.weixin.qq.com/cgi-bin/draft/batchget?access_token='.$AccessToken);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    
	curl_setopt($ch,CURLOPT_POST,1);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data2);
    $output = curl_exec($ch);
    
    curl_close($ch);
	return json_decode($output);
}

$op = getArticleList($appid,$secret,0);
print_r($op);

// 获取公众号文章,因为公众号目前没有开放获取群发文章的接口,放弃获取公众号文章给小程序用

相关内容
最新

坚持的力量

wordpress建站,视频剪辑拍摄,动画制作