短信接口被广泛应用于互联网产品,在开发网站或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}
参数说明: