<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Field; use ModStart\Core\Exception\BizException; use ModStart\Core\Util\CurlUtil; class Json extends AbstractField { const MODE_API = 'api'; const MODE_DEFAULT = 'default'; protected function setup() { $this->addVariables(array('editorHeight' => '200px', 'jsonMode' => 'default')); } public function jsonMode($gwXrh) { $this->addVariables(array('jsonMode' => $gwXrh)); return $this; } public function editorHeight($gwXrh) { $this->addVariables(array('editorHeight' => $gwXrh)); return $this; } public function unserializeValue($gwXrh, AbstractField $VWt5t) { if (null === $gwXrh) { return $gwXrh; } return @json_decode($gwXrh, true); } public function serializeValue($gwXrh, $uV19D) { return json_encode($gwXrh, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); } public function prepareInput($gwXrh, $uV19D) { goto oWMfi; Ar2Cg: BizException::throwsIf($this->label . ' ' . L('Json Format Error'), $gwXrh && null === $bG1t2); goto jP5vD; jP5vD: return $bG1t2; goto XQt6T; oWMfi: $bG1t2 = @json_decode($gwXrh, true); goto Ar2Cg; XQt6T: } public static function executeApi($gwXrh) { goto dkaB7; Gagbt: $oOr7L = array(); goto JSVT6; q4nsz: return $UdQ1p; goto AYLtf; il5ma: BizException::throwsIf('method错误', empty($gwXrh['method']) || !in_array($gwXrh['method'], array('GET', 'POST', 'PUT', 'DELETE'))); goto rNfSg; dkaB7: BizException::throwsIf('url为空', empty($gwXrh['url'])); goto il5ma; N1bSQ: if (!empty($gwXrh['headers'])) { foreach ($gwXrh['headers'] as $VFelt) { $oOr7L['header'][$VFelt['key']] = $VFelt['value']; } } goto fjMOP; fjMOP: if (!empty($gwXrh['query'])) { goto Qw8JA; Qw8JA: $lpymm = array(); goto ToOFs; zLeSG: $zlK8N = $lpymm; goto lOgyn; ToOFs: foreach ($gwXrh['query'] as $VFelt) { $lpymm[$VFelt['key']] = $VFelt['value']; } goto zLeSG; lOgyn: } goto fq2hH; rNfSg: BizException::throwsIf('enctype错误', empty($gwXrh['enctype']) || !in_array($gwXrh['enctype'], array('FormData', 'UrlEncoded', 'Json'))); goto tNy3z; kKrR3: $oOr7L['method'] = $gwXrh['method']; goto XEtAY; fq2hH: switch ($oOr7L['method']) { case 'POST': switch ($gwXrh['enctype']) { case 'FormData': goto OnFg_; OnFg_: $zlK8N = array(); goto mX13U; gT2CF: break; goto TPhWv; OS7XV: $oOr7L['header']['Content-Type'] = 'multipart/form-data'; goto gT2CF; mX13U: if (!empty($gwXrh['bodyParam'])) { foreach ($gwXrh['bodyParam'] as $VFelt) { $zlK8N[$VFelt['key']] = $VFelt['value']; } } goto OS7XV; TPhWv: case 'UrlEncoded': goto GJcif; rBFlT: if (!empty($gwXrh['bodyParam'])) { foreach ($gwXrh['bodyParam'] as $VFelt) { $zlK8N[$VFelt['key']] = $VFelt['value']; } } goto e9LOZ; GJcif: $zlK8N = array(); goto rBFlT; e9LOZ: $oOr7L['header']['Content-Type'] = 'application/x-www-form-urlencoded'; goto rfg2P; rfg2P: break; goto uurPM; uurPM: case 'Json': goto CANgg; mrAbb: $oOr7L['header']['Content-Type'] = 'application/json'; goto r0C_W; r0C_W: break; goto DMvuq; CANgg: $zlK8N = $gwXrh['bodyRaw']; goto mrAbb; DMvuq: } break; } goto itc4y; JSVT6: $oOr7L['returnHeader'] = true; goto kKrR3; XEtAY: $oOr7L['header'] = array(); goto N1bSQ; itc4y: $UdQ1p = CurlUtil::request($gwXrh['url'], $zlK8N, $oOr7L); goto q4nsz; tNy3z: $zlK8N = array(); goto Gagbt; AYLtf: } }