Skip to content

Instantly share code, notes, and snippets.

@ifirmawan
Created July 31, 2020 02:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ifirmawan/fcb4028ef69edc234571e79e67fec166 to your computer and use it in GitHub Desktop.
Save ifirmawan/fcb4028ef69edc234571e79e67fec166 to your computer and use it in GitHub Desktop.
Codeigniter library to create request send message via send.wanotif.com API
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Lib_whatsapp
{
protected $CI;
function __construct()
{
$this->CI =& get_instance();
$this->CI->load->config('whatsapp');
}
public function send_whatsapp($api, $number, $message) {
if (DEMO) {
$this->session->set_flashdata('error', 'Whatsapp are disabled in demo.');
return false;
}
$date = date('Y-m-d H:i:s');
try {
$client = new \GuzzleHttp\Client();
$wa_base_url = $this->CI->config->item('wa_base_url');
$response = $client->post("$wa_base_url/ssem_api/send_wa_api",
[
'form_params' => [
'api_key' => $api,
'mobile' => $number,
'reference_id' => 'wanotif', // you can change with your app name
'message' => $message
]
]
);
return true;
} catch (\Exception $e) {
$this->set_error($e->getMessage());
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment