search
HomeBackend DevelopmentPHP Tutorial253 SMS interface PHP direct call

253 SMS interface PHP direct call

Apr 26, 2018 am 11:18 AM
phptransfer

The content introduced in this article is about the direct call of 253 SMS interface PHP, which has certain reference value. Now I share it with everyone. Friends in need can refer to it

<?php
//namespace Vendor\Sms;
class Sms{  
   
    
      private  $API_SEND_URL=&#39;http://smssh1.253.com/msg/send/&#39;;
      private  $API_ACCOUNT=&#39;C0543&#39;;
      private  $API_PASSWORD=&#39;ItFBqxd2ed&#39;;
     
     
     public function __construct(){    
    }  
     function sendSMS($mobile,$msg,$need_status = 1){

        //发送短信的接口参数
        $post_data = array (
            &#39;un&#39; => $this->API_ACCOUNT,
            &#39;pw&#39; =>  $this->API_PASSWORD,
            &#39;msg&#39; => $msg,
            &#39;phone&#39; => $mobile,
            &#39;rd&#39; => $need_status
        );

        $result = $this->curl_post($this->API_SEND_URL,http_build_query($post_data));

        $result=preg_split("/[,\r\n]/",$result);
        return $result;
    }

     function send_state($state){
        //返回的状态码
        $statusStr = array(
            &#39;0&#39; =>&#39;发送成功&#39;,
            &#39;101&#39;=>&#39;无此用户&#39;,
            &#39;102&#39;=>&#39;密码错&#39;,
            &#39;103&#39;=>&#39;提交过快&#39;,
            &#39;104&#39;=>&#39;系统忙&#39;,
            &#39;105&#39;=>&#39;敏感短信&#39;,
            &#39;106&#39;=>&#39;消息长度错&#39;,
            &#39;107&#39;=>&#39;错误的手机号码&#39;,
            &#39;108&#39;=>&#39;手机号码个数错&#39;,
            &#39;109&#39;=>&#39;无发送额度&#39;,
            &#39;110&#39;=>&#39;不在发送时间内&#39;,
            &#39;111&#39;=>&#39;超出该账户当月发送额度限制&#39;,
            &#39;112&#39;=>&#39;无此产品&#39;,
            &#39;113&#39;=>&#39;extno格式错&#39;,
            &#39;115&#39;=>&#39;自动审核驳回&#39;,
            &#39;116&#39;=>&#39;签名不合法,未带签名&#39;,
            &#39;117&#39;=>&#39;IP地址认证错&#39;,
            &#39;118&#39;=>&#39;用户没有相应的发送权限&#39;,
            &#39;119&#39;=>&#39;用户已过期&#39;,
            &#39;120&#39;=>&#39;内容不是白名单&#39;,
            &#39;121&#39;=>&#39;必填参数。是否需要状态报告,取值true或false&#39;,
            &#39;122&#39;=>&#39;5分钟内相同账号提交相同消息内容过多&#39;,
            &#39;123&#39;=>&#39;发送类型错误(账号发送短信接口权限)&#39;,
            &#39;124&#39;=>&#39;白模板匹配错误&#39;,
            &#39;125&#39;=>&#39;驳回模板匹配错误&#39;,
            &#39;128&#39;=>&#39;内容解码失败&#39;
        );
        return $statusStr[$state];
    }

    function curl_post($url, $post_data) {
        $ch = curl_init();
        $timeout = 300;
        curl_setopt($ch, CURLOPT_URL, $url);
        //curl_setopt($ch, CURLOPT_REFERER, "http://api.dushiyangguan.com/"); 
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER[&#39;HTTP_USER_AGENT&#39;]);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
          curl_setopt( $ch, CURLOPT_TIMEOUT,$timeout); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        // curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        $res = curl_exec($ch);
        if (curl_errno($ch)) {
            echo &#39;Curl error: &#39; . curl_error($ch);
        }
        curl_close($ch);
        return $res;
    }
    
}

Related recommendations:

PHP calls the program class of Google Translate

PHP calls the class in other files

Use PHP to call the so library file Code

The above is the detailed content of 253 SMS interface PHP direct call. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

How to make PHP applications fasterHow to make PHP applications fasterMay 12, 2025 am 12:12 AM

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

PHP Performance Optimization Checklist: Improve Speed NowPHP Performance Optimization Checklist: Improve Speed NowMay 12, 2025 am 12:07 AM

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

PHP Dependency Injection: Improve Code TestabilityPHP Dependency Injection: Improve Code TestabilityMay 12, 2025 am 12:03 AM

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

PHP Performance Optimization: Database Query OptimizationPHP Performance Optimization: Database Query OptimizationMay 12, 2025 am 12:02 AM

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function