WechatPayTypeEnum.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace common\enums;
  3. use common\models\user\User;
  4. /**
  5. * 微信支付类型
  6. *
  7. *
  8. * Class WechatPayTypeEnum
  9. * @package common\enums
  10. */
  11. class WechatPayTypeEnum extends BaseEnum
  12. {
  13. const JS = 'js';
  14. const APP = 'app';
  15. const NATIVE = 'native';
  16. const POS = 'pos';
  17. const M_WEB = 'mweb';
  18. const MINI_PROGRAM = 'mini_program';
  19. // pem文件配置字段
  20. const CERT_PEM = 'wechat_cert_pem';
  21. const KEY_PEM = 'wechat_key_pem';
  22. const WECHAT_TRANSFER_V3 = '3';
  23. const WECHAT_TRANSFER_V2 = '2';
  24. /**
  25. * @return array|string[]
  26. */
  27. public static function getMap(): array
  28. {
  29. return [
  30. self::JS => 'H5',
  31. self::APP => 'app',
  32. self::NATIVE => '扫码',
  33. self::POS => '刷卡',
  34. self::M_WEB => '手机',
  35. self::MINI_PROGRAM => '小程序',
  36. ];
  37. }
  38. /**
  39. * 根据环境获取微信交易类型
  40. * @param $platform
  41. * @return mixed|string
  42. */
  43. public static function getTypeByPlatform($platform)
  44. {
  45. $arr = [
  46. User::PLATFORM_MP_WX => self::MINI_PROGRAM,
  47. User::PLATFORM_WECHAT => self::JS,
  48. User::PLATFORM_APP => self::APP,
  49. User::PLATFORM_H5 => self::M_WEB,
  50. ];
  51. return $arr[$platform] ?? '';
  52. }
  53. /**
  54. * 获取pem文件对应的配置内容
  55. * @Author: lun
  56. * @DateTime: 2021/10/19 0019 15:24
  57. * @Copyright: copyright (c) 2021 广东七件事集团
  58. * @param $key
  59. * @return array|string[]
  60. */
  61. public static function getPemFileName($key)
  62. {
  63. $arr = [
  64. self::CERT_PEM => [
  65. 'file' => 'apiclient_cert.pem',
  66. 'key' => 'wechat_cert_pem_file',
  67. ],
  68. self::KEY_PEM => [
  69. 'file' => 'apiclient_key.pem',
  70. 'key' => 'wechat_key_pem_file',
  71. ],
  72. ];
  73. return $arr[$key] ?? [];
  74. }
  75. /**
  76. * pem数组
  77. * @Author: lun
  78. * @DateTime: 2021/10/19 0019 15:25
  79. * @Copyright: copyright (c) 2021 广东七件事集团
  80. * @return array|string[]
  81. */
  82. public static function pemMap():array
  83. {
  84. return [
  85. self::CERT_PEM,
  86. self::KEY_PEM,
  87. ];
  88. }
  89. }