TPWechat.class.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace Org\Util;
  3. use Common\Cache\RedisCache;
  4. /**
  5. * 微信公众平台PHP-SDK, ThinkPHP实例
  6. * @author dodgepudding@gmail.com
  7. * @link https://github.com/dodgepudding/wechat-php-sdk
  8. * @version 1.2
  9. * usage:
  10. * $options = array(
  11. * 'token'=>'tokenaccesskey', //填写你设定的key
  12. * 'encodingaeskey'=>'encodingaeskey', //填写加密用的EncodingAESKey
  13. * 'appid'=>'wxdk1234567890', //填写高级调用功能的app id
  14. * 'appsecret'=>'xxxxxxxxxxxxxxxxxxx' //填写高级调用功能的密钥
  15. * );
  16. * $weObj = new TPWechat($options);
  17. * $weObj->valid();
  18. * ...
  19. *
  20. */
  21. class TPWechat extends \Org\Util\Wechat
  22. {
  23. /**
  24. * log overwrite
  25. * @see Wechat::log()
  26. */
  27. public function log($log){
  28. if ($this->debug) {
  29. if (function_exists($this->logcallback)) {
  30. if (is_array($log)) $log = print_r($log,true);
  31. return call_user_func($this->logcallback,$log,'INFO');
  32. }elseif (class_exists('Log')) {
  33. Log::write('wechat:'.$log, Log::DEBUG);
  34. return true;
  35. }
  36. }
  37. return false;
  38. }
  39. /**
  40. * 重载设置缓存
  41. * @param string $cachename
  42. * @param mixed $value
  43. * @param int $expired
  44. * @return boolean
  45. */
  46. public function setCache($cachename,$value,$expired){
  47. $redis_cache = new RedisCache();
  48. $redis_cache->set($cachename,$value,$expired);
  49. }
  50. /**
  51. * 重载获取缓存
  52. * @param string $cachename
  53. * @return mixed
  54. */
  55. public function getCache($cachename){
  56. $redis_cache = new RedisCache();
  57. return $redis_cache->get($cachename);
  58. }
  59. /**
  60. * 重载清除缓存
  61. * @param string $cachename
  62. * @return boolean
  63. */
  64. public function removeCache($cachename){
  65. $redis_cache = new RedisCache();
  66. return $redis_cache->rm($cachename);
  67. }
  68. }