ServiceProvider.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /*
  3. * This file is part of the overtrue/wechat.
  4. *
  5. * (c) overtrue <i@overtrue.me>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace crmeb\services\easywechat\miniPayment;
  11. use EasyWeChat\Payment\Merchant;
  12. use Pimple\Container;
  13. use Pimple\ServiceProviderInterface;
  14. use EasyWeChat\MiniProgram\AccessToken;
  15. /**
  16. * Class ServiceProvider.
  17. *
  18. * @author mingyoung <mingyoungcheung@gmail.com>
  19. */
  20. class ServiceProvider implements ServiceProviderInterface
  21. {
  22. /**
  23. * {@inheritdoc}.
  24. */
  25. public function register(Container $pimple)
  26. {
  27. $pimple['merchant'] = function ($pimple) {
  28. $config = array_merge(
  29. ['app_id' => $pimple['config']['app_id']],
  30. $pimple['config']->get('payment', [])
  31. );
  32. return new Merchant($config);
  33. };
  34. $pimple['mini_program.access_token'] = function ($pimple) {
  35. return new AccessToken(
  36. $pimple['config']['mini_program']['app_id'],
  37. $pimple['config']['mini_program']['secret'],
  38. $pimple['cache']
  39. );
  40. };
  41. $pimple['minipay'] = function ($pimple) {
  42. return new WeChatClient($pimple['mini_program.access_token'],$pimple['merchant']);
  43. };
  44. }
  45. }