WechatUploadController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\admin\controllers\setting;
  8. use app\modules\admin\controllers\BaseController;
  9. use app\utils\ShareQrcode;
  10. use app\models\WechatConfig;
  11. use app\modules\admin\models\setting\WechatForm;
  12. class WechatUploadController extends BaseController
  13. {
  14. private $url = 'http://chidian.we10.cn/';
  15. /**
  16. * 获取小程序码
  17. *
  18. * @return void
  19. */
  20. public function actionQrcode()
  21. {
  22. try {
  23. $res = ShareQrcode::wxQrcode('pages/home/home', '0');
  24. if ($res['code'] == 1) {
  25. return $this->asJson([
  26. 'code' => 1,
  27. 'msg' => $res['response']['errmsg'],
  28. ]);
  29. }
  30. return $this->asJson([
  31. 'code' => 0,
  32. 'msg' => 'success',
  33. 'data' => $res['url_path'] . "?time=" . time(),//解决切换小程序appid后,前端图片显示的是旧的图片
  34. ]);
  35. } catch (\Exception $e) {
  36. return $this->asJson([
  37. 'code' => 1,
  38. 'msg' => $e->getMessage(),
  39. ]);
  40. }
  41. }
  42. /**
  43. * 登录
  44. *
  45. * @return void
  46. */
  47. public function actionWxLogin()
  48. {
  49. set_time_limit(0);
  50. $wechat_config = WechatConfig::findOne(['store_id' => get_store_id(), 'type' => 1]);
  51. $url = $this->url . 'login.php';
  52. $is_wxlive = post_params('is_wxlive', 0);
  53. $is_student = post_params('is_student', 0);
  54. $host = str_replace(['http://', 'https://'], ['', ''], \Yii::$app->request->hostInfo);
  55. $ws_url = isset(\Yii::$app->params['ws_url']) ? \Yii::$app->params['ws_url'] : 'ws.cyyvip.com';
  56. $res = http_get($url, [
  57. 'query' => [
  58. 'type' => 'new_system',
  59. 'appid' => $wechat_config->app_id,
  60. 'http_url' => $host,
  61. 'is_live' => $is_wxlive,
  62. 'is_student' => $is_student,
  63. 'store_id' => get_store_id(),
  64. 'version' => cyy_version(),
  65. 'ws_url' => $ws_url,
  66. ]
  67. ]);
  68. if ($res->getStatusCode() != 200) {
  69. return $this->asJson([
  70. 'code' => 1,
  71. 'msg' => '请求出错!',
  72. ]);
  73. }
  74. $content = json_decode((string)$res->getBody());
  75. return $this->asJson($content);
  76. }
  77. /**
  78. * 获取预览码
  79. *
  80. * @return void
  81. */
  82. public function actionPreview($num = 1)
  83. {
  84. set_time_limit(0);
  85. $model = new WechatForm();
  86. $model->store_id = get_store_id();
  87. return $this->asJson($model->preview());
  88. }
  89. /**
  90. * 上传小程序
  91. *
  92. * @return void
  93. */
  94. public function actionUpload()
  95. {
  96. set_time_limit(0);
  97. $model = new WechatForm();
  98. $model->store_id = get_store_id();
  99. return $this->asJson($model->upload());
  100. }
  101. }