WechatParam.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace App\Wechat;
  3. class WechatParam
  4. {
  5. private $param;
  6. private static $_instance = null;
  7. private function __construct($param)
  8. {
  9. $this->param = $param;
  10. }
  11. /**
  12. * 单例模式的实例
  13. */
  14. public static function instance()
  15. {
  16. if (self::$_instance == null) {
  17. self::$_instance = new self(
  18. [
  19. 'appid' => 'wxa3dec10df68cd87d',
  20. 'appsecret' => '17bff4aa5bf1ffa2c15aeb5eea0e2b32',
  21. ]);
  22. }
  23. return self::$_instance;
  24. }
  25. /**
  26. * set方法
  27. */
  28. public function set($name, $value)
  29. {
  30. $this->param[$name] = $value;
  31. }
  32. /**
  33. * get方法
  34. */
  35. public function get($name)
  36. {
  37. if (empty($this->param[$name])) {
  38. return null;
  39. }
  40. return $this->param[$name];
  41. }
  42. /**
  43. * 获取所有参数
  44. */
  45. public function getParam()
  46. {
  47. return $this->param;
  48. }
  49. /**
  50. * 合并参数
  51. */
  52. public function merge($arr)
  53. {
  54. $this->param = array_merge($this->param,$arr);
  55. }
  56. }