Няма описание

TruiSMS.php 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /**
  3. * 阿里云短信验证码发送类
  4. * @author Administrator
  5. *
  6. */
  7. class TruiSMS {
  8. // 保存错误信息
  9. public $error;
  10. // Access Key ID
  11. private $accesskey = '';
  12. // Access Access Key Secret
  13. private $secret = '';
  14. // 签名
  15. private $signName = '猎豆优选';
  16. // 模版ID
  17. private $templateId = '30233';
  18. public function __construct($cofig = array()) {
  19. $cofig = array (
  20. 'accesskey' => 'octOap8wLMsXIS38',
  21. 'secret' => 'rqjJg3Hg4jiGsWH4C5wCVzegZUKxHgRU',
  22. 'signName' => '【猎豆优选】',
  23. 'templateId' => 'SMS_151992296'
  24. );
  25. // 配置参数
  26. $this->accesskey = $cofig ['accesskey'];
  27. $this->secret = $cofig ['secret'];
  28. $this->signName = $cofig ['signName'];
  29. $this->templateId = $cofig ['templateId'];
  30. }
  31. /**
  32. * @param unknown $mobile
  33. * @param unknown $verify_code
  34. *
  35. */
  36. public function send_verify($mobile, $verify_code, $minute) {
  37. $params = array ( //此处作了修改
  38. 'accesskey' => $this->accesskey,
  39. 'secret' => $this->secret,
  40. 'sign' => $this->signName,
  41. 'templateId' => $this->templateId,
  42. 'mobile' => $mobile,
  43. 'content' => $verify_code.'##'.$minute
  44. );
  45. $url = "http://api.1cloudsp.com/api/v2/single_send";
  46. $data = http_build_query ( $params );
  47. $ch = curl_init ();
  48. curl_setopt ( $ch, CURLOPT_URL, $url );
  49. curl_setopt ($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/x-www-form-urlencoded', 'charset=utf-8'));
  50. curl_setopt($ch, CURLOPT_HEADER, 0);//
  51. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
  52. curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
  53. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  54. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  55. $result = curl_exec ( $ch );
  56. curl_close ( $ch );
  57. $result = json_decode ( $result, true );
  58. if (isset ( $result ['Code'] )) {
  59. $this->error = $this->getErrorMessage ( $result ['Code'] );
  60. return false;
  61. }
  62. return true;
  63. }
  64. }