CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviSMS »
  • Add new sms provider
Pages: [1]

Author Topic: Add new sms provider  (Read 2161 times)

aliosman20

  • I’m new here
  • *
  • Posts: 7
  • Karma: 0
  • CiviCRM version: 4.3.1
  • CMS version: drupal 7
  • MySQL version: mysql5
  • PHP version: php5
Add new sms provider
April 26, 2013, 07:35:27 am
Hi,

I tried to add new provider (as extension) based on twilio extension and made some modification on code.

But when I tried to send sms, message of sms part ($message) send to my provider but numbers ( $header['to'] ) does not send to my provider by this code.

I am not familiar witp php, but if somebody help me on this issue I appreciate.

My code is here for send fuunction:

Code: [Select]
  function send($recipients, $header, $message, $jobID = NULL) {
    if ($this->_apiType = 'http') {
      list($url, $postData) = $this->formURLPostData("");
      $postData['numaralar'] = $header['to'];
      $postData['mesaj'] = $message;
  $postData['islem'] = "1";
  $postData['baslik'] = "YYYYY";
  $postData['user'] = "YYYYY";
  $postData['pass'] = "YYYYY";
     
      $response = $this->curl($url, $postData);
 
      if (PEAR::isError($response)) {
        return $response;
      }
 
      $send = simplexml_load_string($response['data']);
      $sid = $send->SMSMessage->Sid;
      if (!empty($sid)) {
        $this->createActivity($sid, $message, $header, $jobID);
        return $sid;
      }
      else {
        return PEAR::raiseError($response['data']);
      }
    }
  }
 

Thanks
« Last Edit: April 26, 2013, 07:38:03 am by aliosman20 »

Michael McAndrew

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1274
  • Karma: 55
    • Third Sector Design
  • CiviCRM version: various
  • CMS version: Nearly always Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Add new sms provider
May 08, 2013, 10:26:40 am
what happens if you do some basic debugging, e.g. print_r($header['to']);exit; after $postData['numaralar'] = $header['to'];
do you see the number?
Quote
I am not familiar witp php
are you famililar with programming in general?
it might help if you share more of the code that you are using to give people more of a chance to debug this.
Service providers: Grow your business, build your reputation and support CiviCRM. Become a partner today

aliosman20

  • I’m new here
  • *
  • Posts: 7
  • Karma: 0
  • CiviCRM version: 4.3.1
  • CMS version: drupal 7
  • MySQL version: mysql5
  • PHP version: php5
Re: Add new sms provider
May 10, 2013, 07:08:41 am
Hi Michael,

Thank you for your reply.

Yes I am not familiar with programming in general but I know some basic things about programming.

My  sms provider send to me some php code to send sms to their server:

Code: [Select]
<?php
function sms_send ($Url,$strRequest)
{
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1) ;
curl_setopt($ch, CURLOPT_POSTFIELDS, $strRequest);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$result = curl_exec($ch);
curl_close($ch);
return 
$result;
}


$durum = sms_send("http://asuzsms.com/api-center/","islem=1&user=xxx&pass=yyy&mesaj=deneme&numaralar=5324887803,5077023679,5077023680&baslik=BASLIKSIZ");
#$durum = sms_send("http://asuzsms.com/api-center/","islem=2&user=xxx&pass=yyy");
#$durum = sms_send("http://asuzsms.com/api-center/","islem=3&user=xxx&pass=yyy");

echo $durum;

?>


They said

Post parameter should be:

islem=1
user=myusername
pass=mypassword
mesaj=message
numaralar=numbers
baslik=BASLIKSIZ

This is my all code  we use with civicrm:

Code: [Select]
class com_osseed_sms_mysmsmantra extends CRM_SMS_Provider {

  /**
   * api type to use to send a message
   * @var string
   */
  protected $_apiType = 'http';

  /**
   * provider details
   * @var string
   */
  protected $_providerInfo = array();

  /**
   * Curl handle resource id
   *
   */
  protected $_ch;

  public $_apiURL = "http://asuzsms.com/api-center/";

  protected $_messageType = array(
  );

  protected $_messageStatus = array(
  );

  /**
   * We only need one instance of this object. So we use the singleton
   * pattern and cache the instance in this variable
   *
   * @var object
   * @static
   */
  static private $_singleton = array();

  /**
   * Constructor
   *
   * Create and auth a Twilio session.
   * This is not needed for Twilio
   *
   * @return void
   */
  function __construct($provider = array(
     ), $skipAuth = TRUE) {
    // initialize vars
    $this->_apiType = CRM_Utils_Array::value('api_type', $provider, 'http');
    $this->_providerInfo = $provider;

    if ($skipAuth) {
      return TRUE;
    }

    // first create the curl handle

    /**
     * Reuse the curl handle
     */
    $this->_ch = curl_init();
    if (!$this->_ch || !is_resource($this->_ch)) {
      return PEAR::raiseError('Cannot initialise a new curl handle.');
    }

    $this->authenticate();
  }

  /**
   * singleton function used to manage this object
   *
   * @return object
   * @static
   *
   */
  static function &singleton($providerParams = array(
    ), $force = FALSE) {
    $providerID = CRM_Utils_Array::value('provider_id', $providerParams);
    $skipAuth   = $providerID ? FALSE : TRUE;
    $cacheKey   = (int) $providerID;

    if (!isset(self::$_singleton[$cacheKey]) || $force) {
      $provider = array();
      if ($providerID) {
        $provider = CRM_SMS_BAO_Provider::getProviderInfo($providerID);
      }
      self::$_singleton[$cacheKey] = new com_osseed_sms_mysmsmantra($provider, $skipAuth);
    }
    return self::$_singleton[$cacheKey];
  }

  /**
   * Authenticate to the Twilio Server.
   * Not needed in Twilio
   * @return boolean TRUE
   * @access public
   * @since 1.1
   */
  function authenticate() {
      return (TRUE);
  }

  function formURLPostData($url, $id = NULL) {
    $url = $this->_providerInfo['api_url'] . $url;
    $postData = array();
    return array($url, $postData);
  }

  /**
   * Send an SMS Message via the Twilio API Server
   *
   * @param array the message with a to/from/text
   *
   * @return mixed true on sucess or PEAR_Error object
   * @access public
   */
  function send($recipients, $header, $message, $jobID = NULL) {
    if ($this->_apiType = 'http') {
      list($url, $postData) = $this->formURLPostData("");
      $postData['to'] = $header['to'];
      $postData['mesaj'] = $message;
  $postData['islem'] = "1";
  $postData['baslik'] = "yyyyyyy";
  $postData['user'] = "yyyyyyy";
  $postData['pass'] = "yyyyyyy";
     
      $response = $this->curl($url, $postData);
 
      if (PEAR::isError($response)) {
        return $response;
      }
 
      $send = simplexml_load_string($response['data']);
      $sid = $send->SMSMessage->Sid;
      if (!empty($sid)) {
        $this->createActivity($sid, $message, $header, $jobID);
        return $sid;
      }
      else {
        return PEAR::raiseError($response['data']);
      }
    }
  }

  function callback() {
  return TRUE;
  }

  function inbound() {
    $like      = "";
    $fromPhone = $this->retrieve('From', 'String');
    return parent::inbound($fromPhone, $this->retrieve('mesaj', 'String'), NULL, $this->retrieve('SmsSid', 'String'));
  }
 
  /**
   * Perform curl stuff
   *
   * @param   string  URL to call
   * @param   string  HTTP Post Data
   * @param   string  Authorization string composed of Account SID and Secret Key
   
   * @return  mixed   HTTP/XML response body or PEAR Error Object
   * @access private
   */
  function curl($url, $postData) {
    $this->_fp = tmpfile();
    curl_setopt($this->_ch, CURLOPT_URL, "http://asuzsms.com/api-center/");
    curl_setopt($this->_ch, CURLOPT_POST, 1);
    curl_setopt($this->_ch, CURLOPT_POSTFIELDS, $postData);
    curl_setopt($this->_ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($this->_ch, CURLOPT_RETURNTRANSFER, 1);

    $status = curl_exec($this->_ch);
   
    $response['http_code'] = curl_getinfo($this->_ch, CURLINFO_HTTP_CODE);
   
    if (empty($response['http_code'])) {
      return PEAR::raiseError('No HTTP Status Code was returned.');
    }
    elseif ($response['http_code'] === 0) {
      return PEAR::raiseError('Cannot connect to the Twilio API Server.');
    }

    $response['data'] = $status;
    asort($response);
   
    return ($response);
  }
}


Thank you for your help.

Ali
« Last Edit: May 10, 2013, 07:14:01 am by aliosman20 »

aliosman20

  • I’m new here
  • *
  • Posts: 7
  • Karma: 0
  • CiviCRM version: 4.3.1
  • CMS version: drupal 7
  • MySQL version: mysql5
  • PHP version: php5
Re: Add new sms provider
May 30, 2013, 01:31:31 am
ANY help  please!!!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviSMS »
  • Add new sms provider

This forum was archived on 2017-11-26.