小程序推广二维码生成
<?php
$appid = '***************';
$secret ='********************************';
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$secret}";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$token = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
header('content-type:image/gif');
$openid = "*********************";
$data['scene'] = "uid=" . $a;
$data['page'] = "pages/index/index";
$data = json_encode($data);
$access = json_decode($token,true);
$access_token= $access['access_token'];
$url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" . $access_token;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //没有这个会自动输出,不用print_r();也会在后面多个1
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$output = curl_exec($ch);
curl_close($ch);
$out = json_decode($output);
$newFilePath=$openid.'.jpg';
$newFile = fopen($newFilePath,"w");
fwrite($newFile,$output);
fclose($newFile);
?>