【发布时间】:2018-04-07 07:53:21
【问题描述】:
{
"id": "4a59a50e-904a-674d-2553-8954ec4a841d",
"name": "JSON API",
"description": "",
"order": [
"155ae062-f839-ef5a-6c40-61e821202984"
],
"folders": [],
"folders_order": [],
"timestamp": 1522932542555,
"owner": 0,
"public": false,
"requests": [
{
"id": "155ae062-f839-ef5a-6c40-61e821202984",
"headers": "Authorization: Basic OTE5MTAwMTkxY2OjEyMzQ1Ng==\n",
"headerData": [
{
"key": "Authorization",
"value": "Basic OTE5MTAwMTkxNjY2OyMzQ1Ng==",
"description": "",
"enabled": true
}
],
"url": "https://apiurl.in/bez/api/v1/documents/upload?disableSms=false",
"queryParams": [
{
"key": "disableSms",
"value": "false",
"equals": true,
"description": "",
"enabled": true
}
],
"preRequestScript": null,
"pathVariables": {},
"pathVariableData": [],
"method": "POST",
"data": [
{
"key": "jsonData",
"value": "{\"phoneNumber\":\"9999999999\",\"merchantId\":\"1122112211\",\"amount\":100,\"billDate\":1514891788753,\"gender\":\"male\",\"ageGroup\":\"21-30\",\"dateOfBirth\":\"12-dec-1989\",\"email\":\"dfgd@gfdgfdg.in\",\"address\":\"dfg\"}",
"description": "Required fileds\n\"phoneNumber\",\"merchantId\",\"amount\",\"billDate\"\noptional fileds\n\"gender\",\"ageGroup\",\"dateOfBirth\",\"email\",\"address\"",
"type": "text",
"enabled": true
},
{
"key": "file",
"value": "",
"description": "",
"type": "file",
"enabled": true
}
],
"dataMode": "params",
"tests": null,
"currentHelper": "basicAuth",
"helperAttributes": {
"id": "basic",
"username": "0101010101",
"password": "30303030",
"saveToRequest": true
},
"time": 1514892082233,
"name": "Bill Uploading",
"description": "",
"collectionId": "4a59a50e-904a-674d-2553-8954ec4a841d",
"responses": [],
"collection_id": "4a59a50e-904a-674d-2553-8954ec4a841d"
}
]
}
以上代码在 JSON 文件中。我需要使用 PHP 文件中的代码。
下面的代码是 PHP 的。我不知道如何通过 PHP 发出 POST 请求。
public function sendSmsApi($array)
{
$data = array();
$data['apikey'] = Configuration::get('Sendin_Api_Key');
$data['to'] = $array['to'];
$data['sender'] = Configuration::get('sender_id');
$data['message'] = $array['text'];
$data['type'] = 'xml';
return Tools::jsonDecode($this->curlRequest($data));
}
如何在 PHP 中包含 JSON 数据并向 API URL 发出 POST 请求。 PHP 代码实际上将消息发送给客户。我想在 PHP 文件中包含 JSON 代码以向 API URL 发送 POST 请求。
【问题讨论】:
-
你可以发个帖子
CURL让我帮你打出来,我建议谷歌搜索一些关于它的教程。 -
Guzzle 是一个流行的 HTTP 客户端:github.com/guzzle/guzzle
-
我认为是
Tools::jsonEncode