我整合了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)
。
答案 0 :(得分:0)
<?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"
}
}]
}
答案 1 :(得分:0)
您无需制作:
$forca = json_encode($forca_a,JSON_FORCE_OBJECT);
在将它放到$ wepay_create_array之前。
在发送请求之前,我认为,您创建了json_encode($wepay_create_array)
,之后,您将拥有&#39; string&#39; for country_options key。