官方文档地址: 创建二维码
论坛帖子地址: {errcode:40002,errmsg:bad access_token}
解决代码
/**
* 获取小程序/小游戏的二维码。
* @return array|string
*/
public function create()
{
$access_token = ‘‘;
$request_url = ‘https://developer.toutiao.com/api/apps/qrcode‘;
$query = [
‘access_token‘ => $access_token,
‘appname‘=>‘douyin‘,
];
$headerArray = ["Content-type:application/json"];
$CurlServer = new CurlServer();
$result = $CurlServer->curl_post($request_url,$query,$headerArray);
print_r($result);
exit;
return $result;
}
此处返回的是一个图片 Buffer,不是链接, 可以使用以下方法写入图片。返回地址
//将图片buffer 写入
$file = fopen("./qrcode/123.jpg","w");//创建件准备写入,
fwrite($file,$result);//写入
fclose($file);//关闭
curlpost
public static function curl_post($url,$data=array(),$headerArray=[]){
$data = json_encode($data);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl,CURLOPT_HEADER,0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl,CURLOPT_HTTPHEADER,$headerArray);
//ssl false
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,FALSE);
$output = curl_exec($curl);
curl_close($curl);
return $output;
}