长网址变短网址的实现方法
1.百度短网址(https://dwz.cn/console/apidoc)
1 <?php 2 $host = 'https://dwz.cn'; 3 $path = '/admin/v2/create'; 4 $url = $host . $path; 5 $method = 'POST'; 6 $content_type = 'application/json'; 7 8 // TODO: 设置Token 9 $token = '你的Token'; 10 11 // TODO:设置待注册长网址 12 $bodys = array('Url'=>'你的长网址', 'TermOfValidity'=>'有效期'); 13 14 // 配置headers 15 $headers = array('Content-Type:'.$content_type, 'Token:'.$token); 16 17 // 创建连接 18 $curl = curl_init($url); 19 curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); 20 curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); 21 curl_setopt($curl, CURLOPT_FAILONERROR, false); 22 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 23 curl_setopt($curl, CURLOPT_HEADER, false); 24 curl_setopt($curl, CURLOPT_POST, true); 25 curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($bodys)); 26 27 // 发送请求 28 $response = curl_exec($curl); 29 curl_close($curl); 30 31 // 读取响应 32 var_dump($response); 33
资料来源:百度短网址生成接口https://dwz.cn/console/apidoc