false]; private function __clone() { } private function __construct($userid) { $config = \Yii::$app->params['jac_erp']; // ... 在应用配置之前初始化 if(!$config['secret']){ throw new \Exception('江奥川ERP参数配置错误'); } if($userid){ $config['userid'] = $userid; } $this->config = $config; } public static function getInstance($userid) { if(empty(self::$instance)){ self::$instance = new self($userid); } return self::$instance; } public function syncOrder($params){ \Yii::info(__METHOD__."——同步订单至江奥川erp接口地址: ".$this->config['url'].'/tis-server/api/addTisApplyMaster'); $url = $this->config['url'].'/tis-server/api/addTisApplyMaster'; $params['hospital_code'] = $this->config['userid']; $params['apply_no'] = time().rand(100,999); $response = (new Client(['http_errors' => false]))->post( $url, [ 'headers' => ['Content-Type' => 'application/json', 'userid' => $this->config['userid'], 'secret' => $this->config['secret']], \GuzzleHttp\RequestOptions::JSON =>$params ] ); $result = json_decode($response->getBody(),true); if ($result['code']) { throw new Exception($result['message']); } return true; } }