<?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($Gttsd) { $this->addVariables(array('jsonMode' => $Gttsd)); return $this; } public function editorHeight($Gttsd) { $this->addVariables(array('editorHeight' => $Gttsd)); return $this; } public function unserializeValue($Gttsd, AbstractField $acdQI) { if (null === $Gttsd) { return $Gttsd; } return @json_decode($Gttsd, true); } public function serializeValue($Gttsd, $BWo2e) { return json_encode($Gttsd, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); } public function prepareInput($Gttsd, $BWo2e) { goto xBJfq; mSw0X: BizException::throwsIf($this->label . ' ' . L('Json Format Error'), $Gttsd && null === $RCoRX); goto rPhe5; rPhe5: return $RCoRX; goto oCn2Z; xBJfq: $RCoRX = @json_decode($Gttsd, true); goto mSw0X; oCn2Z: } public static function executeApi($Gttsd) { goto SK_mg; m2Ozd: $LEG8W['header'] = array(); goto QoXEG; QoXEG: if (!empty($Gttsd['headers'])) { foreach ($Gttsd['headers'] as $F6Fus) { $LEG8W['header'][$F6Fus['key']] = $F6Fus['value']; } } goto CARE_; ZwRzp: BizException::throwsIf('method错误', empty($Gttsd['method']) || !in_array($Gttsd['method'], array('GET', 'POST', 'PUT', 'DELETE'))); goto psaH5; GuHU2: $LEG8W['method'] = $Gttsd['method']; goto m2Ozd; vDX4h: $LEG8W['returnHeader'] = true; goto GuHU2; CARE_: if (!empty($Gttsd['query'])) { goto amQFB; t52xj: foreach ($Gttsd['query'] as $F6Fus) { $sFfhd[$F6Fus['key']] = $F6Fus['value']; } goto ZMk2F; amQFB: $sFfhd = array(); goto t52xj; ZMk2F: $qHLCM = $sFfhd; goto VpLRb; VpLRb: } goto Y1s94; Y1s94: switch ($LEG8W['method']) { case 'POST': switch ($Gttsd['enctype']) { case 'FormData': goto drg5d; drg5d: $qHLCM = array(); goto RguW4; iAIAk: break; goto plzOq; d8F2c: $LEG8W['header']['Content-Type'] = 'multipart/form-data'; goto iAIAk; RguW4: if (!empty($Gttsd['bodyParam'])) { foreach ($Gttsd['bodyParam'] as $F6Fus) { $qHLCM[$F6Fus['key']] = $F6Fus['value']; } } goto d8F2c; plzOq: case 'UrlEncoded': goto TDW2g; ROUWX: if (!empty($Gttsd['bodyParam'])) { foreach ($Gttsd['bodyParam'] as $F6Fus) { $qHLCM[$F6Fus['key']] = $F6Fus['value']; } } goto eHKcd; eHKcd: $LEG8W['header']['Content-Type'] = 'application/x-www-form-urlencoded'; goto wJs9w; wJs9w: break; goto SjPQ9; TDW2g: $qHLCM = array(); goto ROUWX; SjPQ9: case 'Json': goto HsAkA; HsAkA: $qHLCM = $Gttsd['bodyRaw']; goto ksbdu; ksbdu: $LEG8W['header']['Content-Type'] = 'application/json'; goto u5B7c; u5B7c: break; goto LW0Jj; LW0Jj: } break; } goto sAKur; enCWM: return $f3Nqc; goto PNrsI; psaH5: BizException::throwsIf('enctype错误', empty($Gttsd['enctype']) || !in_array($Gttsd['enctype'], array('FormData', 'UrlEncoded', 'Json'))); goto Vzv1J; sAKur: $f3Nqc = CurlUtil::request($Gttsd['url'], $qHLCM, $LEG8W); goto enCWM; fxhqi: $LEG8W = array(); goto vDX4h; SK_mg: BizException::throwsIf('url为空', empty($Gttsd['url'])); goto ZwRzp; Vzv1J: $qHLCM = array(); goto fxhqi; PNrsI: } }