Cert.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | WeChatDeveloper
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2020 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://think.ctolog.com
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | github开源项目:https://github.com/zoujingli/WeChatDeveloper
  12. // +----------------------------------------------------------------------
  13. namespace WePayV3;
  14. use WeChat\Exceptions\InvalidResponseException;
  15. use WePayV3\Contracts\BasicWePay;
  16. use WePayV3\Contracts\DecryptAes;
  17. /**
  18. * 平台证书管理
  19. * Class Cert
  20. * @package WePayV3
  21. */
  22. class Cert extends BasicWePay
  23. {
  24. /**
  25. * 商户平台下载证书
  26. * @throws InvalidResponseException
  27. */
  28. public function download()
  29. {
  30. try {
  31. $aes = new DecryptAes($this->config['mch_v3_key']);
  32. $result = $this->doRequest('GET', '/v3/certificates');
  33. foreach ($result['data'] as $vo) {
  34. $this->tmpFile($vo['serial_no'], $aes->decryptToString(
  35. $vo['encrypt_certificate']['associated_data'],
  36. $vo['encrypt_certificate']['nonce'],
  37. $vo['encrypt_certificate']['ciphertext']
  38. ));
  39. }
  40. } catch (\Exception $exception) {
  41. throw new InvalidResponseException($exception->getMessage(), $exception->getCode());
  42. }
  43. }
  44. }