Yii2 sms网关 - 短信没有去

时间:2017-10-27 12:39:09

标签: curl sms sms-gateway

我有短信网关,用于在Yii2项目上发送短信。 当我调用存储短信代码的特定动作时,短信不会发送。 如果我打印sms网址并在浏览器中复制粘贴并点击它..它的去。 我不知道Yii2中的错误

以下是动作代码和卷曲代码在模型中

  public function actionMessage() {  
        /*sms code start*/ 
                $model = new BillPersonal();

                $mobile = "9703843454";
                $authKey = "XXXXXXXXXXXXXX";
                $senderId = "XXXXXX";
                $textMessage = "Test Messsage"; 

                $url = sprintf("http://www.smsgatewayhub.com/api/mt/SendSMS?APIKey=".$authKey."&senderid=".$senderId."&channel=2&DCS=0&flashsms=0&number=91".$mobile."&text=".$textMessage."&route=11"); 

                $curl_handle = curl_init();
                      curl_setopt($curl_handle, CURLOPT_URL, $url);
                      curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 5);
                      curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
                      curl_setopt($curl_handle, CURLOPT_USERAGENT, 'CHMS');
                      $query = curl_exec($curl_handle);
       }

1 个答案:

答案 0 :(得分:0)

我终于得到了解决方案..问题在于CURL设置。希望这有助于某人。

public function actionSms(){

               $apikey = "XXXXXXXXXXXXXXXXXXX";
               $apisender = "XXXXXXXXX";
               $msg ="YOUR MESSAGE";
               $num = "91XXXXXXXXXXXX";     

               $ms = rawurlencode($msg);   

            $url = 'https://www.smsgatewayhub.com/api/mt/SendSMS?APIKey='.$apikey.'&senderid='.$apisender.'&channel=2&DCS=0&flashsms=0&number='.$num.'&text='.$ms.'&route=1';

             //echo $url;
             $ch=curl_init($url);
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
             curl_setopt($ch,CURLOPT_POST,1);
             curl_setopt($ch,CURLOPT_POSTFIELDS,"");
             curl_setopt($ch, CURLOPT_RETURNTRANSFER,2);
             $data = curl_exec($ch);
             echo '<br/><br/>';
             print($data); /* result of API call*/
      }