Wordpress Woocommerce使用api使用希伯来语文本创建订单返回错误
我正在使用woocommerce版本2.3.10(我无法升级到新版本) 我使用的是API V2 我正在使用API成功创建订单 整个订单文本为英文 一旦其中一个字段(例如billing addres first name)中出现希伯来语,我在尝试创建订单时就会出错 我得到的错误是:woocommerce\u api\u missing\u callback\u param 有没有办法解决这个问题? 我试图将文本编码为unicode字符串,但在创建订单时,字符串没有被解码回希伯来语。 在常规网站(不使用api)上用希伯来语打开订单没有问题 更新:Wordpress Woocommerce使用api使用希伯来语文本创建订单返回错误,wordpress,woocommerce,Wordpress,Woocommerce,我正在使用woocommerce版本2.3.10(我无法升级到新版本) 我使用的是API V2 我正在使用API成功创建订单 整个订单文本为英文 一旦其中一个字段(例如billing addres first name)中出现希伯来语,我在尝试创建订单时就会出错 我得到的错误是:woocommerce\u api\u missing\u callback\u param 有没有办法解决这个问题? 我试图将文本编码为unicode字符串,但在创建订单时,字符串没有被解码回希伯来语。 在常规网站(不
我安装了最新版本的woocommerce,问题仍然是一样的我已经成功地使用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
)
),
));
在后端,顺序显示良好
编辑:根据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;
解决方案:
通过向WebClient添加编码解决了此问题。
它在没有编码的情况下用英语工作,但一旦我使用希伯来语文本,我就从WooCommerceAPI中得到了错误
WebClient wc = new WebClient();
wc.Headers[HttpRequestHeader.ContentType] = "application/json";
wc.Encoding = Encoding.UTF8;
向我们展示一些您尝试过的代码。同时尝试使用最新的WooCommerce创建一个新的WordPress安装,并对其运行代码,以查看它是否有效,是否知道问题所在。如果您确信您正确执行了此操作(意味着所有内容都可以在另一种语言中运行)然后,您可能想在.ana上打开一个问题,我在最新版本上尝试了它,结果是相同的error@uriz,你能给我们看一些你试过的代码吗?@Uris,我刚刚用API创建了一个测试顺序,它可以工作,我设置first_name=您可以捕获原始请求吗?您只需要标题还是正文?您可以放置整个请求(标题和正文)因此,我可以看出问题出在哪里?@Uris,已将原始请求头和正文添加到应答器编码希伯来语字符串或按原样发送,请确保将WebClient对象上的编码设置为UTF-8。我已添加了代码。