Rumah > Soal Jawab > teks badan
Kini terdapat projek di mana Pihak A telah memberikan antara muka http seperti berikut
1 Sediakan url akses http antara muka, pengekodan aksara seragam: UTF-8.
2. http permintaan antara muka kandungan-Type="application/json".
3 Antara muka meminta url antara muka melalui siaran http dan menghantar badan yang mematuhi spesifikasi JSON.
Kekunci akses juga diberikan, bagaimana untuk melaksanakannya menggunakan PHP. terima kasih.
Contoh permintaan:
{
"secretKey": "************",
"stationNo": "123456789",
"msgId": "1111",
"data": {
"heatMeter": [
"heatMeter": "installAddr": "1#heat meter",
"readTime": "2017-09-25 12:00:01",
"accheat": 11.12,
"acccold": 11.13,
"kuasa": 11.14,
"aliran": 11.15,
"accflow": 11.16,
"intemp": 11.17,
" outTemp" : 21.18,
"tempDiff": 10.01,
"workTime": 12,
" Unit": "GJ",
"coldUnit": "GJ",
" powerUnit": "GJ/j",
N "FlowUnit": "m³", // Ambil perhatian bahawa "3 'unit ialah" realflowunit ":" m³/j "}}],Kembali ke sampel:
{ {
NULL2017-12-07 13:37:16
//参数一为提交的地址,参数二为提交方式,参数三为提交数据 function doRequest($url,$method,$data=null){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)'); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_AUTOREFERER, 1); if(!empty($data)){ curl_setopt($ch, CURLOPT_POSTFIELDS, $data); } curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $tmpInfo = curl_exec($ch); if (curl_errno($ch)) { return curl_error($ch); } curl_close($ch); return $tmpInfo; }