国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

Magento Api 記錄

2019-11-15 01:30:14
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
Magento Api 記錄

magento api 首次接觸 (-)

  1 /**  2 * magento Api 身份驗(yàn)證 調(diào)用示例  3 * Example of simple PRoduct POST using Admin account via Magento REST API. OAuth authorization is used  4 */  5 $callbackUrl = "http://127.0.0.1/oauth_admin.php";// 回調(diào)頁(yè)面   7 $temporaryCredentialsRequestUrl = "http://www.magento.com/oauth/initiate?oauth_callback=" . urlencode($callbackUrl); //請(qǐng)求Url 獲取臨時(shí)憑證  8 $adminAuthorizationUrl = 'http://www.magento.com/admin/oauth_authorize'; //請(qǐng)求授權(quán)  9 $accessTokenRequestUrl = 'http://www.magento.com/oauth/token'; //獲取令牌 10 $apiUrl = 'http://www.magento.com/api/rest'; // magento 接口訪問(wèn)所有URL 都基于 此URL 11 $consumerKey = 'xfn5po1semt9iy680wdpcfuue06p058y'; 12 $consumerSecret = 'eq1x5n9w0ppwq4o3imf8b4xls81fh77d'; 13 session_start(); 14 if (!isset($_GET['oauth_token']) && isset($_SESSION['state']) && $_SESSION['state'] == 1) { 15     $_SESSION['state'] = 0; 16 } 17 try { 18     $authType = (@$_SESSION['state'] == 2) ? @OAUTH_AUTH_TYPE_AUTHORIZATION : @OAUTH_AUTH_TYPE_URI; 19     $oauthClient = new OAuth($consumerKey, $consumerSecret, OAUTH_SIG_METHOD_HMACSHA1, $authType); 20     $oauthClient->enableDebug(); 21  22     if (!isset($_GET['oauth_token']) && !@$_SESSION['state']) { 23         $requestToken = $oauthClient->getRequestToken($temporaryCredentialsRequestUrl); 24         $_SESSION['secret'] = $requestToken['oauth_token_secret']; 25         $_SESSION['state'] = 1; 26         //print_r($_SESSION);exit; 27         header('Location: ' . $adminAuthorizationUrl . '?oauth_token=' . $requestToken['oauth_token']); 28         exit; 29     } else if (@$_SESSION['state'] == 1) { 30         $oauthClient->setToken($_GET['oauth_token'], $_SESSION['secret']); 31         $accessToken = $oauthClient->getAccessToken($accessTokenRequestUrl); 32         if(empty($accessToken)) { 33             exit("Failed fetching access token, response was: " . $oauthClient->getLastResponse()); 34         } 35         $_SESSION['state'] = 2; 36         $_SESSION['token'] = $accessToken['oauth_token']; 37         $_SESSION['secret'] = $accessToken['oauth_token_secret']; 38         header('Location: ' . $callbackUrl); 39         exit; 40     } else { 41  42         /***************************修改數(shù)據(jù):************************/ 43         /*$oauthClient->setToken($_SESSION['token'], $_SESSION['secret']); 44         $resourceUrl = "$apiUrl/products/1"; 45         $productData = json_encode(array( 46             'type_id'           => 'simple', 47             'attribute_set_id'  => 4, 48             'sku'               => 'chujiu123' . uniqid(), 49             'weight'            => 1, 50             'status'            => 1, 51             'visibility'        => 4, 52             'name'              => 'chujiu update demo6 28', 53             'descrapplication/json'); 59         $oauthClient->fetch($resourceUrl, $productData, OAUTH_HTTP_METHOD_PUT, $headers); 60         print_r($oauthClient->getLastResponseInfo());*/ 61  62  63         /***************************添加數(shù)據(jù):************************/ 64  65         /*$oauthClient->setToken($_SESSION['token'], $_SESSION['secret']); 66         $resourceUrl = "$apiUrl/products"; 67         $productData = json_encode(array( 68             'type_id'           => 'simple', 69             'attribute_set_id'  => 4, 70             'sku'               => 'chujiu123_cate3' . uniqid(), 71             'weight'            => 1, 72             'weight'            => 1, 73             'status'            => 1, 74             'visibility'        => 4, 75             'categories'      => '2,3', 76             'name'              => 'chujiu cate3 update demo2', 77             'description'       => 'chujiu cate3 Description', 78             'short_description' => 'chujiu cate3 Short Description', 79             'price'             => 59.95, 80             'tax_class_id'      => 0, 81         )); 82         $headers = array('Content-Type' => 'application/json'); 83         $oauthClient->fetch($resourceUrl, $productData, OAUTH_HTTP_METHOD_POST, $headers); 84         print_r($oauthClient->getLastResponseInfo());*/ 85  86  87         /***************************分配產(chǎn)品到指定分類(lèi)中************************/ 88  89         /*$oauthClient->setToken($_SESSION['token'], $_SESSION['secret']); 90         $resourceUrl = "$apiUrl/products/9/categories";  //9  是產(chǎn)品的ID 91         $productData = json_encode(array( 92             'category_id'      => 2, 93         )); 94         $headers = array('Content-Type' => 'application/json'); 95         $oauthClient->fetch($resourceUrl, $productData, OAUTH_HTTP_METHOD_POST, $headers); 96         print_r($oauthClient->getLastResponseInfo());*/ 97  98  99         /***************************查詢(xún): 獲取數(shù)據(jù):************************/100 101         $oauthClient->setToken(@$_SESSION['token'], @$_SESSION['secret']);102         $resourceUrl = "$apiUrl/products";  //如果獲取單個(gè)商品的信息 $apiUrl/products/1  代表訪問(wèn) ID 為1103         $oauthClient->fetch($resourceUrl);104         $productsList = json_decode($oauthClient->getLastResponse(), true);105         echo '<pre>';106         print_r($productsList);107         $k = array_keys($productsList[1]);108         $keys = join(',', $k);109         echo $keys; // 添加商品的字段110 111         /***************************刪除數(shù)據(jù):************************/112 113         /*$oauthClient->setToken(@$_SESSION['token'], @$_SESSION['secret']);114         $resourceUrl = "$apiUrl/products/4";115         $oauthClient->fetch($resourceUrl, OAUTH_HTTP_METHOD_DELETE);116         echo '<pre>';117         print_r($oauthClient->getLastResponseInfo());*/118     }119 } catch (OAuthException $e) {120     echo '<pre>';121     print_r($e);122 }


發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 宁国市| 万盛区| 财经| 土默特左旗| 敦煌市| 明星| 平遥县| 石阡县| 阜新市| 若尔盖县| 道真| 龙陵县| 新昌县| 尚义县| 伊金霍洛旗| 洮南市| 彰化市| 眉山市| 阳高县| 同仁县| 汤阴县| 晋城| 正蓝旗| 沂源县| 晋宁县| 黄平县| 宜兰县| 内丘县| 泽普县| 隆德县| 巧家县| 仪征市| 张北县| 乌鲁木齐县| 邻水| 静乐县| 池州市| 延安市| 旬邑县| 玉门市| 东乡|