将PHP代码转换为Objective-C

3

你好,这是一段PHP代码:

$proxy = new SoapClient('http://magentohost/api/soap/?wsdl');
$sessionId = $proxy->login('apiUser', 'apiKey');

$quoteId = $proxy->call( $sessionId, 'cart.create');

$arrProducts = array(
    array(
        “product_id” => “1”,
        “qty” => 2
    );

$resultCartProductAdd = $proxy->call(
    $sessionId,
    “cart_product.add”,
    array(
        $quoteId,
        $arrProducts
    )
);

我需要在我的iOS应用中使用它,因此我正在使用一个库获取sessionIdquoteId。我正在使用的库的工作方式如下: Magento给了我这个api:customer.create,我必须在客户创建中设置sessionId和一个数组,其中我放置客户的详细信息。在objectiveC中,我得到了这段代码:

[Magento call:@[@"customer.create", @{
     @"email": email,
     @"password": password,
     @"firstname": firstname,
     @"lastname": lastname,
     @"website_id": @1,
     @"store_id": Magento.service.storeID
}] success:^(AFHTTPRequestOperation *operation, id responseObject) {
    Magento.service.customerID = responseObject;
    NSLog(@"signUp customerID = %@", Magento.service.customerID);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"error %@", error.localizedDescription);
}];

现在我猜测我的库将一个php数组转换为NSDictionary(参见上面的代码)。我如何使用这个库将php数组中的数组转换为objectiveC格式? 我需要使用cart_product.add magento api。 希望你能明白我的意思并能够帮助我。

1个回答

1
我已解决,这是代码:

Solved by myself, here's the code:

[Magento call:@[@"cart_product.add", Magento.service.cartID,@[@{@"product_id": productID, @"qty": self.qty}]]
                        success:^(AFHTTPRequestOperation *operation, id responseObject) {
                            NSLog(@"Prodotto aggiunto");
                            [Magento call:@[@"cart.info", @{@"quoteId": Magento.service.cartID}]
                                  success:^(AFHTTPRequestOperation *operation, id responseObject) {
                                      [self getListOfProductsInCart:responseObject];
                                  }failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                                      NSLog(@"Errore: %@", error.localizedDescription);
                                  }];

使用这段代码将我问题中的php代码转换为ObjectiveC。希望这对某些人有用。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接