1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| <?php
error_reporting(0); header('Access-Control-Allow-Origin:*'); header('Content-type: application/json');
$url = $_GET['url']; $mid = '';
if (empty($url)) { $Json = array( 'code' => '201', 'msg' => '生成失败', ); $Json = json_encode($Json,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE); echo stripslashes($Json); return $Json; }else{ postComment($url,$mid); }
function postComment($url, $mid) { $url = "https://www.weibo.com/aj/v6/comment/add"; $data = array( 'mid' => $mid, 'content' => $url ); $arr = json_decode(curl($url, $data), true);
if ($arr['code'] == '100000') { $data = $arr['data']['comment']; preg_match('/title=\"网页链接\" href=\"(.*?)\"/', $data, $shortUrl); preg_match('/comment_id=\"(.+\d)\"/', $data, $commentId); $Json = array( 'code' => '200', 'msg' => '生成成功', 'data' => array( 'comment_id' => $commentId[1], 'short_url' => $shortUrl[1] ) ); delCommen($commentId[1], $mid); } else { $Json = array( 'code' => '201', 'msg' => '生成失败', ); } $Json = json_encode($Json,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE); echo stripslashes($Json); return $Json; }
function delCommen($cid, $mid) { $url = "https://www.weibo.com/aj/comment/del"; $data = array( 'mid' => $mid, 'cid' => $cid ); $arr = curl($url, $data); }
function curl ($url, $post = null) { $headers[] = 'Cookie: SUB=你的cookie'; $headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36'; $headers[] = 'Content-Type : application/x-www-form-urlencoded'; $headers[] = 'Referer: https://www.weibo.com'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch,CURLOPT_HTTPHEADER,$headers); if (!empty($post)) { curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); } $result = curl_exec($ch); curl_close($ch); return $result; }
|