久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 Magento 中創建一個新客戶(RESTful,PHP)

Creating a new customer in Magento(RESTful,PHP)(在 Magento 中創建一個新客戶(RESTful,PHP))
本文介紹了在 Magento 中創建一個新客戶(RESTful,PHP)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試在 Magento 中創建一個新客戶.這是我為此編寫的 PHP 腳本

I am trying to create a new customer in Magento. Here's PHP script I wrote for that

<?php
$callbackUrl = "http://localhost/magento/webservices/NewCustomer1.php";
$temporaryCredentialsRequestUrl = "http://localhost/magento/oauth/initiate?oauth_callback=". urlencode($callbackUrl);
$adminAuthorizationUrl = 'http://localhost/magento/admin/oauth_authorize';
$accessTokenRequestUrl = 'http://localhost/magento/oauth/token';
$apiUrl = 'http://localhost/magento/api/rest';
$consumerKey = 's3xt7w8lwhfrrfzrfvwm3lrilkf66d5n';
$consumerSecret = 'vr3eq1x899pz1cf4zzxjzx3q03t66r3n';


session_start();
if (!isset($_GET['oauth_token']) && isset($_SESSION['state']) && $_SESSION['state'] == 1) {
    $_SESSION['state'] = 0;
}
try {
    $authType = ($_SESSION['state'] == 2) ? OAUTH_AUTH_TYPE_AUTHORIZATION : OAUTH_AUTH_TYPE_URI;
    $oauthClient = new OAuth($consumerKey, $consumerSecret, OAUTH_SIG_METHOD_HMACSHA1, $authType);
    $oauthClient->enableDebug();

    if (!isset($_GET['oauth_token']) && !$_SESSION['state']) {
        $requestToken = $oauthClient->getRequestToken($temporaryCredentialsRequestUrl);
        $_SESSION['secret'] = $requestToken['oauth_token_secret'];
        $_SESSION['state'] = 1;
        header('Location: ' . $adminAuthorizationUrl . '?oauth_token=' . $requestToken['oauth_token']);
        exit;
    } else if ($_SESSION['state'] == 1) {
        $oauthClient->setToken($_GET['oauth_token'], $_SESSION['secret']);
        $accessToken = $oauthClient->getAccessToken($accessTokenRequestUrl);
        $_SESSION['state'] = 2;
        $_SESSION['token'] = $accessToken['oauth_token'];
        $_SESSION['secret'] = $accessToken['oauth_token_secret'];
        header('Location: ' . $callbackUrl);
        exit;
    } else {
        $oauthClient->setToken($_SESSION['token'], $_SESSION['secret']);
        $resourceUrl = "$apiUrl/customers/create";
        $customerData = json_encode(array(
            'firstname'           => 'demofirstname',
            'lastname'            => 'demolastname',
            'email_address'       => 'demo@gmail.com',
            'password'            => 'demo1234',
            'confirmation'        => 'demo1234',

        ));
        $headers = array('Content-Type' => 'application/json');
        $oauthClient->fetch($resourceUrl, $customerData, OAUTH_HTTP_METHOD_POST, $headers);
        print_r($oauthClient->getLastResponseInfo());
    }
} catch (OAuthException $e) {
    print_r($e);
}
?>

我收到此錯誤

OAuthException:無效的身份驗證/錯誤請求(得到 405,預期為 HTTP/1.120X 或重定向)在 C:wampwwwmagentoWebServices ewcustomer1.php在第 47 行調用堆棧 #TimeMemoryFunctionLocation 10.0010386016{main}(.. ewcustomer1.php:0 20.0017391216OAuth->fetch().. ewcustomer1.php:47 )

OAuthException: Invalid auth/bad request (got a 405, expected HTTP/1.1 20X or a redirect) in C:wampwwwmagentoWebServices ewcustomer1.php on line 47 Call Stack #TimeMemoryFunctionLocation 10.0010386016{main}( ).. ewcustomer1.php:0 20.0017391216OAuth->fetch( ).. ewcustomer1.php:47 )

我是 Oauth 和 PHP 的新手.如果有人可以提供幫助,我會很高興.

I am new to Oauth and PHP. Will be glad if someone can help.

推薦答案

這個自定義 API 我寫的作品就像輕而易舉.您需要從 Magento 管理面板創建一個 SOAP 用戶并添加 SOAP 用戶 &以下代碼中的數據庫憑據以使其工作.

This custom API I wrote works like a breeze. You will need to create a SOAP user from Magento Admin Panel and add SOAP user & DB credentials in following code to make it work.

require_once('../app/Mage.php' );
    $dbhost = 'localhost';
    $dbUsername = 'root';
    $dbPassword = 'password';
    $dbName = 'magento';
    $soapUsername = 'soapuser';
    $soapPassword = 'password'; 
    Mage::app("default");
    $store = Mage::app()->getStore();
    $storeId = $store->getId();
    $websiteId = Mage::app()->getStore()->getWebsiteId();
    $email = $_POST['email'];
    $firstname = $_POST['firstname'];
    $lastname = $_POST['lastname'];
    $password = $_POST['password'];
    $proxy = new SoapClient('http://yourdomain/magento/index.php/api/?wsdl'); // TODO : change url
    $session = $proxy->login($soapUsername, $soapPassword);
    try{
    $result = $proxy->call($session,'customer.create',array(array('email' => "$email", 'firstname' => "$firstname", 'lastname' => "$lastname", 'password' => "$password", 'website_id' => "$websiteId", 'store_id' => "$storeId", 'group_id' => 1)));
    echo json_encode("New Customer created with Id-$result");
    $custId = $result;
    $shoppingCartId = $proxy->call($session, 'cart.create', array(1));
    $customer = array(
        'firstname' => "$firstname",
        'lastname' => "$lastname",
        'email' => "$email",
        'password' => md5("$password"),
        'customer_id' => "$custId",
        'mode' => 'customer',
        'website_id' => "$websiteId", 
        'store_id' => "$storeId",
        'group_id' => 1
    );
    $resultCustomerSet = $proxy->call($session, 'cart_customer.set', array( $shoppingCartId, $customer, $storeId) );
    $db_handle = mysql_connect($dbhost, $dbUsername, $dbPassword) or die(mysql_error());
    $db_found = mysql_select_db($dbName, $db_handle);
    mysql_query("UPDATE `sales_flat_quote` SET `is_active` = '1' WHERE `customer_email` = '$email' ");
    mysql_query("INSERT INTO `wishlist` VALUES('','$custId','0','','$timestamp')");
    }
    catch( Exception $e ) {
     echo json_encode($e->getMessage());
     }

這篇關于在 Magento 中創建一個新客戶(RESTful,PHP)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數組自動填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 久久久久成人精品免费播放动漫 | 国产黄色精品在线观看 | 国产精品视频偷伦精品视频 | 亚洲 欧美 在线 一区 | 欧美日韩一区二区三区四区 | www.jizzjizz| 国产区在线免费观看 | 日韩av在线中文字幕 | 国产欧美在线播放 | 国产精品永久免费 | 美女视频一区二区三区 | 久久久久久国产精品久久 | 在线精品观看 | 中文字幕一区二区三区四区五区 | 国产免费av在线 | 亚洲免费三级 | 99视频免费播放 | 免费h在线 | 久久久视频在线 | 日韩欧美一区二区三区免费观看 | 在线一级片 | 成人在线电影在线观看 | 高清国产一区二区 | 九九热在线免费视频 | 成人性视频免费网站 | 日p视频免费看 | 欧美成年黄网站色视频 | 欧美日韩中文字幕在线 | 日韩 欧美 综合 | 久久一级大片 | 久久激情视频 | 国产高清精品一区二区三区 | 北条麻妃一区二区三区在线观看 | 在线免费观看成年人视频 | 国产激情毛片 | 一级在线视频 | 人人操日日干 | 久久亚洲一区 | 成人av高清在线观看 | 草草视频在线播放 | 黄色成人在线观看 |