Woocommerce使用api重新编写错误,使用希伯来语文本创建订单

时间:2015-09-18 11:19:41

标签: wordpress-plugin woocommerce

我正在使用woocommerce版本2.3.10(我无法升级到新版本) 我正在使用API​​ V2 我正在使用API​​成功创建订单 整个订单文本是英文的 一旦在其中一个字段中有希伯来语(例如,账单地址名字),我在尝试创建订单时收到错误。

我得到的错误是:woocommerce_api_missing_callback_param 任何想法如何解决它? 我试图将文本编码为unicode字符串,但在创建订单时字符串未被解码回希伯来语。 在常规网站上使用希伯来语打开订单没有问题(不使用api

更新:
我安装了最新版的woocommerce,问题仍然存在

2 个答案:

答案 0 :(得分:2)

我已经使用API​​ v2成功创建了一个订单,在first_name字段中使用了一个希伯来语单词并且它有效。我在这里粘贴代码,以便您可以检查它。

  $p = $client->orders->create( 
        array (
            'payment_details' => array( 
                "method_id" => "bacs",
                "method_title" => "Direct Bank Transfer",
                "paid" => true
            ),

            'billing_address' => array( 
                "first_name" => "אֱלֹהִ֑ים",
                "last_name" => "Almighty",
                "address_1" => "969 Market",
                "address_2" => "",
                "city" => "San Francisco",
                "state" => "CA",
                "postcode" => "94103",
                "country" => "US",
                "email" => "john.doe@example.com",
                "phone" => "(555) 555-5555" 
            ),

            'shipping_address' => array( 
                "first_name" => "אֱלֹהִ֑ים",
                "last_name" => "Almighty",
                "address_1" => "969 Market",
                "address_2" => "",
                "city" => "San Francisco",
                "state" => "CA",
                "postcode" => "94103",
                "country" => "US"
            ),

            'line_items' => array(
                array( 
                    'product_id' => 579,
                    'quantity' => 2                     
                )               
            ),

            'shippling_lines' => array(
                array(
                    'method_id' => 'flat_rate',
                    'method_title' => 'Flat Rate',
                    'total' => 10                   
                )               
            ),


   ));

在后端,订单显示正常enter image description here

编辑:按照OP的要求添加请求标题和正文

Array
(
    [SERVER_SOFTWARE] => Apache/2.4.16 (FreeBSD) PHP/5.6.13 Phusion_Passenger/4.0.59
    [REQUEST_URI] => /wc-api/v2/orders?oauth_consumer_key=ck_640ffa61657f3db1653c10cbc137d4f1ab136a46&oauth_timestamp=1442922853&oauth_nonce=c60ad782ba9f0ee5c2e3e4af980ee21d01980153&oauth_s
ignature_method=HMAC-SHA256&oauth_signature=zv0spywKNaXEbwyEASC3o%2FDexf71jf7CJbF9tEI%2FbCU%3D
    [HOME] => /nonexistent
    [USER] => www
    [FCGI_ROLE] => RESPONDER
    [REDIRECT_STATUS] => 200
    [proxy-nokeepalive] => 1
    [HTTP_HOST] => wordpress
    [HTTP_ACCEPT] => application/json
    [CONTENT_TYPE] => application/json
    [HTTP_USER_AGENT] => WooCommerce API Client-PHP/2.0.1
    [CONTENT_LENGTH] => 734
    [PATH] => /sbin:/bin:/usr/sbin:/usr/bin
    [LD_LIBRARY_PATH] => /usr/local/lib
    [SERVER_SIGNATURE] =>
    [SERVER_NAME] => wordpress
    [SERVER_ADDR] => 192.168.1.11
    [SERVER_PORT] => 80
    [REMOTE_ADDR] => 192.168.1.11
    [DOCUMENT_ROOT] => /usr/home/anand/wordpress/
    [REQUEST_SCHEME] => http
    [CONTEXT_PREFIX] =>
    [CONTEXT_DOCUMENT_ROOT] => /usr/home/anand/wordpress/
    [SERVER_ADMIN] => you@example.com
    [SCRIPT_FILENAME] => /usr/home/anand/wordpress/index.php
    [REMOTE_PORT] => 13999
    [REDIRECT_QUERY_STRING] => oauth_consumer_key=ck_640ffa61657f3db1653c10cbc137d4f1ab136a46&oauth_timestamp=1442922853&oauth_nonce=c60ad782ba9f0ee5c2e3e4af980ee21d01980153&oauth_signature
_method=HMAC-SHA256&oauth_signature=zv0spywKNaXEbwyEASC3o%2FDexf71jf7CJbF9tEI%2FbCU%3D
    [REDIRECT_URL] => /wc-api/v2/orders
    [GATEWAY_INTERFACE] => CGI/1.1
    [SERVER_PROTOCOL] => HTTP/1.1
    [REQUEST_METHOD] => POST
    [QUERY_STRING] => oauth_consumer_key=ck_640ffa61657f3db1653c10cbc137d4f1ab136a46&oauth_timestamp=1442922853&oauth_nonce=c60ad782ba9f0ee5c2e3e4af980ee21d01980153&oauth_signature_method=H
MAC-SHA256&oauth_signature=zv0spywKNaXEbwyEASC3o%2FDexf71jf7CJbF9tEI%2FbCU%3D
    [SCRIPT_NAME] => /index.php
    [PHP_SELF] => /index.php
    [REQUEST_TIME_FLOAT] => 1442922853.0845
    [REQUEST_TIME] => 1442922853
)


{"order":{"payment_details":{"method_id":"bacs","method_title":"Direct Bank Transfer","paid":true},"billing_address":{"first_name":"\u05d0\u05b1\u05dc\u05b9\u05d4\u05b4\u0591\u05d9\u05dd","
last_name":"Almighty","address_1":"969 Market","address_2":"","city":"San Francisco","state":"CA","postcode":"94103","country":"US","email":"john.doe@example.com","phone":"(555) 555-5555"},
"shipping_address":{"first_name":"\u05d0\u05b1\u05dc\u05b9\u05d4\u05b4\u0591\u05d9\u05dd","last_name":"Almighty","address_1":"969 Market","address_2":"","city":"San Francisco","state":"CA",
"postcode":"94103","country":"US"},"line_items":[{"product_id":579,"quantity":2}],"shippling_lines":[{"method_id":"flat_rate","method_title":"Flat Rate","total":10}]}}

编辑2 :添加C#特定代码

    wc.Headers[HttpRequestHeader.ContentType] = "application/json";
    wc.Encoding = Encoding.UTF8;

    // Send the string as is
    string coupon = "{ \"coupon\": { \"code\": \"new-coupon\", \"type\": \"percent\", \"amount\": \"10\", \"individual_use\": true, \"product_ids\": [], \"exclude_product_ids\": [], \"usage_limit\": \"\", \"usage_limit_per_user\": \"\", \"limit_usage_to_x_items\": \"\", \"expiry_date\": \"\", \"enable_free_shipping\": false, \"product_category_ids\": [], \"exclude_product_category_ids\": [], \"exclude_sale_items\": true, \"minimum_amount\": \"100.00\", \"maximum_amount\": \"0.00\", \"customer_emails\": [], \"description\": \"אֱלֹהִ֑ים\" } }";
    var result = wc.UploadString(url, coupon);

    // Encode the string 
    string coupon = "{ \"coupon\": { \"code\": \"new-coupon1\", \"type\": \"percent\", \"amount\": \"10\", \"individual_use\": true, \"product_ids\": [], \"exclude_product_ids\": [], \"usage_limit\": \"\", \"usage_limit_per_user\": \"\", \"limit_usage_to_x_items\": \"\", \"expiry_date\": \"\", \"enable_free_shipping\": false, \"product_category_ids\": [], \"exclude_product_category_ids\": [], \"exclude_sale_items\": true, \"minimum_amount\": \"100.00\", \"maximum_amount\": \"0.00\", \"customer_emails\": [], \"description\": \"\\u05d0\\u05b1\\u05dc\\u05b9\\u05d4\\u05b4\\u0591\\u05d9\\u05dd\" } }";
    var result = wc.UploadString(url, coupon);
    return result;

答案 1 :(得分:0)

<强>解决方案:
通过向WebClient添加编码解决了这个问题 它在没有编码的情况下使用英语,但是一旦我使用了希伯来语文本,我就会从woocommerce API中获得错误。

WebClient wc = new WebClient();
wc.Headers[HttpRequestHeader.ContentType] = "application/json";
wc.Encoding = Encoding.UTF8;