http_build_query(array) 中文乱码问题

public static function newCurl($url, $data = array(), $timeout = 5)
{
    $ch = curl_init();
    if (is_array($data) && $data) {
        $formdata = http_build_query($data);
        $formdata = urldecode($formdata); // 处理中文加密
        // dump($formdata);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $formdata);
    }
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
}
$formdata = urldecode($formdata); // 处理中文加密
posted @ 2020-09-16 17:03  TBHacker  阅读(1151)  评论(0编辑  收藏  举报