'unionpay'], ]; } public function save() { if(!$this->validate()){ return $this->getModelError(); } if($this->scenario == 'unionpay'){ if (!is_dir(\Yii::$app->runtimePath . '/pem')) { mkdir(\Yii::$app->runtimePath . '/pem'); file_put_contents(\Yii::$app->runtimePath . '/pem/index.html', ''); } $private_key_pem_file = null; if ($this->private_key_pem) { $private_key_pem_file = \Yii::$app->runtimePath . '/pem/' . md5($this->private_key_pem); if (!file_exists($private_key_pem_file)) file_put_contents($private_key_pem_file, $this->private_key_pem); if(!file_exists($private_key_pem_file)){ return $this->apiReturnError('证书读取不到'); } } $public_key_pem_file = null; if ($this->public_key_pem) { $public_key_pem_file = \Yii::$app->runtimePath . '/pem/' . md5($this->public_key_pem); if (!file_exists($public_key_pem_file)) file_put_contents($public_key_pem_file, $this->public_key_pem); if(!file_exists($public_key_pem_file)){ return $this->apiReturnError('证书读取不到'); } } } $data = [ 'app_id' => $this->app_id, 'mch_id' => $this->mch_id, 'private_key_pem' => $this->private_key_pem, 'private_key_password' => $this->private_key_password, 'public_key_pem' => $this->public_key_pem, 'api_url' => $this->api_url, ]; $data = base64_encode(json_encode($data)); return $this->apiReturnSuccess('ok', ['data' => $data]); } }