You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.4 KiB
74 lines
2.4 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\service\admin\weapp;
|
|
|
|
use app\dict\common\CommonDict;
|
|
use app\model\sys\SysConfig;
|
|
use app\service\core\weapp\CoreWeappConfigService;
|
|
use core\base\BaseAdminService;
|
|
use think\Model;
|
|
|
|
/**
|
|
* 微信小程序设置
|
|
* Class WeappConfigService
|
|
* @package app\service\admin\weapp
|
|
*/
|
|
class WeappConfigService extends BaseAdminService
|
|
{
|
|
/**
|
|
* 获取配置信息
|
|
* @return array|null
|
|
*/
|
|
public function getWeappConfig()
|
|
{
|
|
$config_info = (new CoreWeappConfigService())->getWeappConfig();
|
|
foreach ($config_info as $k => $v) {
|
|
if ($v !== '' && in_array($k, ['app_secret', 'encoding_aes_key'])) {
|
|
$config_info[$k] = CommonDict::ENCRYPT_STR;
|
|
}
|
|
}
|
|
return array_merge($config_info, $this->getWeappStaticInfo());
|
|
|
|
}
|
|
|
|
/**
|
|
* 设置配置
|
|
* @param array $data
|
|
* @return SysConfig|bool|Model
|
|
*/
|
|
public function setWeappConfig(array $data){
|
|
$config = (new CoreWeappConfigService())->getWeappConfig();
|
|
foreach ($data as $k => $v) {
|
|
if ($v == CommonDict::ENCRYPT_STR) {
|
|
$data[$k] = $config[$k];
|
|
}
|
|
}
|
|
return (new CoreWeappConfigService())->setWeappConfig($data);
|
|
}
|
|
|
|
/**
|
|
*查询微信小程序需要的静态信息
|
|
* @return array
|
|
*/
|
|
public function getWeappStaticInfo(){
|
|
$domain = request()->domain();
|
|
$domain = str_replace('http://', 'https://', $domain);
|
|
return [
|
|
'serve_url' => (string)url('/api/weapp/serve', [],'',true),
|
|
'request_url' => $domain,
|
|
'socket_url' => "wss://".request()->host(),
|
|
'upload_url' => $domain,
|
|
'download_url' => $domain,
|
|
'upload_ip' => gethostbyname('oss.niucloud.com')
|
|
];
|
|
}
|
|
}
|
|
|