PHP code example of aldok10 / whatsappclientapi

1. Go to this page and download the library: Download aldok10/whatsappclientapi library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

aldok10 / whatsappclientapi example snippets




use AldoKarendra\WhatsappClient\Send\Chat;
use AldoKarendra\WhatsappClient\Auth\Qr;

//use your own config
$config = [
	'base_url' => 'http://127.0.0.1:3002/api/v1/whatsapp',
	'public_key' => 'aldo_k',
	'secret_key' => 'mysecretpassword',
	// 'enable_error' => true,
	'enable_error' => false,
];

// use Qr service
$qr = new Qr($config);

// get barcode if not scan barcode whatsapp
$response = $qr->getQr('html');

if ($response === '{"msg":"Sudah Login"}') {
	
	// use chat service
	$chat = new Chat($config);

	// Send Msg
	$response = $chat->text('6281234567890','Send Msg!');
	echo "<pre style='background:#fafafa;'>";
	var_dump($response);
	echo "</pre>";
} else {
	// echo $response;
	if ($response=='{"status":false,"message":"Akses Terlarang!","data":null}'){
		echo "invalid access public_key / secret_key!";
	} else {
		echo "Get Access. <br>";
		echo $response;
	}
}