php - How to Integrate 3rd party API in Wordpress -
i'm using wordpress , want integrate sms api wordpress site. can in knowing (in file) write code integration , code integrate sms api.
my sms api url : http://www.elitbuzzsms.com/app/smsapi/index.php?key=key&campaign=****&routeid=**&type=text&contacts=< number >&senderid=smsmsg&msg=< message content >
i want integrate above api in wordpress theme can send sms based on mobile number , add required message.
in wordpress can use wp_remote_get , wp_remote_post
get request example
$url = 'http://www.elitbuzzsms.com/app/smsapi/index.php?key=key&campaign=****&routeid=**&type=text&contacts=< number >&senderid=smsmsg&msg=< message content >'; $response = wp_remote_get( $url ); if( is_array($response) ) { $header = $response['headers']; // array of http header lines $body = $response['body']; // use content }
post request example
$response = wp_remote_post( $url, array( 'method' => 'post', 'timeout' => 45, 'redirection' => 5, 'httpversion' => '1.0', 'blocking' => true, 'headers' => array(), 'body' => array( 'username' => 'bob', 'password' => '1234xyz' ), 'cookies' => array() ) ); if ( is_wp_error( $response ) ) { $error_message = $response->get_error_message(); echo "something went wrong: $error_message"; } else { echo 'response:<pre>'; print_r( $response ); echo '</pre>'; }
Comments
Post a Comment