laboratory analysis

One of your cell phone unlock resellers asks you about testing the StockUnlocks plugin for WordPress by using the using the Dhru Fusion GSM API with your unlock server. However, you don’t have an API test service for them to try and you need to know how to create one.

If you don’t want resellers testing against your Dhru Fusion GSM server, then stop now and direct them to test the StockUnlocks plugin for WordPress with the StockUnlocks test server. StockUnlocks is not a direct supplier and does not offer mobile or cell phone unlocking services. StockUnlocks is not your competition.

StockUnlocks simply provides the resources for both the resellers and the Dhru Fusion GSM direct source suppliers. Our goal is to make the remote unlocking process go as smoothly as possible.

What are the benefits of using API test services? Test services allow resellers to:

  • Confirm that their website properly connects with your unlock server
  • Customize their email templates with their own message
  • Simulate the receipt of a successful unlock code (Order available)
  • Simulate the failure of an unlock code (Order rejected)

Creating an API test service involves the following steps:

  • Adding a new test IMEI service to your Dhru Fusion GSM server
  • Setting the test IMEI service delivery time and service price
  • Activating the test IMEI service
  • Creating a scheduled cron job to reply to the test IMEI service

When processing cell phone unlock orders, you know that everything doesn’t always go as planned.

The following messages are sent from the Dhru Fusion GSM Server:

  • An unlock code is delivered, the iPhone is successfully unlocked
  • The unlock order gets rejected for one reason or another

With this in mind, it’s a good idea to create 2 API test services: one to represent the Code Available and the other to represent the Code Unavailable or Rejected service. This allows your resellers to simulate a real world scenario where cell phone unlock codes are delivered and sometimes not.

How to Create an IMEI Service: Dhru Fusion GSM 

To create an IMEI service for your Dhru Fusion GSM server, follow these steps:

Step 1: Log into your Dhru Fusion GSM unlock server

dhru fusion gsm selecting imei servicesStep 2: Click on Products/Services >IMEI Service

dhru fusion gsm add new imei service

Step 3: Click on Add New Services

Step 4: Enter the name of the service in the SERVICE NAME text field

The goal is to create 2 API test services, one for Code Available and the other for Code Unavailable.

dhru fusion gsm new imei service settings pageEnter a name that best describes the service you are creating. e.g. API Test – Available or API Test – Unavailable

Step 5: Set the STATUS toggle switch to ACTIVE

Step 6: Set the SEND FOR VERIFICATION toggle switch to NO

Step 7: Set the USER CAN CANCEL ORDER toggle switch to NO

Step 8: Enter an appropriate DELIVERY TIME

Step 9: Enter the CREDIT required for this service

Step 10: Click the Add button to save this new API test service

Repeat Steps 3-10 to create the additional API test service.

When a reseller connects to your Dhru Fusion GSM server via the StockUnlocks plugin for WordPress, they are now able to import these services into their websites.

When the API test order is delivered to your Dhru Fusion GSM server, you will have to manually reply to the order. You can stop here if you don’t mind manually replying to all API test orders.

However, if you’d like your server to automatically reply to API test orders, then continue on to the next section.

Obtain the API id of the Test Service

Before the auto reply cron job is created, the API id for the test order(s) need to be identified. The API id will be included in the .php script that will be used for the auto reply cron job.

Log into your Dhru Fusion GSM server and follow these steps to find the test service API id:

products services selecting imei serviceStep 1. Click on Products/Services > IMEI Service

Step 2. Identify the title of the desired unlock service by its title under the Service Name column (e.g. API Test – Available or API Test – Unavailable)

dhru fusion gsm api id column for imei serviceStep 3: Note the number next to the Service Name under the ID column. This value will be used later.

This is the API ID that will be used when writing the .php script.

Repeat Steps 1 to 3 above until you have identified all of the unlock services that will be used for testing.

Create an Auto Reply Cron Job

cpanel files main heading to access file managerStep 1: Log into your cPanel account and go to the section with the heading FILES

cpanel file manager selectionStep 2: Click on File Manager

cpanel file manager includes folder selection

Step 3: Navigate to your Dhru Fusion GSM installation directory and select the includes subdirectory (or folder)

cp file manager add new file buttonStep 4: Click on +File at the top to create a file in the includes directory

cpanel file manager new file create dialogType the new file name in the text box. In our example, we’ll call this file: ‘cron_api_test.php’. Of course, you may name it whatever you’d like.

cpanel file manager new file createdVerify that the new file will be created in the  … /includes directory and click the Create New File button.

The web page will refresh and you see the newly created file appear in the directory.

Editing the .php Script File for the Cron Job

NOTE: This tutorial is not intended to be an in-depth explanation of PHP or SQL. In an effort to keep things as simple as possible, very brief explanations will accompany the code found below.

cpanel file manager edit the new fileStep 1: Select the ‘‘cron_api_test.php’ file and click ‘Edit’ at the top

Step 2: Add the following text to the file:

Explaining the .php Script File

date_default_timezone_set

Sets the default timezone used by all date/time functions in the script. Some scripts will behave strangely if the designated timezone is missing.

$servername = "localhost";
$username = "your_mysql_db_username";
$password = "your_mysql_db_password";
$dbname = “your_mysql_db_name”;

Replace these values with those for your web hosting environment.

// Create connection

$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

Create the connection to the mySQL database that holds all of the data for your Dhru Fusion GSM server.

// collect all of the new test api orders:
// user_can_c: new orders = 0, accepted orders = 1, rejected orders = 3, available  orders = 4
// service_id = n1 (available) OR n2 (unavailable)

These comments are a reminder of the possible status settings of the IMEI unlock service.

The user_can_c value will determine the kind of reply that will be sent to the reseller’s unlock order:

0 means a new unlock order. This is the default value given to a newly submitted order to the Dhru Fusion GSM server. It has not yet been processed or replied to.

1 means an unlock order is accepted for processing. This indicates that the details that the reseller submitted with the unlock order contain everything necessary to request a cell phone unlock code.

3 means the unlock order is rejected. The mobile device or cell phone cannot be unlocked.

4 means the unlock order is successful. An unlock code was obtained for the mobile device or cell phone. For the iPhone, it’s now unlocked since unlock codes are not used for the iPhone.

The line containing the service_id is a reference to the API ids for the available/unavailable IMEI test services. The n1 and n2 values will be substituted with the API ids you obtained in the section above: Obtain the API id of the test service.

$sql = "SELECT order_id, service_id, user_can_c, reply, reply_time, reply_by_admin, reply_date FROM tbl_order_imei WHERE user_can_c=0 AND (service_id=1 OR service_id=2)";

$result = mysqli_query($conn, $sql);

These statements collect all of the unlock orders that have user_can_c= 0 (new order) AND service_id=n1 or n2 (available or unavailable). Again, the n1 and n2 values will be substituted with the API ids. These values were obtained in the section above: Obtain the API id of the test service.

if (mysqli_num_rows($result) > 0) {

    // output data of each row
    
    while($row = mysqli_fetch_assoc($result)) {
        // check if service is available (service_id=1) or unavailable (service_id=2) or Test-model (service_id=23)
        
        $order_id = $row["order_id"];
        $service_id = $row["service_id"];
        $user_can_c = $row["user_can_c"];
        $reply = $row["reply"];
        $reply_time = strtotime("now");
        $reply_by_admin = 1;
        $reply_date = strtotime("now");
        
        switch ($service_id) {
            case n1:
                // echo "test api: service available";
                $user_can_c = 4;
                $reply = 'SU API Test - Available';
                break;
            case n2:
                // echo "test api: service unavailable";
                $user_can_c = 3;
                $reply = 'SU API Test - Unavailable';
                break;
            default:
                echo "neither 1 nor 2!";
        }
 
         $sqlUpdate = "UPDATE tbl_order_imei SET user_can_c=" . $user_can_c . " , reply='" . $reply . "', reply_time=" . $reply_time . ", reply_by_admin=" . $reply_by_admin . ", reply_date=" . $reply_date .  " WHERE order_id=" . $order_id;
        if (mysqli_query($conn, $sqlUpdate)) {
            // echo "Record updated successfully";
        } else {
            echo "Error updating record: " . mysqli_error($conn);
        }
 
    }
} else {
    // echo "0 results";
}

While looping through the API test orders, the $reply values are set based on whether it’s an accepted or rejected API test order. If this was an actual unlock order, here is where the unlock code would appear. If the device being unlocked is an iPhone, the $reply message will simply be ‘Unlocked’.

The user_can_c API test table value will be updated with either:

  • 3 = rejected
  • 4 = available.

Step 3: Click the Save Changes button. This saves the .php script for the cron job

Step 4: Click the Close button to close the page and return to the directory

Now that you’ve created the .php script file, it’s time to add the scheduled Cron Job that will reference this file.

Add a New Scheduled Cron Job

cpanel advanced heading to access cron jobs

Step 1: Navigate back to the cPanel Home page and find the section labeled ADVANCED.

cpanel cron jobs selection from advanced sectionStep 2: Click on Cron Jobs to open the page

cpanel cron job common settings selectionStep 3: Select the appropriate schedule for running the cron job under the Common Settings drop-down list in the ‘Add New Cron Job’ section

Be careful when choosing a schedule to run the cron job. If it runs too often, the job can degrade the server performance.

cpanel cron job common settings five minute settingSince this cron job will be replying to API test services submitted by your resellers, a setting like Once Per Five Minutes(*/5****) should be appropriate.

Step 4: Type the PHP command and location of the .php script file in the Command: text field

cpanel common settings adding command line scriptFor example:

php -q /home/yourserverdirectory/public_html/yourdomain.com/includes/cron_api_test.php

cpanel current cron jobs newly addedStep 5: Click the Add New Cron Job button to add the .php script to the schedule with the other cron jobs

In Summary

Having test API services is a nice addition to have for your resellers to help them set up their retail websites to seamlessly connect with your Dhru Fusion GSM server.

1. Resellers can choose to simulate the conditions where an remote unlock order is successful or has failed

2. With each test, resellers can tweak the message in their reply email templates until it’s perfect

3. You can reduce unnecessary traffic on your Dhru Fusion GSM server if you direct your resellers to use the StockUnlocks API testing services

Everything you need to create your own API test service is now all here in one place.

Is there something here that needs further explanation? What other aspects of the Dhru Fusion GSM server would you like to see explained? Contact StockUnlocks directly or leave a comment below!

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.