php 短信API如何解决这个我想改变短信API提供商

qnyhuwrf  于 2023-05-21  发布在  PHP
关注(0)|答案(1)|浏览(87)
<?php
    
    function textTicket($mobile_number, $ticket){

        $str = substr($mobile_number, 1);
        $mobileNumber = (string)"63" . $str;
        $userTicket = (string)$ticket;
        $messageId = (string)mt_rand(1000000000, 9999999999);
        $messageToUser = "Thank you for using CSC-QMSMS: Your Filing Ticket Number: ".$userTicket." will be called soon. You're in the 5th person in the line. ";
        $arr_post_body = array(
            "message_type" => "SEND",
            "mobile_number" => $mobileNumber,
            "shortcode" => "292905464",
            "message_id" => $messageId,
            "message" => urlencode($messageToUser),
            "client_id" => "757867ea2047771fea041a40684334dccee81cd07c81f006e556298e9eb42b00",
            "secret_key" => "4f16aea773532b9cb9bf8330b8b34c8248b9b482255213c2504575faab8e4bcb"
        );

        $query_string = "";

        foreach($arr_post_body as $key => $frow)
        {
            $query_string .= '&'.$key.'='.$frow;
        }

        $URL = "https://post.chikka.com/smsapi/request";

        $curl_handler = curl_init();
        curl_setopt($curl_handler, CURLOPT_URL, $URL);
        curl_setopt($curl_handler, CURLOPT_POST, count($arr_post_body));
        curl_setopt($curl_handler, CURLOPT_POSTFIELDS, $query_string);
        curl_setopt($curl_handler, CURLOPT_RETURNTRANSFER, TRUE);
        $response = curl_exec($curl_handler);
        curl_close($curl_handler);
        $txtResponse = json_encode($response);
        $pos = strpos($txtResponse, "ACCEPTED");
        return $pos;
        
    }
?>

   $query_string = "";

        foreach($arr_post_body as $key => $frow)
        {
            $query_string .= '&'.$key.'='.$frow;
        }

        $URL = "https://post.chikka.com/smsapi/request";

        $curl_handler = curl_init();
        curl_setopt($curl_handler, CURLOPT_URL, $URL);
        curl_setopt($curl_handler, CURLOPT_POST, count($arr_post_body));
        curl_setopt($curl_handler, CURLOPT_POSTFIELDS, $query_string);
        curl_setopt($curl_handler, CURLOPT_RETURNTRANSFER, TRUE);
        $response = curl_exec($curl_handler);
        curl_close($curl_handler);
        $txtResponse = json_encode($response);
        $pos = strpos($txtResponse, "ACCEPTED");
        return $pos;
7eumitmz

7eumitmz1#

首先,您需要找到另一个SMS API提供商,并找出通过该API发送消息所需的内容。您很可能需要注册并接收某种凭据或令牌。
阅读新API的文档。找出需要发送哪些参数。
然后:
1.将$URL的值替换为新API的URL
1.删除$arr_post_body中的所有键,并添加新API所需的键。

相关问题