<?php
/**
 * Author: luzheng.liu
 * Time: 2020/12/5 00:49
 */

namespace app\common\service;


use app\index\model\SettingModel;

class CommonService {

    static $setData;

    public static function getSetData($channelId) {
        if (empty(self::$setData)){
            $data = (new SettingModel())::where(['channel_id' => $channelId])->find();
            self::$setData = $data;
            return $data;
        }
        return self::$setData;

    }

    public static function getAuthUrl($channelId) {
        $baseUrl = self::getBaeUrl($channelId);
        return $baseUrl.'?redirecturi='.self::getRedirectUrl($channelId);
    }

    public static function getBaeUrl($channelId) {
        $data = self::getSetData($channelId);
        return "http://{$data['domain']}/api/wechat/focusarea/{$data['site_id']}/{$data['unique_key']}";

    }

    public static function getRedirectUrl($channelId) {
        $data = self::getSetData($channelId);
        return $data['auth_redirct_url'];
    }
}