抖音小程序码
public function dyqrcode($uid)
{
$url = "https://open.douyin.com/api/apps/v1/qrcode/create";
$data['appid'] = $this->client_key;
$data['app_name'] = 'douyin';
$data['is_circle_code'] = true;
$data['path'] = urlencode('pages/indexs/start/start?spcode=' . $uid);
$data = json_encode($data);
$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
$headers = array(
'access-token: ' . $this->Token(),
'Content-Type: application/json',
'Content-Length: ' . strlen($data)
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
if (!empty($data)) {
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curl);
curl_close($curl);
$result = json_decode($output, true);
if ($result['err_no'] == '0') {
$imageName = "p_" . date("His", time()) . "_" . rand(1111, 9999) . '.jpg';
$path = "upload/dyqrcode/" . date("Ymd");
if (!is_dir($path)) { //判断目录是否存在 不存在就创建
mkdir($path, 0777, true);
chmod($path, 0777);
}
$imageSrc = $path . "/" . $imageName; //图片名字
$r = file_put_contents($imageSrc, base64_decode($result['data']['img']));//返回的是字节数
Db::table('member')->where(array('id' => $uid))->update(['dy_qrcode' => $imageSrc]);
return $path . "/" . $imageName;
} else {
return $this->error($result['err_msg']);
}
}