TplOperator.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: bingone
  5. * Date: 16/1/20
  6. * Time: 上午10:37
  7. */
  8. require_once 'HttpUtil.php';
  9. class TplOperator
  10. {
  11. public $apikey;
  12. public $api_secret;
  13. public $yunpian_config;
  14. public function __construct($apikey = null, $api_secret = null)
  15. {
  16. $this->yunpian_config = $GLOBALS['YUNPIAN_CONFIG'];
  17. if ($api_secret == null)
  18. $this->api_secret = $this->yunpian_config['API_SECRET'];
  19. else
  20. $this->api_secret = $apikey;
  21. if ($apikey == null)
  22. $this->apikey = $this->yunpian_config['APIKEY'];
  23. else
  24. $this->apikey = $api_secret;
  25. }
  26. public function encrypt(&$data)
  27. {
  28. }
  29. public function get_default($data = array())
  30. {
  31. $data['apikey'] = $this->apikey;
  32. return HttpUtil::PostCURL($this->yunpian_config['URI_GET_DEFAULT_TEMPLATE'], $data);
  33. }
  34. public function get($data = array())
  35. {
  36. $data['apikey'] = $this->apikey;
  37. return HttpUtil::PostCURL($this->yunpian_config['URI_GET_TEMPLATE'], $data);
  38. }
  39. public function add($data = array())
  40. {
  41. if (!array_key_exists('tpl_id',$data))
  42. return new Result(null,$data,null,$error = 'tpl_id 为空');
  43. if (!array_key_exists('tpl_content',$data))
  44. return new Result(null,$data,null,$error = 'tpl_content 为空');
  45. $data['apikey'] = $this->apikey;
  46. return HttpUtil::PostCURL($this->yunpian_config['URI_ADD_TEMPLATE'], $data);
  47. }
  48. public function upd($data = array())
  49. {
  50. if (!array_key_exists('tpl_id',$data))
  51. return new Result(null,$data,null,$error = 'tpl_id 为空');
  52. if (!array_key_exists('tpl_content',$data))
  53. return new Result(null,$data,null,$error = 'tpl_content 为空');
  54. $data['apikey'] = $this->apikey;
  55. return HttpUtil::PostCURL($this->yunpian_config['URI_UPD_TEMPLATE'], $data);
  56. }
  57. public function del($data = array())
  58. {
  59. if (!array_key_exists('tpl_id',$data))
  60. return new Result(null,$data,null,$error = 'tpl_id 为空');
  61. $data['apikey'] = $this->apikey;
  62. return HttpUtil::PostCURL($this->yunpian_config['URI_DEL_TEMPLATE'], $data);
  63. }
  64. }