这是我的代码:
class WechatServiceProvider extends ServiceProvider
{
// Bootstrap the application services.
// @return void
public function boot()
{
//
}
// Register the application services.
// @return void
public function register()
{
$this->app->bind('App\Http\Wechat',function()
{
$arr = array('token'=>'foo') ;
return new Wechat($arr) ;
});
}
}
尝试在此处自动注入依赖项
class WechatController extends Controller
{
protected $wechatObj;
public function __construct(Wechat $wechatObj)
{
$this->wechatObj = $wechatObj;
}
...
}
在App \ Http \ Wechat.php
中public function __construct($options)
{
$this->token = isset($options['token'])?$options['token']:'';
$this->encodingAesKey = isset($options['encodingaeskey'])?$options['encodingaeskey']:'';
$this->appid = isset($options['appid'])?$options['appid']:'';
$this->appsecret = isset($options['appsecret'])?$options['appsecret']:'';
$this->agentid = isset($options['agentid'])?$options['agentid']:'';
$this->debug = isset($options['debug'])?$options['debug']:false;
$this->logcallback = isset($options['logcallback'])?$options['logcallback']:false;
}
错误堆栈
答案 0 :(得分:1)
所有步骤都完美无缺,但您需要在config/app.php
数组providers
下的'providers' => [
// .. others
WechatServiceProvider::class,
],
注册您的服务提供商:
sun.awt.image.codec.*