Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- * Sends SMS via Clickatell api
- *
- * @uses `wedevs_sms_via_clickatell` filter to fire
- *
- * @param type $sms_data
- * @return boolean
- */
- function clickatellAPI( $sms_data ) {
- $response = array(
- 'success' => false,
- 'message' => wedevs_sms_get_option( 'sms_sent_error' )
- );
- $username = wedevs_sms_get_option( 'clickatell_username' );
- $password = wedevs_sms_get_option( 'clickatell_pass' );
- $api_key = wedevs_sms_get_option( 'clickatell_api' );
- //bail out if nothing provided
- if ( empty( $username ) || empty( $password ) || empty( $api_key ) ) {
- return $response;
- }
- // auth call
- $baseurl = "http://api.clickatell.com";
- $url = sprintf( '%s/http/auth?user=%s&password=%s&api_id=%s', $baseurl, $username, $password, $api_key );
- // do auth call
- $ret = file( $url );
- // explode our response. return string is on first line of the data returned
- $sess = explode( ":", $ret[0] );
- if ( $sess[0] == "OK" ) {
- $sess_id = trim( $sess[1] ); // remove any whitespace
- $url = sprintf( '%s/http/sendmsg?session_id=%s&to=%s&text=%s', $baseurl, $sess_id, $sms_data['to'], $sms_data['text'] );
- // do sendmsg call
- $ret = file( $url );
- $send = explode( ":", $ret[0] );
- if ( $send[0] == "ID" ) {
- $response = array(
- 'success' => true,
- 'code' => $sms_data['code'],
- 'message' => wedevs_sms_get_option( 'sms_sent_msg' )
- );
- }
- }
- return $response;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement