API PHP

Halan Schlickmann's Avatar

Halan Schlickmann

03 Sep, 2013 10:46 PM

When the API in PHP come?

  1. 1 Posted by Diego on 26 Sep, 2013 07:58 AM

    Diego's Avatar

    Hello,i 'D like integrated passbook download in my website... Can you explane me how i Can do it? I'd like insert a buttom or qr code for my client and with this code they can add passbook in their iPhone .

    Thanks

    Diego

  2. 2 Posted by Alejandro on 13 Oct, 2013 12:04 PM

    Alejandro's Avatar

    Here some code to CALL API, but I think that "PUT" (used to update passbooks) is incompleted

    >--
    <?php

    ini_set('display_errors','1');
    error_reporting(E_ALL);
      
    // Method: POST, PUT, GET etc
    // Data: array("param" => "value") ==> index.php?param=value

    function CallAPI($method, $url, $data = false)
    {
        $curl = curl_init();
        
        switch ($method)
        {
            case "POST":
                curl_setopt($curl, CURLOPT_POST, 1);

                if ($data)
                    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
                break;
            case "PUT":
                curl_setopt($curl, CURLOPT_PUT, 1);
                break;
            default:
                if ($data)
                    $url = sprintf("%s?%s", $url, http_build_query($data));
        }

    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

    $respuesta = curl_exec($curl);

    if ($respuesta === false) {
        $info = curl_getinfo($curl);
    echo curl_error($curl);
         echo '<h1>Se ha producido un error durante el exec</h1>';
        echo indent(json_encode($info));
    }

    curl_close($curl);
       
        return $respuesta;
    }

    /**
     * Indents a flat JSON string to make it more human-readable.
     *
     * @param string $json The original JSON string to process.
     *
     * @return string Indented version of the original JSON string.
     */
    function indent($json) {

        $result = '';
        $pos = 0;
        $strLen = strlen($json);
        $indentStr = ' &nbsp;&nbsp;&nbsp;&nbsp;';
        $newLine = "<br>\n";
        $prevChar = '';
        $outOfQuotes = true;

        for ($i=0; $i<=$strLen; $i++) {

            // Grab the next character in the string.
            $char = substr($json, $i, 1);

            // Are we inside a quoted string?
            if ($char == '"' && $prevChar != '\\') {
                $outOfQuotes = !$outOfQuotes;

            // If this character is the end of an element,
            // output a new line and indent the next line.
            } else if(($char == '}' || $char == ']') && $outOfQuotes) {
                $result .= $newLine;
                $pos --;
                for ($j=0; $j<$pos; $j++) {
                    $result .= $indentStr;
                }
            }

            // Add the character to the result string.
            $result .= $char;

            // If the last character was the beginning of an element,
            // output a new line and indent the next line.
            if (($char == ',' || $char == '{' || $char == '[') && $outOfQuotes) {
                $result .= $newLine;
                if ($char == '{' || $char == '[') {
                    $pos ++;
                }

                for ($j = 0; $j < $pos; $j++) {
                    $result .= $indentStr;
                }
            }

            $prevChar = $char;
        }

        return $result;
    }

    ?>
    >--

  3. 3 Posted by chackAburi on 25 Dec, 2019 11:08 PM

    chackAburi's Avatar

    Second citizenship and residency by investment! Short terms, official programs, full service. Grenada, Malta, Portugal, Vanuatu, USA etc.
    Just go to right-invest.com!

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

24 Jan, 2020 11:41 AM
18 Jan, 2020 07:30 AM
08 Jan, 2020 10:48 PM
08 Jan, 2020 02:08 AM
25 Dec, 2019 11:08 PM