Post 图片到 localbitcoin 联系人

Post Image to localbitcoin contact

我正在尝试 post 从本地数据库到 localbitcoins 交易聊天的图像(附件)和消息,但它返回给我一个错误。是的,API 密钥有效并且可以使用其他方法。

{"error": {"message": "HMAC authentication key and signature was given, but they are invalid.", "error_code": 41}}

我不确定我做错了什么。有人可以告诉我吗?

    $path = '/api/contact_message_post/'.$contact_id."/";    
    
    $key= $this->API_AUTH_KEY;
    $secret= $this->API_AUTH_SECRET;      
 
    $array_mt = explode(' ', microtime());   
    $nonce = $array_mt[1].substr($array_mt[0], 2, 6);   
 
    $post = "";
    if ($req) {
       $post=http_build_query($req);
    }
    $postdata=$nonce.$key.$path.$post; 
 
    $sign = strtoupper(hash_hmac('sha256', $postdata, $secret)); 
   
    $headers = array(
       'Apiauth-Signature:'.$sign,
       'Apiauth-Key:'.$key,
       'Apiauth-Nonce:'.$nonce,
       'Content-type: multipart/form-data'
    );

    $ch = null;
    $ch = curl_init('https://localbitcoins.com'.$path); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    $res = curl_exec($ch);
    dd($res);
    if ($res === false) throw new \Exception('Curl error: '.curl_error($ch));
    $dec = json_decode($res, true);   
    if (!$dec) throw new \Exception('Invalid data: '.$res);
    curl_close($ch);   
    return $dec;

我正在尝试向这样的 post 数据添加附件。

$data = array(
            'document' => new \CURLFile(
                $_SERVER['DOCUMENT_ROOT'].'\attachments\'.$attachment, 
                'image/jpeg',
                $attachment
            ),
            'msg' => $messages[0]->message,
        );

我用的是Guzzle,也试过很多方法。所有其他方法都有效,但仅在发送图像时出现签名错误。我认为这是 Localbitcoins 方面的问题,我们应该联系支持人员。

我的代码:https://gist.github.com/021-code/4026086ab55735744fa8784375046d7d