Exemplo n.º 1
0
define("BIZWEB_API_KEY", "797c456c504bcf1c9a42964851e55d80");
// EGANY on Bizweb
define("BIZWEB_SECRET", "419313b6c64bf212597c0a64573d56eb");
define("REDIRECT_URI", "http://localhost/bizweb_app_phong");
define("BIZWEB_SCOPE", "read_products,write_products");
session_start();
if (isset($_GET['code'])) {
    // if the code param has been sent to this page... we are in Step 2
    // Step 2: do a form POST to get the access token
    $shopifyClient = new BizwebClient($_GET['store'], "", BIZWEB_API_KEY, BIZWEB_SECRET);
    session_unset();
    // if(!$shopifyClient->validateSignature($_GET)) die('Error: invalid signature.');
    // var_dump($_GET);
    // die( "signature: " . $_GET['signature']);
    // Now, request the token and store it in your session.
    $token = $shopifyClient->getAccessToken($_GET['code'], REDIRECT_URI);
    $_SESSION['token'] = $token;
    if ($_SESSION['token'] != '') {
        $_SESSION['shop'] = $_GET['shop'];
    }
    echo $token;
    header("Location: shop.php");
    exit;
} else {
    if (isset($_POST['shop']) || isset($_GET['shop'])) {
        // Step 1: get the shopname from the user and redirect the user to the
        // shopify authorization page where they can choose to authorize this app
        $shop = isset($_POST['shop']) ? $_POST['shop'] : $_GET['shop'];
        $shopifyClient = new BizwebClient($shop, "", BIZWEB_API_KEY, BIZWEB_SECRET);
        // if(!$shopifyClient->validateSignature($_GET)) die('Error: invalid signature.');
        // redirect to authorize url