CI_Wechat.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. /**
  4. * 微信公众平台PHP-SDK, Codeigniter实例
  5. * @author nigelvon@gmail.com
  6. * @link https://github.com/dodgepudding/wechat-php-sdk
  7. * usage:
  8. * $this->load->library('CI_Wechat');
  9. * $this->ci_wechat->valid();
  10. * ...
  11. *
  12. */
  13. require_once(dirname(__FILE__) . '/wechat-php-sdk/wechat.class.php');
  14. class CI_Wechat extends Wechat {
  15. protected $_CI;
  16. public function __construct() {
  17. $this->_CI =& get_instance();
  18. $this->_CI->config->load('wechat');
  19. $options = $this->_CI->config->item('wechat');
  20. $this->_CI->load->driver('cache', array('adapter' => 'apc', 'backup' => 'file'));
  21. parent::__construct($options);
  22. }
  23. /**
  24. * 重载设置缓存
  25. * @param string $cachename
  26. * @param mixed $value
  27. * @param int $expired
  28. * @return boolean
  29. */
  30. protected function setCache($cachename, $value, $expired) {
  31. return $this->_CI->cache->save($cachename, $value, $expired);
  32. }
  33. /**
  34. * 重载获取缓存
  35. * @param string $cachename
  36. * @return mixed
  37. */
  38. protected function getCache($cachename) {
  39. return $this->_CI->cache->get($cachename);
  40. }
  41. /**
  42. * 重载清除缓存
  43. * @param string $cachename
  44. * @return boolean
  45. */
  46. protected function removeCache($cachename) {
  47. return $this->_CI->cache->delete($cachename);
  48. }
  49. }
  50. /* End of file CI_Wechat.php */
  51. /* Location: ./application/libraries/CI_Wechat.php */