Job2 Street

Sunday, June 10, 2018

How to send WhatsApp Messages from PHP

How to send WhatsApp Messages from PHP

Using the WhatsMate WA Gateway REST API



This article shows you how to send a WhatsApp message from PHP.
Before the recipient can receive your WhatsApp message, she will need to register with the WhatsMate WA Gateway. Instructions are available on the official siteUnregistered users will never receive messages from the Gateway.
To send a WhatsApp message from PHP, do this:
  1. Copy the following source code to your script.
    <?php
    $INSTANCE_ID = 'YOUR_INSTANCE_ID_HERE'; // TODO: Replace it with your gateway instance ID here
    $CLIENT_ID = "YOUR_CLIENT_ID_HERE"; // TODO: Replace it with your Forever Green client ID here
    $CLIENT_SECRET = "YOUR_CLIENT_SECRET_HERE"; // TODO: Replace it with your Forever Green client secret here
    $postData = array(
    'number' => '12025550108', // TODO: Specify the recipient's number here. NOT the gateway number
    'message' => 'Howdy! Is this exciting?'
    );
    $headers = array(
    'Content-Type: application/json',
    'X-WM-CLIENT-ID: '.$CLIENT_ID,
    'X-WM-CLIENT-SECRET: '.$CLIENT_SECRET
    );
    $url = 'http://api.whatsmate.net/v3/whatsapp/single/text/message/' . $INSTANCE_ID;
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData));
    $response = curl_exec($ch);
    echo "Response: ".$response;
    curl_close($ch);
    ?>
    view rawsend-whatsapp.php hosted with ❤ by GitHub
  2. Customize the TODO lines:
    • Specify your gateway instance ID on line 2.
    • Specify your client ID and secret on lines 3 and 4.
    • Specify your target recipient on line 7. Remember to include the country code.
    • Specify your message on line 8.
  3. Visit the PHP page your just created to send your message.
You will need a trial account to call the above API. Go sign up now.

No comments:

Post a Comment

K-Play

kPlaylist - get your music online

The player will show in this paragraph

2 3

IkimFM

speaker music speaker