我已经集成了Wepay payment gateway。但是我面临着一个通过json object to wepay的问题。它总是显示错误的json格式。请看下面的代码。
$forca_a = array(
'debit_opt_in'=>true
);
$forca = json_encode($forca_a,JSON_FORCE_OBJECT);
$wepay_create_array = array(
'name' =>"xxxx",
'description' => "xxxxxxxxx xxxx",
'callback_uri' => "xxxxxxx",
'country' => "CA",
'currencies' => array('CAD'),
'country_options' => $forca,
'rbits'=> array(
array(
'receive_time'=>strtotime("now"),
'type' =>'website_uri',
'source' => 'partner_database',
'properties'=> array('uri'=>xxxxx)
)
)
);如果我不传递country_options,它似乎可以工作,但是如果我传递这个参数,它总是会给我一个错误,说“不正确的JSON格式”。
我给wepay帮助中心发了一封电子邮件。他们告诉我,你传递的是字符串"country_options":"{"debit_opt_in":true}" <--- this is a string而不是"country_options":{"debit_opt_in":true} <--- this is a JSON object。所以我很困惑。我不知道如何传递JSON对象。唯一的办法就是json_encode($object)。
发布于 2016-04-25 13:13:43
使用下面的代码来获得合适的json
<?php
$forca_a = array(
'debit_opt_in'=>true
);
// $forca = json_encode($forca_a);
$wepay_create_array = array(
'name' =>"xxxx",
'description' => "xxxxxxxxx xxxx",
'callback_uri' => "xxxxxxx",
'country' => "CA",
'currencies' => array('CAD'),
'country_options' => $forca_a,
'rbits'=> array(
array(
'receive_time'=>strtotime("now"),
'type' =>'website_uri',
'source' => 'partner_database',
'properties'=> array('uri'=>'xxxxx')
)
)
);
print_r(json_encode($wepay_create_array));
?>此代码将给出以下json输出
{
"name": "xxxx",
"description": "xxxxxxxxx xxxx",
"callback_uri": "xxxxxxx",
"country": "CA",
"currencies": ["CAD"],
"country_options": {
"debit_opt_in": true
},
"rbits": [{
"receive_time": 1461561030,
"type": "website_uri",
"source": "partner_database",
"properties": {
"uri": "xxxxx"
}
}]
}发布于 2016-04-25 13:22:03
您不需要进行以下操作:
$forca = json_encode($forca_a,JSON_FORCE_OBJECT);在你把它放到$wepay_create_array之前。在发送请求之前,我想,你做了json_encode($wepay_create_array),是的,在那之后,你将会有country_options密钥的'string‘。
https://stackoverflow.com/questions/36832234
复制相似问题