| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\controllers\setting;
- use app\modules\admin\controllers\BaseController;
- use app\utils\ShareQrcode;
- use app\models\Option;
- class ServerWechatUploadController extends BaseController
- {
- private $url = 'http://chidian.we10.cn/';
- /**
- * 获取小程序码
- *
- * @return void
- */
- public function actionQrcode()
- {
- try {
- // 兼容wokerman模式
- $params = \all_params();
- $params['store_id'] = -1;
- \Yii::$app->request->setQueryParams($params);
- $res = ShareQrcode::wxQrcode('pages/index/index', '0', 600, false, true);
- if ($res['code'] == 1) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $res['response']['errmsg'],
- ]);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $res['url_path'] . "?time=" . time(),//解决切换小程序appid后,前端图片显示的是旧的图片
- ]);
- } catch (\Exception $e) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $e->getMessage(),
- 'file' => $e->getFile(),
- 'line' => $e->getLine(),
- ]);
- }
- }
- /**
- * 登录
- *
- * @return void
- */
- public function actionWxLogin()
- {
- set_time_limit(0);
- $appid = Option::get('platform_mch_appid', 0, 'saas')['value'] ?? '';
- if (empty($appid)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '请先配置服务端小程序appid',
- ]);
- }
- $url = $this->url . 'server/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 actionPreview($num = 1)
- {
- set_time_limit(0);
- try {
- $appid = Option::get('platform_mch_appid', 0, 'saas')['value'] ?? '';
- if (empty($appid)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '请先配置服务端小程序appid',
- ]);
- }
- $url = $this->url . 'server/preview.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) {
- if ($num < 4) {
- return $this->actionPreview($num + 1);
- } else {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '请求出错!',
- ]);
- }
- }
- $content = json_decode((string)$res->getBody());
- return $this->asJson($content);
- } catch (\Exception $e) {
- if ($num < 4) {
- return $this->actionPreview($num + 1);
- } else {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '请求出错!',
- ]);
- }
- }
- }
- /**
- * 上传小程序
- *
- * @return void
- */
- public function actionUpload()
- {
- set_time_limit(0);
- $appid = Option::get('platform_mch_appid', 0, 'saas')['value'] ?? '';
- if (empty($appid)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '请先配置服务端小程序appid',
- ]);
- }
- $url = $this->url . 'server/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);
- }
- }
|