Advertisement
Guest User

Untitled

a guest
Jul 29th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. * Sends SMS via Clickatell api
  2. *
  3. * @uses `wedevs_sms_via_clickatell` filter to fire
  4. *
  5. * @param type $sms_data
  6. * @return boolean
  7. */
  8. function clickatellAPI( $sms_data ) {
  9. $response = array(
  10. 'success' => false,
  11. 'message' => wedevs_sms_get_option( 'sms_sent_error' )
  12. );
  13.  
  14. $username = wedevs_sms_get_option( 'clickatell_username' );
  15. $password = wedevs_sms_get_option( 'clickatell_pass' );
  16. $api_key = wedevs_sms_get_option( 'clickatell_api' );
  17.  
  18. //bail out if nothing provided
  19. if ( empty( $username ) || empty( $password ) || empty( $api_key ) ) {
  20. return $response;
  21. }
  22.  
  23. // auth call
  24. $baseurl = "http://api.clickatell.com";
  25. $url = sprintf( '%s/http/auth?user=%s&password=%s&api_id=%s', $baseurl, $username, $password, $api_key );
  26.  
  27. // do auth call
  28. $ret = file( $url );
  29.  
  30. // explode our response. return string is on first line of the data returned
  31. $sess = explode( ":", $ret[0] );
  32. if ( $sess[0] == "OK" ) {
  33.  
  34. $sess_id = trim( $sess[1] ); // remove any whitespace
  35. $url = sprintf( '%s/http/sendmsg?session_id=%s&to=%s&text=%s', $baseurl, $sess_id, $sms_data['to'], $sms_data['text'] );
  36.  
  37. // do sendmsg call
  38. $ret = file( $url );
  39. $send = explode( ":", $ret[0] );
  40.  
  41. if ( $send[0] == "ID" ) {
  42. $response = array(
  43. 'success' => true,
  44. 'code' => $sms_data['code'],
  45. 'message' => wedevs_sms_get_option( 'sms_sent_msg' )
  46. );
  47. }
  48. }
  49.  
  50. return $response;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement