$this->store_id, 'type' => 1]); $url = $this->url . 'preview.php'; $host = str_replace(['http://', 'https://'], ['', ''], \Yii::$app->request->hostInfo); try { $res = http_get($url, [ 'query' => [ 'type' => 'new_system', 'appid' => $wechat_config->app_id, 'http_url' => $host, 'store_id' => $this->store_id, 'version' => cyy_version(), ] ]); if ($res->getStatusCode() != 200) { if ($num < 4) { sleep(5); return $this->preview($num + 1); } else { return [ 'code' => 1, 'msg' => '请求出错!', ]; } } $content = json_decode((string)$res->getBody()); return $content; } catch (\Throwable $e) { if ($num < 4) { return $this->preview($num + 1); } else { return [ 'code' => 1, 'msg' => '请求出错!', ]; } } } public function upload($num = 1) { $wechat_config = WechatConfig::findOne(['store_id' => $this->store_id, 'type' => 1]); $url = $this->url . 'upload.php'; $host = str_replace(['http://', 'https://'], ['', ''], \Yii::$app->request->hostInfo); try { $res = http_get($url, [ 'query' => [ 'type' => 'new_system', 'appid' => $wechat_config->app_id, 'http_url' => $host, 'store_id' => $this->store_id, 'version' => cyy_version(), ] ]); if ($res->getStatusCode() != 200) { if ($num < 4) { sleep(5); return $this->upload($num + 1); } else { return [ 'code' => 1, 'msg' => '请求出错!', ]; } } $content = json_decode((string)$res->getBody()); return $content; } catch (\Throwable $e) { if ($num < 4) { return $this->upload($num + 1); } else { return [ 'code' => 1, 'msg' => '请求出错!', ]; } } } }