Heim > Backend-Entwicklung > PHP-Tutorial > 短信验证 - php如何实现发送短信?

短信验证 - php如何实现发送短信?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Freigeben: 2016-06-06 20:19:24
Original
1614 Leute haben es durchsucht

php如何实现发送短信的功能?有什么库吗,不知道有没有免费发送短信这方面的服务。求各位大神赐教。

回复内容:

php如何实现发送短信的功能?有什么库吗,不知道有没有免费发送短信这方面的服务。求各位大神赐教。

一张图看清大致原理:
短信验证 - php如何实现发送短信?

  • 红色的请求线是我们关注的重点,第三方服务商一般都会用HTTP协议来实现发短信的API的

  • 去服务商短信官网看API就行了,一般都会提供PHP的短信SDK

  • 如果没有提供,也可以自己写的,下面例子

要确认开启了curl支持

<code class="PHP"><?php $ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, 'http://www.baidu.com/');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
 
echo $file_contents;
?></code>
Nach dem Login kopieren

或者直接用file_get_contents

<code class="PHP"><?php // 以POST方式
$data = array ('foo' => 'bar');
$data = http_build_query($data);
 
$opts = array (
'http' => array (
'method' => ‘POST',
'header'=> 'Content-type: application/x-www-form-urlencodedrn' .
"Content-Length:" . strlen($data) . "rn",
'content' => $data
)
);
 
$context = stream_context_create($opts);
$html = file_get_contents(‘https://www.baidu.com', false, $context);
 
echo $html;

// 以GET方式
$url='http://www.baidu.com/';
$html = file_get_contents($url);
echo $html;
?></code>
Nach dem Login kopieren

http://www.yunpian.com

发短信,你要接第三方短信供应商吧,一般这种都会提供demo的。
每家的短信平台都是有差异的。

这个跟库没什么关系。都是第三方提供的服务。你这边http调用下就可以了,就这么简单

几乎没有免费的,我司用的阿里大鱼,速度极快。。。
配置也极其简单。。可以通过get请求发送。。
缺点:比较贵。。
http://www.alidayu.com/

有收费的第三方服务 可以百度下 短信api

我在想要是把螺丝帽的文档贴出会不显得有点low,呵呵

<code class="php">$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://sms-api.luosimao.com/v1/send.json");

curl_setopt($ch, CURLOPT_HTTP_VERSION  , CURL_HTTP_VERSION_1_0 );
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);

curl_setopt($ch, CURLOPT_HTTPAUTH , CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD  , 'api:key-b761c24f77fc5d77769d5a442ccacc10');

curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('mobile' => '13761428267','message' => '验证码:123456【铁壳网络】'));

$res = curl_exec( $ch );
curl_close( $ch );
//$res  = curl_error( $ch );
var_dump($res);
</code>
Nach dem Login kopieren

返回结果:

<code class="json">{"error":0,"msg":"ok"}</code>
Nach dem Login kopieren

http://submail.cn/chs/documents/developer/BSx2b3 SUBMAIL PHP短信SDK,希望对您有帮助:)

http://sms.mob.com/#/sms

免费的肯定没有

免费的没有,一般会有个额度给你测试用。一直在用http://www.yuntongxun.com,各方面都还不错,实现也简单。

我们用的是云之讯,这家可以

我们自己用安卓机写了一个APP 做短信猫来用。

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Aktuelle Ausgaben
PHP-Datenerfassung?
Aus 1970-01-01 08:00:00
0
0
0
PHP-Erweiterung intl
Aus 1970-01-01 08:00:00
0
0
0
Wie man PHP gut lernt
Aus 1970-01-01 08:00:00
0
0
0
Mehrere PHP-Versionen
Aus 1970-01-01 08:00:00
0
0
0
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage