DefaultConfig.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace crmeb\services\wechat;
  12. use think\facade\Config;
  13. /**
  14. * 默认配置
  15. * Class DefaultConfig
  16. * @package crmeb\services\wechat
  17. */
  18. class DefaultConfig
  19. {
  20. //小程序appid
  21. const MINI_APPID = 'mini.appid';
  22. //公众号appid
  23. const OFFICIAL_APPID = 'official.appid';
  24. //开放平台appid
  25. const APP_APPID = 'app.appid';
  26. //开放平台网页端appid
  27. const WEB_APPID = 'web.appid';
  28. //企业微信id
  29. const WORK_CORP_ID = 'work.corp_id';
  30. //商户id
  31. const PAY_MCHID = 'pay.mchid';
  32. //系统配置域名地址,携带,格式:http://www.a.com
  33. const COMMENT_URL = 'comment.url';
  34. /**
  35. *
  36. */
  37. const WECHAT_CONFIG = [
  38. //请求响应日志
  39. 'logger' => true,
  40. //公用
  41. 'comment' => [
  42. 'url' => 'site_url',
  43. ],
  44. //小程序配置
  45. 'mini' => [
  46. 'appid' => 'routine_appId',
  47. 'secret' => 'routine_appsecret',
  48. 'notifyUrl' => '/api/pay/notify/routine',//必须携带斜杠开头
  49. ],
  50. //公众号配置
  51. 'official' => [
  52. 'appid' => 'wechat_appid',
  53. 'secret' => 'wechat_appsecret',
  54. 'token' => 'wechat_token',
  55. 'key' => 'wechat_encodingaeskey',
  56. 'encode' => 'wechat_encode',
  57. ],
  58. //开放平台APP
  59. 'app' => [
  60. 'appid' => 'wechat_app_appid',
  61. 'secret' => 'wechat_app_appsecret',
  62. 'token' => 'wechat_openapp_app_token',
  63. 'key' => 'wechat_openapp_app_aes_key',
  64. 'notifyUrl' => '/api/pay/notify/app',//必须携带斜杠开头
  65. ],
  66. //开放平台网页应用
  67. 'web' => [
  68. 'appid' => 'wechat_open_app_id',
  69. 'secret' => 'wechat_open_app_secret',
  70. 'token' => 'wechat_open_app_token',
  71. 'key' => 'wechat_open_app_aes_key',
  72. ],
  73. //企业微信
  74. 'work' => [
  75. 'corp_id' => 'wechat_work_corpid',
  76. 'token' => 'wechat_work_token',
  77. 'key' => 'wechat_work_aes_key',
  78. ],
  79. //支付
  80. 'pay' => [
  81. 'mchid' => 'pay_weixin_mchid',//商户号
  82. 'key' => 'pay_weixin_key',//支付key
  83. 'client_cert' => 'pay_weixin_client_cert',//证书
  84. 'client_key' => 'pay_weixin_client_key',//证书
  85. 'notifyUrl' => '/api/pay/notify/wechat',//支付回调,必须携带斜杠开头
  86. 'refundUrl' => '/api/pay/refund/wechat',//退款回到,必须携带斜杠开头
  87. ]
  88. ];
  89. /**
  90. * 获取配置,如果配置为数组则使用value的值,如果没有值返回key
  91. * @param string $key
  92. * @return array|mixed|string[]|null
  93. */
  94. public static function value(string $key)
  95. {
  96. $config = [];
  97. if (Config::has('wechat')) {
  98. $config = Config::get('wechat', []);
  99. }
  100. $config = array_merge(self::WECHAT_CONFIG, $config);
  101. $key = explode('.', $key);
  102. $value = null;
  103. foreach ($key as $k) {
  104. if ($value) {
  105. $value = $value[$k] ?? null;
  106. } else {
  107. $value = $config[$k] ?? null;
  108. }
  109. }
  110. if (is_array($value)) {
  111. $value = !empty($value['value']) ? $value['value'] : $value['key'];
  112. }
  113. return $value;
  114. }
  115. }