123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace app\common\api;
- class ChuanglanSmsApi {
-
- const API_SEND_URL = 'http://smssh1.253.com/msg/send/json';
- const API_ACCOUNT = 'N7450217';
- const API_PASSWORD = 'wS5gE4GQszb46f';
- private $verification;
-
- public function sendSMS($mobile, $msg, $needstatus = 'true') {
-
- $postArr = array(
- 'account' => self::API_ACCOUNT,
- 'password' => self::API_PASSWORD,
- 'msg' => urlencode($msg),
- 'phone' => $mobile,
- 'report' => $needstatus,
- );
- $deny_list = ["jjrcw.test", "jjrcw.test:8080","report.com","report.jinjianghc.com"];
- if (in_array($_SERVER["HTTP_HOST"], $deny_list))
- return false;
- $result = $this->curlPost(self::API_SEND_URL, $postArr);
- return $result;
- }
-
- private function curlPost($url, $postFields) {
- $postFields = json_encode($postFields);
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- 'Content-Type: application/json; charset=utf-8'
- )
- );
- curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
- curl_setopt($ch, CURLOPT_TIMEOUT, 60);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
- $ret = curl_exec($ch);
- if (false == $ret) {
- $result = curl_error($ch);
- } else {
- $rsp = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- if (200 != $rsp) {
- $result = "请求状态 " . $rsp . " " . curl_error($ch);
- } else {
- $result = $ret;
- }
- }
- curl_close($ch);
- return $result;
- }
- }
|