123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- /**
- * 阿里云短信验证码发送类
- * @author Administrator
- *
- */
-
- class TruiSMS {
-
- // 保存错误信息
-
- public $error;
-
- // Access Key ID
-
- private $accesskey = '';
-
- // Access Access Key Secret
-
- private $secret = '';
-
- // 签名
-
- private $signName = '猎豆优选';
-
- // 模版ID
-
- private $templateId = '30233';
-
- public function __construct($cofig = array()) {
-
- $cofig = array (
-
- 'accesskey' => 'octOap8wLMsXIS38',
-
- 'secret' => 'rqjJg3Hg4jiGsWH4C5wCVzegZUKxHgRU',
-
- 'signName' => '【猎豆优选】',
-
- 'templateId' => 'SMS_151992296'
-
- );
-
- // 配置参数
-
- $this->accesskey = $cofig ['accesskey'];
-
- $this->secret = $cofig ['secret'];
-
- $this->signName = $cofig ['signName'];
-
- $this->templateId = $cofig ['templateId'];
-
- }
-
- /**
- * @param unknown $mobile
- * @param unknown $verify_code
- *
- */
-
- public function send_verify($mobile, $verify_code, $minute) {
-
- $params = array ( //此处作了修改
-
- 'accesskey' => $this->accesskey,
- 'secret' => $this->secret,
- 'sign' => $this->signName,
- 'templateId' => $this->templateId,
-
- 'mobile' => $mobile,
-
- 'content' => $verify_code.'##'.$minute
-
- );
- $url = "http://api.1cloudsp.com/api/v2/single_send";
- $data = http_build_query ( $params );
-
- $ch = curl_init ();
-
- curl_setopt ( $ch, CURLOPT_URL, $url );
- curl_setopt ($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/x-www-form-urlencoded', 'charset=utf-8'));
-
- curl_setopt($ch, CURLOPT_HEADER, 0);//
-
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
- curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
-
- $result = curl_exec ( $ch );
-
- curl_close ( $ch );
-
- $result = json_decode ( $result, true );
-
- if (isset ( $result ['Code'] )) {
-
- $this->error = $this->getErrorMessage ( $result ['Code'] );
-
- return false;
-
- }
-
- return true;
-
- }
-
-
- }
|