php短信接口开发(http协议)

来源:互联网 发布:怎么在淘宝直播 编辑:程序博客网 时间:2024/06/10 21:41

本文有动力思维乐信原创文章,技术杨工提供,欢迎交流合作,动力思维乐信短信接口官网:http://www.lx598.com/。

    一、接口说明

    1、提交方式与编码

    http请求都应以POST形式提交,编码为UTF-8

    2、请求地址

    请求地址(host)为:  http://www.lx198.com/sdk/

    不同的协议拥有不同的提交地址 方式是在以上地址后面增加相应的地址;

    二、主体协议

    1、发送短信

    发送普通短信调用此方法,可单个或批量发送。

    注意:①、短信内容格式为:短信内容【签名】,要使用中文’【‘。

    2、发送地址

    http://host/send

3、发送参数

  

接口测试实例,可以在浏览器中直接输入测试(建议使用POST方式)

http://www.lx198.com/sdk/send?accName=***&accPwd=***&aimcodes=***&content=内容【签名】&bizId=***&dataType=string

 

 

4、发送响应Json格式

   

示例:

{"balance":"12882680","chargCount":61,"deduction":"3660","failedNum":0,"replyCode":1,"replyMsg":"发送成功!","succeedNum":61}



5、发送相应xml格式

 

示例:

<?xml version="1.0" encoding="UTF-8"?><SendSmsReply>  <replyCode>1</replyCode>  <replyMsg>发送成功!</replyMsg>  <succeedNum>61</succeedNum>  <failedNum>0</failedNum>  <deduction>3660</deduction>  <balance>12028040</balance>  <chargCount>61</chargCount></SendSmsReply>


 6、发送相应string格式

 

    说明:

    多个响应参数之前以”;”隔开,格式为:成功或失败代码;成功或失败信息;成功条数;失败条数;计费条数;计费金额;余额;

    示例:

    1;发送成功!;61;0;61;3660;12024380;

 

三、短信接口接入步骤:

 

1、 注册短信接口平台账户:http://www.lx598.com/acc/x5?i=110792

 

2、 申请短信接口使用,或者联系客服开通,400电话:400-6699-521。

 


3、下载完整接口文件,下载地址:http://www.lx598.com/api/sdk_php.zip。

 

4、参考代码示例完成。

 

<?phprequire_once 'HttpClient.class.php';class dlswSdk {const HOST = 'www.lx198.com';final private static function __replyResult($xmlStr) {$doc = new DOMDocument ();$doc->loadXML ( $xmlStr );print($xmlStr);$xpath = new DOMXpath ( $doc );$arr = $xpath->query ( '/reply/ErrorCode/text()', $doc );$ret = '';foreach ( $arr as $o ) {$ret = $o->nodeValue;}return $ret;}final public static function sendSms($user, $password,$content,$mobiles) {$client = new HttpClient ( self::HOST );$client->setDebug ( true );if (! $client->post ( '/sdk/send', array ('accName' => $user,'accPwd' => strtoupper ( md5 ( $password ) ),'bizId' => date ( 'YmdHis' ),'content' => mb_convert_encoding ( $content, 'UTF-8', 'UTF-8' ),'aimcodes' =>$mobiles ,'dataType'=>"xml") )) {return '-10000';} else {return self::__replyResult ( $client->getContent () );}}}print(dlswSdk::sendSms( 'yangchao_713@163.com', '123456','下午好php【杨超】','13592605881'));  ?>


原创粉丝点击