小编Yan*_*eld的帖子

Google API客户端和Cronjob

我正在使用Google API客户端来阅读Gmail中的电子邮件.现在我想添加一个Cronjob,每5分钟读一次邮件.

使用Google API客户端的问题是,它需要允许用户首先点击授权链接并允许用户使用Google API客户端.

我有一个类Inbox,其初始化函数初始化了Google API客户端.但是cronjob不起作用,因为我必须获得access_token.

public function initialize() {
    $configuration = Configuration::getConfiguration('class_Inbox');

    // Creates the Google Client
    $this->client = new Google_Client();
    $this->client->setApplicationName('Tiptsernetwork');
    $this->client->setClientId($configuration['clientId']);
    $this->client->setClientSecret($configuration['clientSecret']);
    $this->client->setRedirectUri('http://www.tipsternetwork.nl/cronjob/authenticate');
    $this->client->addScope('https://mail.google.com/');
    $this->client->setApprovalPrompt('force');
    $this->client->setAccessType('offline');

    // Creates the Google Gmail Service
    $this->service = new Google_Service_Gmail($this->client);

    // Authenticates the user.
    if (isset($_GET['code'])) {
        $this->authenticate($_GET['code']);
    }

    // Check if we have an access token in the session
    if (isset($_SESSION['access_token'])) {
        $this->client->setAccessToken($_SESSION['access_token']);
    } else {
        $loginUrl = $this->client->createAuthUrl();
        echo '<a href="'.$loginUrl.'">Click Here</a>';
    }

    // If the token is …
Run Code Online (Sandbox Code Playgroud)

php cron crontab google-api-php-client

5
推荐指数
1
解决办法
734
查看次数

Docker for WordPress 速度慢

问题

我在使用 WordPress 和 Docker 时遇到问题,因为我的网站加载时间很慢(+- 7 秒)。我不确定为什么会发生这种情况,但我认为这与外部数据库或共享卷有关。

设置:

我有一个使用 XDebug 和 Mailhog 在 WordPress 上构建的自定义 Dockerfile。这个 Dockerfile 包含在我的 docker-compose.yml 中,我的 docker-compose 包含的其他服务是 WP-CLI 和 Mailhog。我的数据库托管在 Amazon RDS 上,因此我可以与同事共享。

代码:

我的 Dockerfile 如下所示:

FROM wordpress:latest

# Plugins & Media
RUN mkdir -p /var/www/html/wp-content/plugins
RUN mkdir -p /var/www/html/wp-content/uploads

RUN chown -R www-data:www-data /var/www

RUN find /var/www/ -type d -exec chmod 0755 {} \;
RUN find /var/www/ -type f -exec chmod 644 {} \;

# Mailhog
RUN curl --location --output /usr/local/bin/mhsendmail …
Run Code Online (Sandbox Code Playgroud)

wordpress docker docker-compose

5
推荐指数
1
解决办法
4670
查看次数

将扩展类与基类合并

我有两个类,一个叫做 MemberModel,一个叫做 CustomPrincipal。CustomPrincipal 类继承 MemberModel 类。

MemberModel 类如下所示:

namespace example.Models
{
    public class MemberModel
    {
        [Required]
        public string Username { get; set; }
        [Required]
        public string Password { get; set; }

        public bool Remember { get; set; }
    }
}
Run Code Online (Sandbox Code Playgroud)

CustomPrincipal 类如下所示:

namespace example.Examples
{
    public class CustomPrincipal : MemberModel, IPrincipal
    {
        public CustomPrincipal(IIdentity identity)
        {
            this.Identity = identity;
        }

        public IIdentity Identity { get; private set; }

        public bool IsInRole(string role) { return false; }
    }
}
Run Code Online (Sandbox Code Playgroud)

在下面的示例中,您会看到两个类 MemberModel …

c# merge inheritance class base-class

2
推荐指数
1
解决办法
1115
查看次数