/* library with necessary functions: */
include('for_smspay.php');
$my_pay = new ForSmspay(
'93aef5992a45ac09420376db01a56c7f', // your SMS-pay service id
'942e2059a5b1adfe8dcf1fbc4bac610e' // your SMS-pay service secret
);
/*
* NB! Response headers are set by session_start() function and thus,
* it must be executed before generating the response body.
*
* If your application already calls session_start() before executing this script,
* it will be recommended to remove the function call:
*/
if ($my_pay->sessions) {
session_start();
}
/* The content can be displayed by another script which generates HTML output: */
global $smspay_resp;
if ($my_pay->payment_verified()) {
/* User entered a valid password, authentication successful and the content can be displayed to the user */
$smspay_resp = $my_pay->restricted_content();
/* Or you can redirect the user to a separate script which verifies that $_SESSION["payment_ok"] is set: */
/*
* header('HTTP/1.0 302 Moved temporarily');
* header('Location: content.php');
*/
} else {
/*
* Invalid password or an error occurred;
* display the login widget with an error message
*/
$smspay_resp = $my_pay->widget();
}
?>
SMS-pay sample app
$FORSMSPAY_SERVER = "smspay.fortumo.com";
/*
* We do not use "http_get" as the function name here, because http_get
* has already been defined in the standard PHP 5 extension "http"
*/
function http_get4($url) {
$s = "";
if( ($fp = @fopen($url, 'r')) !== false ) {
while (!feof($fp)) { $s .= fgets($fp); }
}
return $s;
}
class ForSmspay {
/*
* Parameters:
* $id - your service_id
* $secret - your service secret
* $do_sessions - if true, authentication status will be kept in the session after successful authentication
*/
function ForSmspay($id, $secret, $do_sessions = true) {
$this->id = $id;
$this->secret = $secret;
$this->sessions = $do_sessions;
$this->error = "";
}
/*
* This function performs an HTTP GET request to http://smspay.fortumo.com/tokens/show/
* in order to authenticate a password submitted by an end-user.
*
* Mandatory request parameters:
* service_id - an unique string identifying your service
* (see the general configuration page of your service in Fortumo)
* code - password submitted by the end-user from your widget
* sig - request signature, generated as following:
* 1) concatenate request params as "param=value" strings in alphabetical order into one string
* 2) append your service secret to the end of this string
* 3) apply md5() to the result
*
* The result is an XML with status code and message
* Code "0" indicates successful authentication.
* Otherwise, authentication failed and the widget should be displayed to the end-user
*
*/
function authenticate($code) {
global $FORSMSPAY_SERVER;
if( strlen($code) == 0 ) {
return false;
} else {
$sig = md5("code=".urlencode($code)."service_id=".$this->id.$this->secret);
$response = http_get4(
"http://".$FORSMSPAY_SERVER."/tokens/show/?".
"service_id=".$this->id.
"&code=".urlencode($code).
"&sig=".$sig
);
// if we are using php5, use simplexml to parse the xml
if (version_compare(PHP_VERSION,'5','>=')) {
$doc = simplexml_load_string($response);
$status = $doc->status_code;
$message = $doc->message;
} else { // use domxml for parsing the xml
$doc = domxml_open_mem($response);
}
/* if xml parsing does not work for you for whatever reason,
* then comment it out and use the following regexp instead. */
/*
* Parameters which you can use to control the content of the widget:
*
* submit_url - the "SUBMIT" button on the widget needs to point to your password-processing script
* status_code - when password validation failed,
* use the status_code to reload the widget with a proper error message
*
* Description of error codes:
* 1 - password processing error
* 2 - end-user submitted a wrong password
* 3 - password has expired
* 6 - end-user reply SMS hasn't been billed yet (billing is pending)
* 7 - end-user reply SMS billing failed
*
*/
function widget() {
global $FORSMSPAY_SERVER;
$widget_params = "?submit_url=".$_SERVER['REQUEST_URI'];
if ($this->error != null) {
$widget_params = $widget_params."&status_code=".$this->error;
}
function restricted_content() {
return "Great Success!";
}
};
?>
19 Януари 08, 13:07
Коментари (1834)
[Foo7BaL3r$]-ll-[Your Nick]
Сайтът е конструиран с Glog. Dir.bg не носи отговорност за съдържанието и достоверността на публикуваните в сайта материали, както и за тяхното неправомерно използване от трети страни.