Skip to content

Instantly share code, notes, and snippets.

@miniplay
miniplay / mpS2SItemValidationHandlingSample.php
Last active August 29, 2015 14:00
Sample on how to pre-validate item purchases with our Server 2 Server notifications.
<?php
/* ---- PLEASE MAKE SURE YOUR ENCODING IS: UTF-8 (without BOM) ---- */
$jsonString = file_get_contents("php://input"); /* Get the RAW POST DATA */
/* Validate signature */
if ( ! ( isset($_SERVER['HTTP_MINI_SIGNATURE'])
&& $_SERVER['HTTP_MINI_SIGNATURE'] == md5("[YOUR_API_KEY]".$jsonString) )) {
throw new Exception("Invalid signature");
}
/* Decode the JSON string received and convert it to an associative array */
@miniplay
miniplay / mpS2SCallbackHandlingSample.php
Last active December 19, 2015 05:59
Sample on how to validate signature and handle our Server 2 Server notifications for item purchases, game likes, dislikes...
<?php
/* ---- PLEASE MAKE SURE YOUR ENCODING IS: UTF-8 (without BOM) ---- */
$jsonString = file_get_contents("php://input"); /* Get the RAW POST DATA */
/* Validate signature */
if ( ! ( isset($_SERVER['HTTP_MINI_SIGNATURE'])
&& $_SERVER['HTTP_MINI_SIGNATURE'] == md5("[YOUR_API_KEY]".$jsonString) )) {
throw new Exception("Invalid signature");
}
/* Decode the JSON string received and convert it to an associative array */
@miniplay
miniplay / mpJavascriptExternalDemo.php
Last active December 15, 2015 20:19
API loading for external games. Miniplay Connect DEMO.
<?php
/* NOTICE: For miniplay connect to work, your domain must be allowed by us, contact us to request access */
/* 1. Parameters decoding ============================================================================================ */
/* Only if your system configuration or language doesn't automatically decodes it */
foreach ($_GET as $key => $value) $_GET[$key] = urldecode($value);
/* 2. Parameters validation (mp_*) =================================================================================== */
/* External games doesn't receive neither parameters or signature, no validation needed */
@miniplay
miniplay / mpFlashAPILoad_extended.as
Last active February 3, 2017 11:04
Miniplay API - Loading of the AS3 API into a flash game (EXTENDED). Additional content provided, refer to the BASE for the simplest version.
/* 1. Imports */
import flash.display.LoaderInfo;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.system.Security;
/* 2. Get the url from the flashvars */
var params:Object = LoaderInfo(root.loaderInfo).parameters; /* Access to the root object is required */
@miniplay
miniplay / mpFlashAPILoad_base.as
Last active February 3, 2017 11:04
Miniplay API - Loading of the AS3 API into a flash game (BASE)
/* 1. Imports */
import flash.display.LoaderInfo;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.system.Security;
/* 2. Get the url from the flashvars */
var params:Object = LoaderInfo(root.loaderInfo).parameters; /* Access to the root object is required */
@miniplay
miniplay / typeahead-sample.js
Last active December 14, 2015 01:09
Example of custom templates and suggestion properties for https://github.com/twitter/typeahead.js
function MiniTemplateEngine() {
this.compile = function(templateContents) {
var parentTemplate = '<li class="tt-suggestion">%body</li>';
switch(templateContents) {
case parentTemplate.replace("%body", "test"):
return new MiniTemplateSample();
break;
default:
return new MiniTemplateSample();
break;
@miniplay
miniplay / mpSandboxDemo_JS.php
Last active April 28, 2022 20:02
Miniplay API - Basic usage of the Javascript API to handle the current logged user (Miniplay connect functionality is automatically used for external games that have permissions).
<?php
/* 1. Game api_key =================================================================================================== */
if (!empty($_GET['mp_game_devel']) && !!$_GET['mp_game_devel']) {
define("API_KEY","## YOUR_SECURE_DEVELOPMENT_API_KEY ##"); /* Set this to the development api_key we've provided you. DO NOT DISPLAY IT!!! */
} else {
define("API_KEY","## YOUR_SECURE_PRODUCTION_API_KEY ##"); /* Set this to the production api_key we've provided you. DO NOT DISPLAY IT!!! */
}
/* 2. Parameters decoding ============================================================================================ */
// Only if your system configuration or language doesn't automatically decodes it
@miniplay
miniplay / mpSandboxTemplate_ JS.php
Last active December 14, 2015 00:09
Miniplay API - A template sandbox for non-hosted games. Javascript API is automatically loaded if detected. Parameters signature is automatically validated.
<?php
/* 1. Game api_key =================================================================================================== */
if (!empty($_GET['mp_game_devel']) && !!$_GET['mp_game_devel']) {
define("API_KEY","## YOUR_SECURE_DEVELOPMENT_API_KEY ##"); /* Set this to the development api_key we've provided you. DO NOT DISPLAY IT!!! */
} else {
define("API_KEY","## YOUR_SECURE_PRODUCTION_API_KEY ##"); /* Set this to the production api_key we've provided you. DO NOT DISPLAY IT!!! */
}
/* 2. Parameters decoding ============================================================================================ */
// Only if your system configuration or language doesn't automatically decodes it
@miniplay
miniplay / mpSandboxTemplate_FLASH.php
Last active December 14, 2015 00:09
Miniplay API - A template sandbox for non-hosted Flash Games. Javascript API is automatically loaded if detected. Parameters signature is automatically validated.
<?php
/* 1. Game api_key ================================================================================================== */
define("API_KEY","## YOUR_SECURE_API_KEY ##"); /* Set this to the api_key we've provided you. DO NOT DISPLAY IT!! */
/* 2. Flash game configuration ====================================================================================== */
define("FLASH_GAME_URL","http://your.host/your_flash_game.swf"); /* Set this to your swf file */
define("FLASH_GAME_WIDTH","100%");
define("FLASH_GAME_HEIGHT","100%");
define("FLASH_GAME_SWFVERSION","10.0"); /* For version detection, set to min. required Flash Player version, or 0 (or 0.0.0), for no version detection. */
define("FLASH_GAME_PLAYERINSTALL","http://api.minijuegos.com/lechuck/static/as3/swfobject/playerProductInstall.swf"); /* To use express install, set to playerProductInstall.swf, otherwise the empty string. */
@miniplay
miniplay / mpParametersValidationSnippet.php
Last active December 13, 2015 20:48
Miniplay API: Parameters validation snippet (PHP)
<?php
/* 1. Decode all get parameters */
// Only if your system configuration or language doesn't automatically decodes it
// foreach ($_GET as $key => $value) $_GET[$key] = urldecode($value);
/* 2. Check signature */
if ($_GET['mini_signature'] != signParameters("YOUR_API_KEY",$_GET)) {
die("The 'mp_*' parameters signature is invalid");
} else {
echo "The 'mp_*' parameters signature is valid!";
}