PHP根据登录Cookie请求接口获取数据插入数据库

PHP根据登录Cookie请求接口获取数据插入数据库




//  RUL   http://休息休息吧/app/index.php?i=44&c=entry&rid=1&do=luo&m=xiaoka_xiaoshuo

$url_a = "https://嘻嘻嘻嘻嘻嘻嘻/backend/wx_articles/api_get_titles?type=2&classify=1&gender=3&keyword=&wx_article_resource_type=1&per_page=20&_=1596074960324&page=";

for ($i=1;$i<=215;$i++){

    $url  =  $url_a . $i;
    $cookie = "aliyungf_tc=AQAAABCfdDYaUwgAFjZM2t6dMyyPSpBI; _uab_collina=159607490330349442426543; user_token=d1364125c5ee4344a6323112e259cf7a; Hm_lvt_8276ab5fd9ad1c07baf8c57b0ab16945=1596074932; last_read_notice_id_81639=597; Hm_lpvt_8276ab5fd9ad1c07baf8c57b0ab16945=1596074961";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// 我们在POST数据哦!
    curl_setopt($ch, CURLOPT_POST, 1);
// 把post的变量加上
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    curl_setopt($ch, CURLOPT_COOKIE, $cookie);
    $output = curl_exec($ch);
    curl_close($ch);
//    echo $output;

    $output =  json_decode($output,true);
    foreach ($output as $key => $value){

      $title  =  removeEmojiChar($value['title']);

        $saveData = array(
            'title' => $title,
            'pid'=> $value['id']
        );


        echo $value['title'];
        echo PHP_EOL;

        pdo_insert("xiaoka_luo", $saveData);


    }





}




function removeEmojiChar($str)
{
    $mbLen = mb_strlen($str);

    $strArr = [];
    for ($i = 0; $i < $mbLen; $i++) {
        $mbSubstr = mb_substr($str, $i, 1, 'utf-8');
        if (strlen($mbSubstr) >= 4) {
            continue;
        }
        $strArr[] = $mbSubstr;
    }

    return implode('', $strArr);
}






你可能感兴趣的:(php函数)