WxAccountConfig.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <?php
  2. namespace app\common\util\wechat;
  3. use app\common\model\Config;
  4. class WxAccountConfig
  5. {
  6. /**
  7. * 获取小程序接口配置参数
  8. * @return array
  9. * @throws \think\db\exception\DataNotFoundException
  10. * @throws \think\db\exception\DbException
  11. * @throws \think\db\exception\ModelNotFoundException
  12. */
  13. public static function getMiniProgramConfig()
  14. {
  15. $wxconfig = Config::getSettingModel("onlineRetailers");
  16. $config = [
  17. 'app_id' => $wxconfig["appId"],
  18. 'secret' => $wxconfig["appSecret"],
  19. 'response_type' => "array",
  20. 'log' => [
  21. 'default' => 'dev', // 默认使用的 channel,生产环境可以改为下面的 prod
  22. 'channels' => [
  23. // 测试环境
  24. 'dev' => [
  25. 'driver' => 'daily',
  26. 'path' => RUNTIME_PATH . '/easywechat_log/mini_program.log',
  27. 'level' => 'debug',
  28. ],
  29. // 生产环境
  30. 'prod' => [
  31. 'driver' => 'daily',
  32. 'path' => RUNTIME_PATH . '/easywechat_log/mini_program.log',
  33. 'level' => 'info',
  34. ],
  35. ],
  36. ],
  37. ];
  38. return $config;
  39. }
  40. /**
  41. * 获取公众号口配置参数
  42. * @return array
  43. * @throws \think\db\exception\DataNotFoundException
  44. * @throws \think\db\exception\DbException
  45. * @throws \think\db\exception\ModelNotFoundException
  46. */
  47. public static function getMpConfig()
  48. {
  49. $wxconfig = Config::getSettingModel("destination");
  50. $config = [
  51. 'app_id' => $wxconfig["appId"],
  52. 'secret' => $wxconfig["appSecret"],
  53. 'response_type' => "array",
  54. 'log' => [
  55. 'default' => 'dev', // 默认使用的 channel,生产环境可以改为下面的 prod
  56. 'channels' => [
  57. // 测试环境
  58. 'dev' => [
  59. 'driver' => 'daily',
  60. 'path' => RUNTIME_PATH . '/easywechat_log/mp.log',
  61. 'level' => 'debug',
  62. ],
  63. // 生产环境
  64. 'prod' => [
  65. 'driver' => 'daily',
  66. 'path' => RUNTIME_PATH . '/easywechat_log/mp.log',
  67. 'level' => 'info',
  68. ],
  69. ],
  70. ],
  71. ];
  72. return $config;
  73. }
  74. /**
  75. * 获取公众号口配置参数
  76. * @return array
  77. * @throws \think\db\exception\DataNotFoundException
  78. * @throws \think\db\exception\DbException
  79. * @throws \think\db\exception\ModelNotFoundException
  80. */
  81. public static function getWechatPayConfig()
  82. {
  83. $wxconfig = Config::getSettingModel("wechatPayment");
  84. $config = [
  85. 'app_id' => $wxconfig["appId"],
  86. 'mch_id' => $wxconfig["merchantNumber"],
  87. 'key' => $wxconfig["merchantKey"],
  88. 'cert_path' => $wxconfig['certificate'] . "apiclient_cert.pem", // XXX: 绝对路径!!!!
  89. 'key_path' => $wxconfig['certificate'] . "apiclient_key.pem", // XXX: 绝对路径!!!!
  90. 'response_type' => "array",
  91. 'log' => [
  92. 'default' => 'dev', // 默认使用的 channel,生产环境可以改为下面的 prod
  93. 'channels' => [
  94. // 测试环境
  95. 'dev' => [
  96. 'driver' => 'daily',
  97. 'path' => RUNTIME_PATH . '/easywechat_log/mp.log',
  98. 'level' => 'debug',
  99. ],
  100. // 生产环境
  101. 'prod' => [
  102. 'driver' => 'daily',
  103. 'path' => RUNTIME_PATH . '/easywechat_log/mp.log',
  104. 'level' => 'info',
  105. ],
  106. ],
  107. ],
  108. ];
  109. return $config;
  110. }
  111. public function getFullConfigExample()
  112. {
  113. return [
  114. /**
  115. * 账号基本信息,请从微信公众平台/开放平台获取
  116. */
  117. 'app_id' => 'your-app-id', // AppID
  118. 'secret' => 'your-app-secret', // AppSecret
  119. 'token' => 'your-token', // Token
  120. 'aes_key' => '', // EncodingAESKey,兼容与安全模式下请一定要填写!!!
  121. /**
  122. * 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名
  123. * 使用自定义类名时,构造函数将会接收一个 `EasyWeChat\Kernel\Http\Response` 实例
  124. */
  125. 'response_type' => 'array',
  126. /**
  127. * 日志配置
  128. *
  129. * level: 日志级别, 可选为:
  130. * debug/info/notice/warning/error/critical/alert/emergency
  131. * path:日志文件位置(绝对路径!!!),要求可写权限
  132. */
  133. 'log' => [
  134. 'default' => 'dev', // 默认使用的 channel,生产环境可以改为下面的 prod
  135. 'channels' => [
  136. // 测试环境
  137. 'dev' => [
  138. 'driver' => 'single',
  139. 'path' => '/tmp/easywechat.log',
  140. 'level' => 'debug',
  141. ],
  142. // 生产环境
  143. 'prod' => [
  144. 'driver' => 'daily',
  145. 'path' => '/tmp/easywechat.log',
  146. 'level' => 'info',
  147. ],
  148. ],
  149. ],
  150. /**
  151. * 接口请求相关配置,超时时间等,具体可用参数请参考:
  152. * http://docs.guzzlephp.org/en/stable/request-config.html
  153. *
  154. * - retries: 重试次数,默认 1,指定当 http 请求失败时重试的次数。
  155. * - retry_delay: 重试延迟间隔(单位:ms),默认 500
  156. * - log_template: 指定 HTTP 日志模板,请参考:https://github.com/guzzle/guzzle/blob/master/src/MessageFormatter.php
  157. */
  158. 'http' => [
  159. 'max_retries' => 1,
  160. 'retry_delay' => 500,
  161. 'timeout' => 5.0,
  162. // 'base_uri' => 'https://api.weixin.qq.com/', // 如果你在国外想要覆盖默认的 url 的时候才使用,根据不同的模块配置不同的 uri
  163. ],
  164. /**
  165. * OAuth 配置
  166. *
  167. * scopes:公众平台(snsapi_userinfo / snsapi_base),开放平台:snsapi_login
  168. * callback:OAuth授权完成后的回调页地址
  169. */
  170. 'oauth' => [
  171. 'scopes' => ['snsapi_userinfo'],
  172. 'callback' => '/examples/oauth_callback.php',
  173. ],
  174. ];
  175. }
  176. }