Woocommerce 使用 api 使用希伯来语文本创建订单返回错误 [英] Woocommerce create order with hebrew text using the api retuns an error

查看:21
本文介绍了Woocommerce 使用 api 使用希伯来语文本创建订单返回错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using woocommerce Version 2.3.10 (i cant upgrade to the new version) I am using API V2 I am creating an order using the API successfully The entire order text is in english once there is Hebrew in one of the fields (billing addres first name for example), I am getting an error when trying to create the order.

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

The error i am getting is: woocommerce_api_missing_callback_param Any ideas how to fix it? i tried to encode the text to unicode string but the string is not being decoded back to hebrew when the order is created. There is no problem to open an order with hebrew in the regular website (not using the api

更新:
我安装了最新版本的woocommerce,问题依旧

UPDATE:
I installed latest version of woocommerce and the problem remains the same

推荐答案

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

I have successfully created an order using API v2, used a Hebrew word for the first_name field and it worked. I am pasting the code here so that you can check yours against it.

  $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                   
                )               
            ),


   ));

在后端,订单显示良好

In the backend the order shows fine

EDIT :根据 OP 的要求添加请求标头和正文

EDIT : Adding the request headers and body as requested by 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}]}}

EDIT 2:添加特定于 C# 的代码段

EDIT 2 : Adding C# specific piece of code

    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;

这篇关于Woocommerce 使用 api 使用希伯来语文本创建订单返回错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆