Please download sample code (PHP) from here.
- subscription.php This file includes all the functions related to subscription API
- notification.php This script collects the subscription notifications, which send to the app from ideamart (or simulator)
- definitions.php This file contains Ideamart API endpoint data
- log.php That helps to record activities.
First, add following script on the head of the PHP script for initializing settings
<?php
include_once "definitions.php";include_once "subscription.php";
$sub = new Subscription(); $AppId = "APP_000000"; $Password = ""; $SubscriberId ="tel:94771234567";
How to register a user?
$SubscriberId ="tel:94771234567";
// Register new user $sub->RegisterUser($AppId,$Password,$SubscriberId);
How to unregister a user?
$SubscriberId ="tel:94771234567";
// Unregister new user $sub->UnregisterUser($AppId,$Password,$SubscriberId);
Need to know how many users currently registered on your app?
(Please note that this function gives only the count of active users. On ideamart, PENDING CHARGE status doesn't count as an active user. So actual subscriber base may be higher than this value)
//Get subscription base size $baseSize = $sub->getBaseSize($AppId,$Password);
Are you need to check the status of your subscriber?
REGISTERED
UNREGISTERED
PENDING CHARGE
TEMPORARY_BLOCKED
BLOCKED
// Get user registration status $status = $sub->getStatus($AppId,$Password,$SubscriberId);
Subscription Notifications
When user registering or unregistering from your app, ideamart send a notification to your app. You need to give the URL of this script to "Subscription notification URL" in subscription API configurations.
<?php include_once 'log.php'; $array = json_decode(file_get_contents('php://input'), true); $applicationId =$array['applicationId']; $frequency= $array['frequency']; $status= $array['status']; $address= $array['subscriberId']; $version= $array['version']; $timeStamp= $array['timeStamp']; logFile(""); logFile("***********************************************"); logFile("address :$address"); logFile("frequency :$frequency"); logFile("status :$status"); logFile("timestamp :$timeStamp"); if($status=="REGISTERED") { // Do something }else if($status=="UNREGISTERED") { // Do something } ?>
Nice work!
ReplyDeleteවටිනා කියන ලිපියක් බොහොම ස්තුත්යි නුවන්
ReplyDeletecan you upload the database file also. Thanks.
ReplyDelete