2015-09-10 48 views
0

我正在尝试在我的symfony项目中集成WHAnonymous API。在symfony中集成Whatsapp API

我在项目中使用的作曲家包括安装它,它现在是我的供应商的文件夹中。

但我不理解如何将其导入到我的项目!

这是我的经理级。

<?php 

namespace AppBundle\Managers; 

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 


class WhatsAppManager 
{ 

    private $test; 
    /** 
    * Constructor 
    */ 
    public function __construct() 
    { 
     $this->test =1; 
    } 

    public function sendMessage() 
    { 
    $username = ""; // Your number with country code, ie: 34123456789 
    $nickname = ""; // Your nickname, it will appear in push notifications 
    $debug = true; // Shows debug log 

    // Create a instance of WhastPort. 
    $w = new WhatsProt($username, $nickname, $debug); 
    var_dump("In send message method"); 
    } 
} 
?> 

我用

require_once 'whatsprot.class.php'; 

require_once 'Whatsapp\Bundle\Chat-api\src\whatsprot.class.php'; 

use Whatsapp\Bundle\Chat-api\Whatsprot 

但它只是不工作。 请告诉我正确的做法! 当我在symfony中使用第三方供应商时,我应该做些什么。

我也考虑了WHanonymous的文档,但我发现只有代码片段使用它,而不是将其导入的方式。 Git回购WHAnonymous:https://github.com/WHAnonymous

回答

3

该类没有名称空间,但是由我的作曲家创建的自动加载系统正确加载。所以,你可以参考类没有任何包括或要求指令,而只是用\为例:

// Create a instance of WhastPort. 
    $w = new \WhatsProt($username, $nickname, $debug); 

希望这有助于

+0

Thanks.It工作! – user3425344

+0

但你能解释我是如何工作的吗? 作曲家的路径是whatsapp/chat-api。 但是这个类的路径是whatsapp/chat-api/src/whatsprot.class.php。 – user3425344

+0

hi @ user3425344该库不尊重[标准PRS-0](http://www.php-fig.org/psr/psr-0/),但作曲家能够正确加载类 – Matteo