<fieldset id="eo0ma"></fieldset>
  • php如何對接短信接口方法

    2021-11-25 10:33:16 admin

    PHP短信接口是在開發商城網站、APP、小程序等經常會用到的,比如:用戶進行注冊、登錄以及發送通知類信息。本php短信接口開發實例是基于創信短信接口api而寫,從而實現短信發送功能。

    PHP短信接口demo

    <?php

    function Post($data, $target) {

    $url_info = parse_url($target);

    $httpheader = "POST " . $url_info['path'] . " HTTP/1.0\r\n";

    $httpheader .= "Host:" . $url_info['host'] . "\r\n";

    $httpheader .= "Content-Type:application/x-www-form-urlencoded\r\n";

    $httpheader .= "Content-Length:" . strlen($data) . "\r\n";

    $httpheader .= "Connection:close\r\n\r\n";

    //$httpheader .= "Connection:Keep-Alive\r\n\r\n";

    $httpheader .= $data;

    $fd = fsockopen($url_info['host'], 80);

    fwrite($fd, $httpheader);

    $gets = "";

    while(!feof($fd)) {

        $gets .= fread($fd, 128);

    }

    fclose($fd);

    return $gets;

    }

    ?>

    <?php

    include_once('sms.php');

    $target = "http://dc.28inter.com/sms.aspx";

    //替換成自己的測試賬號,參數順序和wenservice對應

    $post_data = "action=send&rt=json&userid=用戶ID&account=賬號&password=密碼&mobile=手機號&content=".rawurlencode("程序調試請測試平時需要發送的正式內容");

    //$binarydata = pack("A", $post_data);

    $gets = Post($post_data, $target);

    $start=strpos($gets,"<?xml");

    $data=substr($gets,$start);

    $xml=simplexml_load_string($data);

    var_dump(json_decode(json_encode($xml),TRUE));

    //請自己解析$gets字符串并實現自己的邏輯

    //0表示成功,其它的參考文檔

    ?>

    微信

    公眾號