SmsOperator.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: bingone
  5. * Date: 16/1/19
  6. * Time: 下午5:42
  7. */
  8. require_once('HttpUtil.php');
  9. class SmsOperator
  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 single_send($data = array())
  30. {
  31. if (!array_key_exists('mobile', $data))
  32. return new Result(null, $data, null, 'mobile 为空');
  33. if (!array_key_exists('text', $data))
  34. return new Result(null, $data, null, 'text 为空');
  35. $data['apikey'] = $this->apikey;
  36. return HttpUtil::PostCURL($this->yunpian_config['URI_SEND_SINGLE_SMS'], $data);
  37. }
  38. public function batch_send($data = array())
  39. {
  40. if (!array_key_exists('mobile', $data))
  41. return new Result(null, $data, null, $error = 'mobile 为空');
  42. if (!array_key_exists('text', $data))
  43. return new Result(null, $data, null, $error = 'text 为空');
  44. $data['apikey'] = $this->apikey;
  45. return HttpUtil::PostCURL($this->yunpian_config['URI_SEND_BATCH_SMS'], $data);
  46. }
  47. public function multi_send($data = array())
  48. {
  49. if (!array_key_exists('mobile', $data))
  50. return new Result(null, $data, null, $error = 'mobile 为空');
  51. if (!array_key_exists('text', $data))
  52. return new Result(null, $data, null, $error = 'text 为空');
  53. if (count(explode(',', $data['mobile'])) != count(explode(',', $data['text'])))
  54. return new Result(null, $data, null, $error = 'mobile 与 text 个数不匹配');
  55. $data['apikey'] = $this->apikey;
  56. $text_array = explode(',', $data['text']);
  57. $data['text'] = '';
  58. for ($index = 0; $index < count($text_array); $index++) {
  59. $data['text'] .= urlencode($text_array[$index]) . ',';
  60. }
  61. $data['text'] = substr($data['text'],0,-1);
  62. return HttpUtil::PostCURL($this->yunpian_config['URI_SEND_MULTI_SMS'], $data);
  63. }
  64. public function tpl_send($data = array())
  65. {
  66. if (!array_key_exists('mobile', $data))
  67. return new Result(null, $data, null, 'mobile 为空');
  68. if (!array_key_exists('tpl_id', $data))
  69. return new Result(null, $data, null, 'tpl_id 为空');
  70. if (!array_key_exists('tpl_value', $data))
  71. return new Result(null, $data, null, 'tpl_value 为空');
  72. $data['apikey'] = $this->apikey;
  73. return HttpUtil::PostCURL($this->yunpian_config['URI_SEND_TPL_SMS'], $data);
  74. }
  75. }