这里分享的是动力思维乐信第三方短信接口的demo,阅读demo前,需要先了解以下几点:
乐信短信接口API文档(http://www.lx598.com/apitext.html ),了解更多请移步乐信官网(http://www.lx598.com/ )
<?php require_once 'HttpClient.class.php'; class dlswSdk { const HOST = 'www.lx198.com'; /** * 发送短信 * @param $user 用户名 * @param $password 密码 * @param $content 内容后加签名 * @param $mobiles 手机号多个手机号之间英文半角逗号隔开 * @return 服务端返回的结果 ok:业务id 或者 错误代码 */ final public static function sendSms($user, $password,$content,$mobiles) { $client = new HttpClient ( self::HOST ); $client->setDebug ( true ); $seed=date ( 'YmdHis' ); if (! $client->post ( '/sdk/send2', array ( 'accName' => $user, 'accPwd' => strtoupper(md5(strtoupper ( md5 ( $password ))+$seed )), 'seed' => $seed, 'content' => mb_convert_encoding ( $content, 'UTF-8', 'UTF-8' ), 'aimcodes' =>$mobiles ) )) { return '-10000'; } else { return $client->getContent () ; } } /** * 查询余额 * @param $user 用户名 * @param $password 原始密码 */ final public static function qryBalance($user, $password) { $client = new HttpClient ( self::HOST ); $client->setDebug ( true ); $seed=date ( 'YmdHis' ); if (! $client->post ( '/sdk/qryBalance2', array ( 'accName' => $user, 'accPwd' => strtoupper(md5(strtoupper ( md5 ( $password ))+$seed )), 'seed' => $seed ) )) { return '-10000'; } else { return $client->getContent () ; } } /** * 查询回执报告 * @param $user 用户名 * @param $password 原始密码 * @param $seed 当前时间 格式:YYYYMMDD HHMISS 例如:20130806102030 * @return 返回的查询报告结果 格式为:业务id,手机号,状态;业务id,手机号,状态 状态1表示成功;0表示失败 */ final public static function qryReport($user, $password) { $client = new HttpClient ( self::HOST ); $client->setDebug ( true ); $seed=date ( 'YmdHis' ); if (! $client->post ( '/sdk/qryReport2', array ( 'accName' => $user, 'accPwd' => strtoupper(md5(strtoupper ( md5 ( $password ))+$seed )), 'seed' => $seed ) )) { return '-10000'; } else { return $client->getContent () ; } } /** * 查询上行短信 * @param $user 用户名 * @param $password 密码 * @param $seed 当前时间 格式:YYYYMMDD HHMISS 例如:20130806102030 * @return 返回的上行短信信息格式为:签名$$上行手机号$$上行内容$$上行 时间####签名$$上行手机号$$上行内容$$上行时间 */ final public static function receiveSms($user, $password) { $client = new HttpClient ( self::HOST ); $client->setDebug ( true ); $seed=date ( 'YmdHis' ); if (! $client->post ( '/sdk/receiveSms2', array ( 'accName' => $user, 'accPwd' => strtoupper(md5(strtoupper ( md5 ( $password ))+$seed )), 'seed' => $seed ) )) { return '-10000'; } else { return $client->getContent () ; } } } print(dlswSdk::sendSms( 'user', 'password','content','mobiles')); print(dlswSdk::qryBalance( 'user', 'password,')); print(dlswSdk::qryReport( 'user', 'password,')); print(dlswSdk::receiveSms( 'user', 'password,')); ?>