[英]How to pass json object using PHP in Wepay API
我已經集成了Wepay payment gateway
。 但是我面臨將json object to wepay
傳遞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)
。
嘿使用下面的代碼來獲取正確的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"
}
}]
}
您無需進行以下操作:
$forca = json_encode($forca_a,JSON_FORCE_OBJECT);
然后將其放入$ wepay_create_array。 我認為,在發送請求之前,您要制作json_encode($wepay_create_array)
,是的,在那之后,您將為country_options鍵使用“字符串”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.