| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\models\setting;
- use app\models\WechatConfig;
- use yii\base\Model;
- class WechatForm extends Model
- {
- private $url = 'http://chidian.we10.cn/';
- public $store_id;
- public function preview($num = 1)
- {
- $wechat_config = WechatConfig::findOne(['store_id' => $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' => '请求出错!',
- ];
- }
- }
- }
- }
|