Cert.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | WeChatDeveloper
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2022 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: https://thinkadmin.top
  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. * @return void
  27. * @throws \WeChat\Exceptions\InvalidResponseException
  28. */
  29. public function download()
  30. {
  31. try {
  32. $aes = new DecryptAes($this->config['mch_v3_key']);
  33. $result = $this->doRequest('GET', '/v3/certificates');
  34. foreach ($result['data'] as $vo) {
  35. $this->tmpFile($vo['serial_no'], $aes->decryptToString(
  36. $vo['encrypt_certificate']['associated_data'],
  37. $vo['encrypt_certificate']['nonce'],
  38. $vo['encrypt_certificate']['ciphertext']
  39. ));
  40. }
  41. } catch (\Exception $exception) {
  42. throw new InvalidResponseException($exception->getMessage(), $exception->getCode());
  43. }
  44. }
  45. }