whatsapp-api-nodejs icon indicating copy to clipboard operation
whatsapp-api-nodejs copied to clipboard

qrcode only appears on localhost

Open rafaWPP opened this issue 3 years ago • 2 comments

qrcode only appears on localhost does not appear in php requests from a server

``$curl = curl_init();

curl_setopt_array($curl, array( CURLOPT_URL => 'IPSERVER:21228/instance/qrbase64?key=123', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', ));

$response = curl_exec($curl);

curl_close($curl); echo $response;``

return {"error":false,"message":"QR Base64 fetched successfully","qrcode":""}

rafaWPP avatar Sep 11 '22 13:09 rafaWPP

send me your full code ...

sairmali avatar Sep 18 '22 14:09 sairmali

Same error i'm getting an empty string for qr base64

i'm using PHP on a différent server where whatsapp-api-nodejs is installed. on a browser it's works after i'm using the PHP code the qrcode become empty (event when re-using it on a browser)

aelguezbari avatar Sep 19 '22 12:09 aelguezbari

Previously I also had this problem. Then I thought about adding a delay to the request. Because this API also takes a while to generate the QR Code. And this worked on my code. Give a 3-second delay on the request to get the QR Code after initializing the instance.

This is my code.

Init instance
    public function initInstance()
    {
        $token = Str::random(32);

        $response = $this->client->request('GET', 'instance/init', [
            'query' => [
                'token' => $token,
            ],
        ]);
        $response = $response->getBody()->getContents();
        $response = json_decode($response);

        return $response;
    }
Get QR Code in base64
    public function getBase64Qr($key)
    {
        sleep(3); // <-- Add delay for get QR Code
        $response = $this->client->request('GET', 'instance/qrbase64', [
            'query' => [
                'key' => $key,
            ],
        ]);
        $response = $response->getBody()->getContents();
        return json_decode($response);
    }
A Response

screely-1666786598937

It's work 👍🏼

IhsanDevs avatar Oct 26 '22 12:10 IhsanDevs