WeappConfigService.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的saas管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace app\service\admin\weapp;
  12. use app\model\sys\SysConfig;
  13. use app\service\core\weapp\CoreWeappConfigService;
  14. use core\base\BaseAdminService;
  15. use think\Model;
  16. /**
  17. * 微信小程序设置
  18. * Class WeappConfigService
  19. * @package app\service\admin\weapp
  20. */
  21. class WeappConfigService extends BaseAdminService
  22. {
  23. /**
  24. * 获取配置信息
  25. * @return array|null
  26. */
  27. public function getWeappConfig()
  28. {
  29. $config_info = (new CoreWeappConfigService())->getWeappConfig();
  30. return array_merge($config_info, $this->getWeappStaticInfo());
  31. }
  32. /**
  33. * 设置配置
  34. * @param array $data
  35. * @return SysConfig|bool|Model
  36. */
  37. public function setWeappConfig(array $data){
  38. return (new CoreWeappConfigService())->setWeappConfig($data);
  39. }
  40. /**
  41. *查询微信小程序需要的静态信息
  42. * @return array
  43. */
  44. public function getWeappStaticInfo(){
  45. $domain = request()->domain();
  46. return [
  47. 'serve_url' => (string)url('/api/weapp/serve', [],'',true),
  48. 'request_url' => $domain,
  49. 'socket_url' => "wss://".request()->host(),
  50. 'upload_url' => $domain,
  51. 'download_url' => $domain,
  52. 'upload_ip' => gethostbyname('oss.niucloud.com')
  53. ];
  54. }
  55. }