Heim >Backend-Entwicklung >PHP-Tutorial >Probleme mit domänenübergreifenden Anfragen
Mein Frontend-Code sieht so aus:
Das Backend ist in PHP geschrieben,
<code><?php class IBaseAction extends Action { public $params = array();// 所有请求的参数 public $return = array('returnCode' =>200, 'returnDesc' => 'success'); // 返回的基础数据 function __construct() { $this->return['serverTime'] =time(); Log::record('传入的参数:' . var_export($_REQUEST, true),Log::DEBUG); $this->params = @json_decode(base64_decode(I('post.params'),true),true); if (!$this->params){ $this->return['returnCode'] =100; $this->return['returnDesc'] = 'sign failed!'; $this->responseJson(); }else if(C('KEY')!=$this->params['key']){ $this->return['returnCode'] =100; $this->return['returnDesc'] = 'sign failed!'; $this->return['returnAlert'] = '密钥不正确!'; $this->responseJson(); } } /* * 检查接口传入的方式 */ public function checkPublicParams($interfaces) { $pass = false; $this->return['returnCode'] = 100; if (!I('post.')) { $this->return['returnDesc'] = '请求方式错误'; } else if (!I('post.method') || !I('post.params')) { $this->return['returnDesc'] = '接口参数错误'; } else if (!array_key_exists(I('post.method'), $interfaces)) { $this->return['returnDesc'] = '接口名错误'; } else { $this->return['returnCode'] = 200; $pass = true; } return $pass; } protected function responseJson() { exit(json_encode($this->return)); } }</code>
Der unveränderte Status ist Rückgabeauthentifizierungsfehler
“{"returnCode":100,"returnDesc":sign failed!","serverTime":1476799012}"
Ich habe auch eine Änderungsmethode im Internet gefunden
Aber ich weiß nicht, wie ich es ändern soll