easywechat報錯:Failed to cache access token


場景:

1.小程序

2.在代碼中用$app=EasyWeChat\Factory::miniProgram(['app_id' => $app_id, 'secret' => $secret])獲取小程序實例

3.配置文件wechat.default.use_laravel_cache=true

結果在$app->template_message->send()的時候,拋異常(EasyWeChat\Kernel\AccessToken.php):

RuntimeException('Failed to cache access token')

但是用$app=EasyWeChat::miniProgram()加載默認配置文件卻能正常send()

問題還是出在第2步,追溯源碼,use_laravel_cache用在Overtrue\LaravelWeChat\ServiceProvider中,當為true的時候,miniProgram容器中是包含了Overtrue\LaravelWeChat\CacheBridge(app(cache.store))這個實例的

如果我們在業務邏輯中手動輸入配置,即步驟2,但配置文件又用的laravel緩存,則會有這個異常

解決方法就是接着步驟2:

$app['cache'] = new Overtrue\LaravelWeChat\CacheBridge(app(cache.store))


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM