asJson([ 'code' => 1, 'msg' => '请先配置三方平台小程序appid', ]); } $url = $this->url . 'template/login.php'; $host = str_replace(['http://', 'https://'], ['', ''], \Yii::$app->request->hostInfo); $ws_url = isset(\Yii::$app->params['ws_url']) ? \Yii::$app->params['ws_url'] : 'ws.cyyvip.com'; $res = http_get($url, [ 'query' => [ 'appid' => $appid, 'http_url' => $host, 'version' => cyy_version(), 'ws_url' => $ws_url, ] ]); if ($res->getStatusCode() != 200) { return $this->asJson([ 'code' => 1, 'msg' => '请求出错!', ]); } $content = json_decode((string)$res->getBody()); return $this->asJson($content); } /** * 上传小程序 * * @return void */ public function actionUpload() { set_time_limit(0); $appid = Option::get('platform_wechat_third_appid', 0, 'saas')['value'] ?? ''; if (empty($appid)) { return $this->asJson([ 'code' => 1, 'msg' => '请先配置三方平台小程序appid', ]); } $url = $this->url . 'template/upload.php'; $host = str_replace(['http://', 'https://'], ['', ''], \Yii::$app->request->hostInfo); $res = http_get($url, [ 'query' => [ 'appid' => $appid, 'http_url' => $host, 'version' => cyy_version(), ] ]); if ($res->getStatusCode() != 200) { return $this->asJson([ 'code' => 1, 'msg' => '请求出错!', ]); } $content = json_decode((string)$res->getBody()); return $this->asJson($content); } public function actionAddTemplate() { try { $form = new WechatThirdForm; $res = $form->openPlatform->code_template->getDrafts(); if ($res['errcode'] != 0) { throw new \Exception('添加到模版库失败'); } $draft_list = $res['draft_list']; foreach ($draft_list as &$item) { $item['draft_id'] = (string)$item['draft_id']; } $last_names = array_column($draft_list, 'create_time'); array_multisort($last_names, SORT_DESC, $draft_list); $id = $draft_list[0]['draft_id']; $res = $form->openPlatform->code_template->createFromDraft($id); if ($res['errcode'] != 0) { throw new \Exception('添加到模版库失败'); } return $this->asJson([ 'code' => 0, 'msg' => '添加成功', ]); } catch(\Throwable $e) { return $this->asJson([ 'code' => 1, 'msg' => $e->getMessage(), ]); } } }