Client.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace ln\services\easywechat\certficates;
  3. use ln\services\easywechat\BaseClient;
  4. use EasyWeChat\Core\AbstractAPI;
  5. use think\exception\InvalidArgumentException;
  6. use think\facade\Cache;
  7. class Client extends BaseClient
  8. {
  9. public function get()
  10. {
  11. $driver = Cache::store('file');
  12. $cacheKey = '_wx_v3' . $this->app['config']['service_payment']['serial_no'];
  13. if ($driver->has($cacheKey)) {
  14. return $driver->get($cacheKey);
  15. }
  16. $certficates = $this->getCertficates();
  17. $driver->set($cacheKey, $certficates, 3600 * 24 * 30);
  18. return $certficates;
  19. }
  20. /**
  21. * get certficates.
  22. *
  23. * @return array
  24. */
  25. public function getCertficates()
  26. {
  27. $response = $this->request('/v3/certificates', 'GET', [], false);
  28. $certificates = $response['data'][0];
  29. $certificates['certificates'] = $this->decrypt($certificates['encrypt_certificate']);
  30. unset($certificates['encrypt_certificate']);
  31. return $certificates;
  32. }
  33. }