收藏
回答

上传素材接口无响应,请问是什么问题呢?

上传素材接口无响应,请问是什么问题呢?也不知道是那里错了,本来好好的,忽然就这样了。求大佬指教一二,谢谢

代码如下:


public function t1 ()
{
    $url = 'https://api.weixin.qq.com/cgi-bin/media/upload?access_token=55_BMM8rdWhSg11sbZyx4mBQMyB6mKESFtWwr27HSinxrna6ALASsYWvD3ak7-EyXnDpxShPv9XVAU2o6ffK9WbFLV6E2B9G4XzSlgtB-iK1EWzlP01EvavVAyKe5c77inHht8CgZhbVxm_QZxmTDHaALDNXB&type=image';
    $img_path = Env::get('root_path') . 'public\uploads\20220416737486.jpeg';
    $media = new \CURLFile($img_path);
    $post = ['media' => $media];
    $res = $this->curl_request($url, $post, 'post');
    echo $res;
    dump($res);
}

function curl_request ($url, $data = null, $method = 'get', $https = true)
{
    $ch = curl_init();                             //初始化
    curl_setopt($ch, CURLOPT_URL, $url);           //访问的URL
    curl_setopt($ch, CURLOPT_HEADER, false);       //设置不需要头信息
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);//只获取页面内容,但不输出
    if ($https) {
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//https请求 不验证证书
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);//https请求 不验证HOST
    }
    if ($method == 'post') {
        curl_setopt($ch, CURLOPT_POST, true);       //请求方式为post请求
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);//请求数据
    }
    $result = curl_exec($ch);//执行请求
    curl_close($ch);         //关闭curl,释放资源
    return $result;
}
回答关注问题邀请回答
收藏
登录 后发表内容