WechatCommand.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. /**
  3. * @filename WechatCommand.php
  4. * @date 2020/6/6
  5. * @project https://github.com/yanwenwu/catch-admin
  6. * @document http://doc.catchadmin.com
  7. * @author JaguarJack <njphper@gmail.com>
  8. * @copyright By CatchAdmin
  9. * @license https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt
  10. */
  11. namespace catchAdmin\wechat\command;
  12. use think\console\Command;
  13. use think\console\Input;
  14. use think\console\Output;
  15. class WechatCommand extends Command
  16. {
  17. protected function configure()
  18. {
  19. $this->setName('publish:wechat')
  20. ->setDescription('publish wechat config');
  21. }
  22. protected function execute(Input $input, Output $output)
  23. {
  24. file_put_contents(config_path() . 'wechat.php', $this->config());
  25. $this->env();
  26. $output->warning('wechat publish successfully');
  27. }
  28. protected function config()
  29. {
  30. return <<<CONFIG
  31. <?php
  32. return [
  33. /**
  34. * 公众号配置
  35. *
  36. */
  37. 'official_account' => [
  38. /**
  39. * 账号基本信息,请从微信公众平台/开放平台获取
  40. */
  41. 'app_id' => env('wechat.official_app_id'), // AppID
  42. 'secret' => env('wechat.official_secret'), // AppSecret
  43. 'token' => env('wechat.official_token'), // Token
  44. 'aes_key' => env('wechat.official_aes_key'), // EncodingAESKey,兼容与安全模式下请一定要填写!!!
  45. 'response_type' => 'array',
  46. /**
  47. * OAuth 配置
  48. *
  49. * scopes:公众平台(snsapi_userinfo / snsapi_base),开放平台:snsapi_login
  50. * callback:OAuth授权完成后的回调页地址
  51. */
  52. 'oauth' => [
  53. 'scopes' => ['snsapi_userinfo'],
  54. 'callback' => '/examples/oauth_callback.php',
  55. ],
  56. ],
  57. /**
  58. * 小程序
  59. */
  60. 'mini_program' => [
  61. // 更多配置查看 https://www.easywechat.com/docs/master/mini-program/index
  62. ],
  63. /**
  64. * 开放平台
  65. */
  66. 'open_platform' => [
  67. // 更多配置查看 https://www.easywechat.com/docs/master/open-platform/index
  68. ],
  69. /**
  70. * 企业微信
  71. */
  72. 'work' => [
  73. // 更多配置查看 https://www.easywechat.com/docs/master/wework/index
  74. ],
  75. /**
  76. * 企业微信开放平台
  77. */
  78. 'open_work' => [
  79. // 配置 https://www.easywechat.com/docs/master/open-work/index
  80. ],
  81. /**
  82. * 小微商户
  83. */
  84. 'micro_merchant' => [
  85. // 配置 https://www.easywechat.com/docs/master/micro-merchant/index
  86. ],
  87. /**
  88. * wechat pay
  89. */
  90. 'payment' => [
  91. 'app_id' => 'xxxx',
  92. 'mch_id' => 'your-mch-id',
  93. 'key' => 'key-for-signature', // API 密钥
  94. // 如需使用敏感接口(如退款、发送红包等)需要配置 API 证书路径(登录商户平台下载 API 证书)
  95. 'cert_path' => 'path/to/your/cert.pem', // XXX: 绝对路径!!!!
  96. 'key_path' => 'path/to/your/key', // XXX: 绝对路径!!!!
  97. 'notify_url' => '默认的订单回调地址', // 你也可以在下单时单独设置来想覆盖它
  98. ],
  99. // 更多配置请查看 https://www.easywechat.com/docs
  100. ];
  101. CONFIG;
  102. }
  103. protected function env()
  104. {
  105. $filename = file_exists(root_path() . '.env') ? '.env' : '.example.env';
  106. $env = \parse_ini_file(root_path() . $filename, true);
  107. $env['WECHAT'] = $this->envConfig();
  108. $dotEnv = '';
  109. foreach ($env as $key => $e) {
  110. if (is_string($e)) {
  111. $dotEnv .= sprintf('%s = %s', $key, $e === '1' ? 'true' : ($e === '' ? 'false' : $e)) . PHP_EOL;
  112. $dotEnv .= PHP_EOL;
  113. } else {
  114. $dotEnv .= sprintf('[%s]', $key) . PHP_EOL;
  115. foreach ($e as $k => $v) {
  116. $dotEnv .= sprintf('%s = %s', $k, $v === '1' ? 'true' : ($v === '' ? 'false' : $v)) . PHP_EOL;
  117. }
  118. $dotEnv .= PHP_EOL;
  119. }
  120. }
  121. file_put_contents(root_path() . '.env', $dotEnv);
  122. }
  123. protected function envConfig()
  124. {
  125. return [
  126. "official_app_id" => null,
  127. "official_secret" => null,
  128. "official_token" => null,
  129. "official_aes_key" => null,
  130. ];
  131. }
  132. }