短信接口被廣泛應用於互聯網產品,在開發網站或app等應用時會經常遇到接入短信接口的需求,接入短信接口詳細過程如下:
首先需要找到一家短信接口服務商,獲取短信接口調用地址和相關接入參考文檔,這里就以動力思維樂信短信接口為例。
1、申請帳戶、下載接口文件
帳戶申請:http://www.lx598.com/acc/x5?i=110792
短信接口地址:http://www.lx598.com/send2
短信接口文檔:http://www.lx598.com/apitext.html
調用方法:接口采用http方式提交,支持幾乎所有的開發語言。
2、動力思維樂信php短信接口接入demo
<?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 () ; } } ?>
3、參數說明
4、返回值
在接收到客戶端發送的https請求后,返回以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>
參數說明:
發送響應Json結果,示例為:
{"balance":"12882680","chargCount":61,"deduction":"3660","failedNum":0,"replyCode":1,"replyMsg":"發送成功!","succeedNum":61}
參數說明: