Skip to content

Instantly share code, notes, and snippets.

@v1shwa
Last active December 20, 2015 00:09
Show Gist options
  • Save v1shwa/6039359 to your computer and use it in GitHub Desktop.
Save v1shwa/6039359 to your computer and use it in GitHub Desktop.
Simple Txtweb Push API Example.
<?php
function txtweb_push($app_key,$pub_key,$mobile_hash,$message) {
//setup message
$message = trim($message);
$message = urlencode("<html><head><meta name=\"txtweb-appkey\" content=\"$app_key\" /></head>
<body>$message</body></html>");
//Set parameters for post request
$fields = "txtweb-message=$message&txtweb-pubkey=$pub_key&txtweb-mobile=$mobile_hash";
$ch = curl_init();
$url = "http://api.txtweb.com/v1/push";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$push_request = curl_exec($ch);
$doc = new DOMDocument();
$doc -> loadXML($push_request);
$status_code = $doc -> getElementsByTagName('code') -> item(0) -> nodeValue;
$status_msg = $doc -> getElementsByTagName('message') -> item(0) -> nodeValue;
//return array containing status code & status message
return array($status_code,$status_msg);
}
?>
@Karthick11
Copy link

Hi Vishwa,

I am new to txtweb development, just now i started to learn php to develop applications, may i know whats the use of mobile hash and curl_setopt function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment