短信接码php源码(php怎么写短信接口)

本文目录
- php怎么写短信接口
- thinkPHP怎么实现短信验证接口的调用
- 如何实现php手机短信验证功能
- PHP对接腾讯云短信求助
- 谁能帮我写一个PHP的短信验证例程,
- 通用免认证的短信接口,每天单个号码100条以上
- 我有移动提供的短信接口,请问怎么用php调用这些接口发送短信呢
php怎么写短信接口
短信接口可以广泛应用在网站会员手机验证、订单通知、物流提醒等触发类短信应用。技术实现1、用户填写自己的手机号码,点击“获取验证码”按钮2、网站按规则生成短信验证码,并将用户的手机号码和验证码内容通过短信验证接口发送到验证码短信平台。3、验证码短信平台对经过一系列的判断并通过之后(账户余额、内容是否合规、手机号码是否合规、手机号码所属的运营商),将信息提交到相应运营商的服务器。4、运营商将短信内容下发到用户的手机。
thinkPHP怎么实现短信验证接口的调用
1、一般来说这个短信验证的功能都是要选择相关的公司付费来使用的。在使用的时候他会提供一个接口,你需要获取这个接口就可以了,一般都是封装为方法的, 你调用这个方法名称就OK了 ,
2、这个接口你只需要写一个来方法传参来调用这个接口的参数就可以了
比如:public function A(fang){
写方法
}
echo A(d);这样就可以了的
如何实现php手机短信验证功能
现在网站在建设网站时为了保证用户信息的真实性,往往会选择发短信给用户手机发验证码信息,只有通过验证的用户才可以注册,这样保证了用户的联系信息资料的100%的准确性 。
第一、实现php手机短信验证功能的基本思路
1、要找到短信服务提供商,接入短信服务
2、在网站信息提交页面请求发送信息
3、服务器向短信服务提供商通信,提交发送请求
4、短信服务提供商通过运营商将信息发送到用户的手机中
二、手机号码短信验证前台页面效果实现
《!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 》
《html xmlns》
《head》
《title》《/title》
《script src="js/jquery-1.4a2.min.js" type="text/javascript"》《/script》
《script type="text/javascript"》
/*-------------------------------------------*/
var InterValObj; //timer变量,控制时间
var count = 60; //间隔函数,1秒执行
var curCount;//当前剩余秒数
var code = ""; //验证码
var codeLength = 6;//验证码长度
function sendMessage() {
curCount = count;
var dealType; //验证方式
tel = $(’#tel’).val();
if(tel!=’’){
//验证手机有效性
var myreg = /^(((13{1}))+\d{8})$/;
if(!myreg.test($(’#tel’).val()))
{
alert(’请输入有效的手机号码!’);
return false;
}
tel = $(’#tel’).val();
//产生验证码
for (var i = 0; i 《 codeLength; i++) {
code += parseInt(Math.random() * 9).toString();
}
//设置button效果,开始计时
$("#btnSendCode").attr("disabled", "true");
$("#btnSendCode").val("请在" + curCount + "秒内输入验证码");
InterValObj = window.setInterval(SetRemainTime, 1000); //启动计时器,1秒执行一次
//向后台发送处理数据
$.ajax({
type: "POST", //用POST方式传输
dataType: "text", //数据格式:JSON
url: ’yanzhengma.php’, //目标地址(根据实际地址)
data: "&tel=" + tel + "&code=" + code,
error: function (XMLHttpRequest, textStatus, errorThrown) { },
success: function (msg){ }
});
}else{
alert(’请填写手机号码’);
}
}
//timer处理函数
function SetRemainTime() {
if (curCount == 0) {
window.clearInterval(InterValObj);//停止计时器
$("#btnSendCode").removeAttr("disabled");//启用按钮
$("#btnSendCode").val("重新发送验证码");
code = ""; //清除验证码。如果不清除,过时间后,输入收到的验证码依然有效
}
else {
curCount--;
$("#btnSendCode").val("请在" + curCount + "秒内输入验证码");
}
}
《/script》
《/head》
《body》
《input name="tel" id=tel type="text" /》
《input id="btnSendCode" type="button" value="发送验证码" onclick="sendMessage()" /》《/p》
《/body》
《/html》
第三、调用短信服务器短信接口
整理的页面是yanzhengma.php(具体根据服务商提供信息)
《?php //提交短信
$post_data = array();
$post_data = 短信服务商提供ID;
$post_data = ’短信服务商提供用户名’;
$post_data = ’短信服务商提供密码’;
// Session保存路径
$sessSavePath = dirname(__FILE__)."/../data/sessions/";
if(is_writeable($sessSavePath) && is_readable($sessSavePath)){
session_save_path($sessSavePath);
}
session_register(’mobliecode’);
$_SESSION;
$content=’短信验证码:’.$_POST.’【短信验证】’;
$post_data = mb_convert_encoding($content,’utf-8’, ’gb2312’); //短信内容需要用urlencode编码下
$post_data;
$post_data = ’’; //不定时发送,值为0,定时发送,输入格式YYYYMMDDHHmmss的日期值
***隐藏网址***
$o=’’;
foreach ($post_data as $k=》$v)
{
$o.="$k=".$v.’&’;
}
$post_data=substr($o,0,-1);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //如果需要将结果直接返回到变量里,那加上这句。
$result = curl_exec($ch);
?》
第四:提交表单信息时对短信验证码验证
//手机验证码开始
session_start();
$svalitel = $_SESSION;
$vdcodetel = empty($vdcodetel) ? ’’ : strtolower(trim($vdcodetel));
if(strtolower($vdcodetel)!=$svalitel || $svalitel==’’)
{
ResetVdValue();
//echo "Pageviews=".$vdcodetel;
ShowMsg("手机验证码错误!", ’-1’);
exit();
}
PHP对接腾讯云短信求助
你的模板是需要两个参数所以$params变量有两个元素就行,例如$params=
另外一个问题 你想问的是腾讯该如何使用你的模板,这个是要用到模板id,你在腾讯那边申请短信模板之后 ,腾讯会去审核你的模板审核成功之后 这个短信模板才可以使用,对应的会有一个模板id给你,
例如你申请的短信模板为 【尊敬的客户{1},感谢您对{2}的大力支持,在此祝您身体健康生活愉快。】 腾讯那边审核成功之后 产生的模板id是123456,那么你只用把123456告诉腾讯就行而不是传一堆文字
你的代码看不清,我下载了腾讯官方的sdk 下图$templateId就是短信模板id,
调这个方法sendWithParam把需要传的参数传进去就行,
假设 $params= ;$templateId=123456
腾讯那边会找到123456对应的短信模板是: 【尊敬的客户{1},感谢您对{2}的大力支持,在此祝您身体健康生活愉快。】
然后腾讯会根据$params把短信解析成【尊敬的客户张三,感谢您对淘宝的大力支持,在此祝您身体健康生活愉快。】,然后再根据你传的手机号 发给对应的手机上
谁能帮我写一个PHP的短信验证例程,
《?php
/**
*
* User: shikiliu
* Date: 13-7-11
*/
class TelephoneCheck
{
/**
* 取得某个用户某次活动的手机验证码
* @param $uin 用户ID 小于10000系统保留
* @param $actId 活动ID 小于1000系统保留
* @param $telephone 用户手机号
* @return bool|int 4位数的验证码
*/
public function getTelephoneCode($uin, $actId, $telephone)
{
if ($uin 《 10000 || $actId 《 1000 || empty($telephone)) {
return false;
}
$time = time();
$timeFeature = hexdec(substr(md5($time), 0, 3)) & 0x1F1;
$telephoneFeature = hexdec(substr(md5($telephone), 8, 4));
$actIdFeature = hexdec(substr(md5($actId), 16, 4));
$uinFeature = hexdec(substr(md5($uin), 24, 4));
$sumFeature = $telephoneFeature + $actIdFeature + $uinFeature;
$sumFeature = $sumFeature % 10000;
if ($sumFeature 《 1000) {
$sumFeature = 5145;
}
$result = $sumFeature | $timeFeature;
return $result;
}
/**
* 验证用户的手机验证码
* @param $uin 用户ID 小于10000系统保留
* @param $actId 活动ID 小于1000系统保留
* @param $telephone 用户手机号
* @param $code getTelephoneCode生成的验证码
* @return bool 是否正确
*/
public function checkTelephoneCode($uin, $actId, $telephone, $code)
{
if ($uin 《 10000 || $actId 《 1000 || empty($telephone) || empty($code)) {
return false;
}
$telephoneFeature = hexdec(substr(md5($telephone), 8, 4));
$actIdFeature = hexdec(substr(md5($actId), 16, 4));
$uinFeature = hexdec(substr(md5($uin), 24, 4));
$sumFeature = $telephoneFeature + $actIdFeature + $uinFeature;
$sumFeature = $sumFeature % 10000;
if ($sumFeature 《 1000) {
$sumFeature = 5145;
}
$sumFeature = $sumFeature & 0xE0E;
$code = $code & 0xE0E;
if ($sumFeature == $code) {
return true;
}
return false;
}
}
$actId = 10001;
$telephone = 13797025562;
$uin = 514540767;
$telCode = new TelephoneCheck();
$code = $telCode-》getTelephoneCode($uin, $actId, $telephone);
var_dump($code);
var_dump($telCode-》checkTelephoneCode($uin, $actId, $telephone, $code));
var_dump($telCode-》checkTelephoneCode($uin, $actId, $telephone, $code+10));
通用免认证的短信接口,每天单个号码100条以上
下面介绍一下moduyun平台的短信php接口。链接:www.moduyun.com
// Works well with php5.3 and php5.6.
namespace Moduyun\Sms;
require_once(’SmsSenderUtil.php’);
class SmsSingleSender {
var $url;
var $accesskey;
var $secretkey;
var $util;
function __construct($accesskey, $secretkey) {
***隐藏网址***
$this-》accesskey = $accesskey;
$this-》secretkey = $secretkey;
$this-》util = new SmsSenderUtil();
}
/**
* 普通单发,明确指定内容,如果有多个签名,请在内容中以【】的方式添加到信息内容中,否则系统将使用默认签名
* @param int $type 短信类型,0 为普通短信,1 营销短信
* @param string $nationCode 国家码,如 86 为中国
* @param string $phoneNumber 不带国家码的手机号
* @param string $msg 信息内容,必须与申请的模板格式一致,否则将返回错误
* @param string $extend 扩展码,可填空串
* @param string $ext 服务端原样返回的参数,可填空串
* @return string json string { "result": xxxxx, "errmsg": "xxxxxx" ... },被省略的内容参见协议文档
*/
function send($type, $nationCode, $phoneNumber, $msg, $extend = "", $ext = "") {
/*
请求包体
{
"tel": {
"nationcode": "86",
"mobile": "13788888888"
},
"type": 0,
"msg": "你的验证码是1234",
"sig": "fdba654e05bc0d15796713a1a1a2318c",
"time": 1479888540,
"extend": "",
"ext": ""
}
应答包体
{
"result": 0,
"errmsg": "OK",
"ext": "",
"sid": "xxxxxxx",
"fee": 1
}
*/
$random = $this-》util-》getRandom();
$curTime = time();
$wholeUrl = $this-》url . "?accesskey=" . $this-》accesskey . "&random=" . $random;
// 按照协议组织 post 包体
$data = new \stdClass();
$tel = new \stdClass();
$tel-》nationcode = "".$nationCode;
$tel-》mobile = "".$phoneNumber;
$data-》tel = $tel;
$data-》type = (int)$type;
$data-》msg = $msg;
$data-》sig = hash("sha256",
"secretkey=".$this-》secretkey."&random=".$random."&time=".$curTime."&mobile=".$phoneNumber, FALSE);
$data-》time = $curTime;
$data-》extend = $extend;
$data-》ext = $ext;
return $this-》util-》sendCurlPost($wholeUrl, $data);
}
/**
* 指定模板单发
* @param string $nationCode 国家码,如 86 为中国
* @param string $phoneNumber 不带国家码的手机号
* @param int $templId 模板 id
* @param array $params 模板参数列表,如模板 {1}...{2}...{3},那么需要带三个参数
* @param string $sign 签名,如果填空串,系统会使用默认签名
* @param string $extend 扩展码,可填空串
* @param string $ext 服务端原样返回的参数,可填空串
* @return string json string { "result": xxxxx, "errmsg": "xxxxxx" ... },被省略的内容参见协议文档
*/
function sendWithParam($nationCode, $phoneNumber, $templId = 0, $params, $sign = "", $extend = "", $ext = "") {
/*
请求包体
{
"tel": {
"nationcode": "86",
"mobile": "13788888888"
},
"sign": "Moduyun",
"tpl_id": 19,
"params": [
"验证码",
"1234",
"4"
],
"sig": "fdba654e05bc0d15796713a1a1a2318c",
"time": 1479888540,
"extend": "",
"ext": ""
}
应答包体
{
"result": 0,
"errmsg": "OK",
"ext": "",
"sid": "xxxxxxx",
"fee": 1
}
*/
$random = $this-》util-》getRandom();
$curTime = time();
$wholeUrl = $this-》url . "?sdkaccesskey=" . $this-》accesskey . "&random=" . $random;
// 按照协议组织 post 包体
$data = new \stdClass();
$tel = new \stdClass();
$tel-》nationcode = "".$nationCode;
$tel-》mobile = "".$phoneNumber;
$data-》tel = $tel;
$data-》sig = $this-》util-》calculateSigForTempl($this-》secretkey, $random, $curTime, $phoneNumber);
$data-》tpl_id = $templId;
$data-》params = $params;
$data-》sign = $sign;
$data-》time = $curTime;
$data-》extend = $extend;
$data-》ext = $ext;
return $this-》util-》sendCurlPost($wholeUrl, $data);
}
}
class SmsMultiSender {
var $url;
var $accesskey;
var $secretkey;
var $util;
function __construct($accesskey, $secretkey) {
***隐藏网址***
$this-》accesskey = $accesskey;
$this-》secretkey = $secretkey;
$this-》util = new SmsSenderUtil();
}
/**
* 普通群发,明确指定内容,如果有多个签名,请在内容中以【】的方式添加到信息内容中,否则系统将使用默认签名
* 【注意】海外短信无群发功能
* @param int $type 短信类型,0 为普通短信,1 营销短信
* @param string $nationCode 国家码,如 86 为中国
* @param string $phoneNumbers 不带国家码的手机号列表
* @param string $msg 信息内容,必须与申请的模板格式一致,否则将返回错误
* @param string $extend 扩展码,可填空串
* @param string $ext 服务端原样返回的参数,可填空串
* @return string json string { "result": xxxxx, "errmsg": "xxxxxx" ... },被省略的内容参见协议文档
*/
function send($type, $nationCode, $phoneNumbers, $msg, $extend = "", $ext = "") {
/*
请求包体
{
"tel": [
{
"nationcode": "86",
"mobile": "13788888888"
},
{
"nationcode": "86",
"mobile": "13788888889"
}
],
"type": 0,
"msg": "你的验证码是1234",
"sig": "fdba654e05bc0d15796713a1a1a2318c",
"time": 1479888540,
"extend": "",
"ext": ""
}
应答包体
{
"result": 0,
"errmsg": "OK",
"ext": "",
"detail": [
{
"result": 0,
"errmsg": "OK",
"mobile": "13788888888",
"nationcode": "86",
"sid": "xxxxxxx",
"fee": 1
},
{
"result": 0,
"errmsg": "OK",
"mobile": "13788888889",
"nationcode": "86",
"sid": "xxxxxxx",
"fee": 1
}
]
}
*/
$random = $this-》util-》getRandom();
$curTime = time();
$wholeUrl = $this-》url . "?accesskey=" . $this-》accesskey . "&random=" . $random;
$data = new \stdClass();
$data-》tel = $this-》util-》phoneNumbersToArray($nationCode, $phoneNumbers);
$data-》type = $type;
$data-》msg = $msg;
$data-》sig = $this-》util-》calculateSig($this-》secretkey, $random, $curTime, $phoneNumbers);
$data-》time = $curTime;
$data-》extend = $extend;
$data-》ext = $ext;
return $this-》util-》sendCurlPost($wholeUrl, $data);
}
/**
* 指定模板群发
* 【注意】海外短信无群发功能
* @param string $nationCode 国家码,如 86 为中国
* @param array $phoneNumbers 不带国家码的手机号列表
* @param int $templId 模板 id
* @param array $params 模板参数列表,如模板 {1}...{2}...{3},那么需要带三个参数
* @param string $sign 签名,如果填空串,系统会使用默认签名
* @param string $extend 扩展码,可填空串
* @param string $ext 服务端原样返回的参数,可填空串
* @return string json string { "result": xxxxx, "errmsg": "xxxxxx" ... },被省略的内容参见协议文档
*/
function sendWithParam($nationCode, $phoneNumbers, $templId, $params, $sign = "", $extend ="", $ext = "") {
/*
请求包体
{
"tel": [
{
"nationcode": "86",
"mobile": "13788888888"
},
{
"nationcode": "86",
"mobile": "13788888889"
}
],
"sign": "Moduyun",
"tpl_id": 19,
"params": [
"验证码",
"1234",
"4"
],
"sig": "fdba654e05bc0d15796713a1a1a2318c",
"time": 1479888540,
"extend": "",
"ext": ""
}
应答包体
{
"result": 0,
"errmsg": "OK",
"ext": "",
"detail": [
{
"result": 0,
"errmsg": "OK",
"mobile": "13788888888",
"nationcode": "86",
"sid": "xxxxxxx",
"fee": 1
},
{
"result": 0,
"errmsg": "OK",
"mobile": "13788888889",
"nationcode": "86",
"sid": "xxxxxxx",
"fee": 1
}
]
}
*/
$random = $this-》util-》getRandom();
$curTime = time();
$wholeUrl = $this-》url . "?accesskey=" . $this-》accesskey . "&random=" . $random;
$data = new \stdClass();
$data-》tel = $this-》util-》phoneNumbersToArray($nationCode, $phoneNumbers);
$data-》sign = $sign;
$data-》tpl_id = $templId;
$data-》params = $params;
$data-》sig = $this-》util-》calculateSigForTemplAndPhoneNumbers(
$this-》secretkey, $random, $curTime, $phoneNumbers);
$data-》time = $curTime;
$data-》extend = $extend;
$data-》ext = $ext;
return $this-》util-》sendCurlPost($wholeUrl, $data);
}
}
更多,欢迎关注云服务-moduyun平台
***隐藏网址***
我有移动提供的短信接口,请问怎么用php调用这些接口发送短信呢
移动的接口是什么风格的?是soap的还是自定义的?
调用自定义接口通常有以下步骤:
1、阅读接口文档
2、数据接口一般会提供一些参数。如果是GET接口,请将参数拼接在地址的后面(推荐使用
***隐藏网址***
3、请求数据
4、解析返回的内容,判断调用是否成功。一般返回的内容有xml和json格式。
给你一个CURL调用POST接口的例子:
《?php
$ch = curl_init(’省略接口地址, 防止屏蔽’);
// 以下选项设为true,否则接口返回的内容会直接打印在页面上
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// 连接超时,一定要设置
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
// 连接成功后,请求超时,一定要设置
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
// 使用POST请求
curl_setopt($ch, CURLOPT_POST, 1);
// 将参数POST过去, $post_data是你的参数组成的关联数组
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
// 提交请求,得到反馈
$response = curl_exec($ch);
// 解析反馈的内容,略
如果是SOAP风格的,请查阅PHP文档SoapClient类的用法。因为Soap规范不统一,使用其他语言实现的Soap可能和PHP不兼容。
以前我使用过移动梦网的接口(不是移动的接口),它提供两种风格的API。它的Soap就和PHP不兼容。所以我选择了自定义风格的API。

更多文章:
21天学通c语言怎么样(大家推荐一个c语言教材c primer plues和21天学通c语言怎么样)
2026年8月24日 11:30
service启动方式区别(android 启动service的两种方式有什么不同)
2026年1月19日 09:00
下载app领彩金37(注册送300元打到3000,我真是想知道贵公司(联想)官网注册会员后送)
2026年9月7日 21:15
excel图书馆管理系统模板(VBA+Excel+Access做一个图书管理系统)
2025年7月7日 17:30
hbase预分区(hbase 设计表的时候rowkey 和分区考虑哪个)
2026年1月14日 14:00
validation process(汽车ppv和pp阶段)
2025年11月24日 22:00
oraclehash分区查询(oracle中怎么查询一个分区表中某个分区的具体信息,例如这个分区的范围,这个可以查得到吗)
2026年8月12日 08:45
html2canvas中文文档(关于html2canvas用法的总结)
2026年8月11日 16:15
dumpuper是什么软件(DumpUper.exe是什么程序)
2025年10月3日 00:15















