免费发送短信验证码
调用短信平台,免费发送短信验证码,前提是你必须注册成为短信平台开发者。获得开发者ID.
前天弄了个短信验证的东西,有免费的短信验证真的很不错,对于做开发的人来说是个好消息,感谢电信能力开放平台的贡献。
以下是我自己调用电信短信验证码接口做的一个短信验证类,拿出来跟大家分享一下,不好勿喷。<?php <br />
<br>
class PHPSMS<br>
{<br>
<br>
<br>
<br>
<br>
public function send($mobile, $message)<br>
{<br>
$App_Id=C('AppId');<br>
$App_Secret=C('AppSecret');<br>
$access_token=$this->get_Access_token();<br>
$token=$this->getToken();<br>
$timestamp = date('Y-m-d H:i:s');<br>
$url="http://api.189.cn/v2/dm/randcode/sendSms";<br>
<br>
$param['app_id']= "app_id=".$App_Id;<br>
$param['access_token'] = "access_token=".$access_token;<br>
$param['timestamp'] = "timestamp=".$timestamp;<br>
$param['phone']="phone=".$mobile;<br>
$param['token']="token=".$token;<br>
$param['randcode']="randcode=".$message;<br>
ksort($param);<br>
$plaintext = implode("&",$param);<br>
$param['sign'] = "sign=".rawurlencode(base64_encode(hash_hmac("sha1", $plaintext, $App_Secret, $raw_output=True)));<br>
ksort($param);<br>
<br>
$result=$this->curl_post($url,implode("&",$param));<br>
$resultArr=json_decode($result);<br>
<br>
<br>
<br>
}<br>
//获取信任码<br>
public function getToken(){<br>
<br>
$App_Id=C('AppId');<br>
//dump($App_Id);<br>
$App_Secret=C('AppSecret');<br>
$access_token=$this->get_Access_token();<br>
$timestamp = date('Y-m-d H:i:s');<br>
$url = "http://api.189.cn/v2/dm/randcode/token?";<br>
<br>
$param['app_id']= "app_id=".$App_Id;<br>
$param['access_token'] = "access_token=".$access_token;<br>
$param['timestamp'] = "timestamp=".$timestamp;<br>
ksort($param);<br>
$plaintext = implode("&",$param);<br>
$param['sign'] = "sign=".rawurlencode(base64_encode(hash_hmac("sha1", $plaintext, $App_Secret, $raw_output=True)));<br>
ksort($param);<br>
$url .= implode("&",$param);<br>
//$result = curl_get($url);<br>
<br>
$r=$this->curl_get($url);<br>
$result=json_decode($r,true);<br>
return $result['token'];<br>
<br>
}<br>
//获取访问令牌 <br>
public function get_Access_token(){<br>
<br>
$App_Id=C('AppId');<br>
$App_Secret=C('AppSecret');<br>
$grant_type='client_credentials';<br>
<br>
$send = 'app_id='.$App_Id.'&app_secret='.$App_Secret.'&grant_type='.$grant_type;<br>
<br>
$access_token = $this->curl_post("https://oauth.api.189.cn/emp/oauth2/v3/access_token", $send);<br>
$access_token = json_decode($access_token, true);<br>
<br>
return $access_token['access_token'];<br>
<br>
}<br>
<br>
function curl_post($url,$data){ // 模拟提交数据函数 <br>
$curl = curl_init(); // 启动一个CURL会话 <br>
curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址 <br>
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查 <br>
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); // 从证书中检查SSL加密算法是否存在 <br>
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器 <br>
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转 <br>
curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer <br>
curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求 <br>
curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包 <br>
curl_setopt($curl, CURLOPT_COOKIEFILE, $GLOBALS['cookie_file']); // 读取上面所储存的Cookie信息 <br>
curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环 <br>
curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容 <br>
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回 <br>
$tmpInfo = curl_exec($curl); // 执行操作 <br>
if (curl_errno($curl)) { <br>
echo 'Errno'.curl_error($curl); <br>
} <br>
curl_close($curl); // 关键CURL会话 <br>
return $tmpInfo; // 返回数据 <br>
}<br>
<br>
/**<br>
* 模拟提交参数,支持https提交 可用于各类api请求<br>
* @param string $url : 提交的地址<br>
* @param array $data :POST数组<br>
* @param string $method : POST/GET,默认GET方式<br>
* @return mixed<br>
*/<br>
function curl_get($url, $data='', $method='GET'){ <br>
$curl = curl_init(); // 启动一个CURL会话<br>
curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址<br>
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查<br>
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在<br>
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器<br>
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转<br>
curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer<br>
if($method=='POST'){<br>
curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求<br>
if ($data != ''){<br>
curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包<br>
}<br>
}<br>
curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环<br>
curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容<br>
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回<br>
$tmpInfo = curl_exec($curl); // 执行操作<br>
curl_close($curl); // 关闭CURL会话<br>
return $tmpInfo; // 返回数据<br>
}<br>
<br>
}
sendSms.zip
( 2.41 MB 下载:697 次 )
AD:真正免费,域名+虚机+企业邮箱=0元

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Learn about Python programming with introductory code examples Python is an easy-to-learn, yet powerful programming language. For beginners, it is very important to understand the introductory code examples of Python programming. This article will provide you with some concrete code examples to help you get started quickly. Print HelloWorldprint("HelloWorld") This is the simplest code example in Python. The print() function is used to output the specified content

"Go Language Programming Examples: Code Examples in Web Development" With the rapid development of the Internet, Web development has become an indispensable part of various industries. As a programming language with powerful functions and superior performance, Go language is increasingly favored by developers in web development. This article will introduce how to use Go language for Web development through specific code examples, so that readers can better understand and use Go language to build their own Web applications. 1. Simple HTTP Server First, let’s start with a

PHP variables store values during program runtime and are crucial for building dynamic and interactive WEB applications. This article takes an in-depth look at PHP variables and shows them in action with 10 real-life examples. 1. Store user input $username=$_POST["username"];$passWord=$_POST["password"]; This example extracts the username and password from the form submission and stores them in variables for further processing. 2. Set the configuration value $database_host="localhost";$database_username="username";$database_pa

The simplest code example of Java bubble sort Bubble sort is a common sorting algorithm. Its basic idea is to gradually adjust the sequence to be sorted into an ordered sequence through the comparison and exchange of adjacent elements. Here is a simple Java code example that demonstrates how to implement bubble sort: publicclassBubbleSort{publicstaticvoidbubbleSort(int[]arr){int

Title: From Beginner to Mastery: Code Implementation of Commonly Used Data Structures in Go Language Data structures play a vital role in programming and are the basis of programming. In the Go language, there are many commonly used data structures, and mastering the implementation of these data structures is crucial to becoming a good programmer. This article will introduce the commonly used data structures in the Go language and give corresponding code examples to help readers from getting started to becoming proficient in these data structures. 1. Array Array is a basic data structure, a group of the same type

Huawei Cloud Edge Computing Interconnection Guide: Java Code Samples to Quickly Implement Interfaces With the rapid development of IoT technology and the rise of edge computing, more and more enterprises are beginning to pay attention to the application of edge computing. Huawei Cloud provides edge computing services, providing enterprises with highly reliable computing resources and a convenient development environment, making edge computing applications easier to implement. This article will introduce how to quickly implement the Huawei Cloud edge computing interface through Java code. First, we need to prepare the development environment. Make sure you have the Java Development Kit installed (

How to use PHP to write the inventory management function code in the inventory management system. Inventory management is an indispensable part of many enterprises. For companies with multiple warehouses, the inventory management function is particularly important. By properly managing and tracking inventory, companies can allocate inventory between different warehouses, optimize operating costs, and improve collaboration efficiency. This article will introduce how to use PHP to write code for inventory warehouse management functions, and provide you with relevant code examples. 1. Establish the database before starting to write the code for the inventory warehouse management function.

Java Selection Sorting Method Code Writing Guide and Examples Selection sorting is a simple and intuitive sorting algorithm. The idea is to select the smallest (or largest) element from the unsorted elements each time and exchange it until all elements are sorted. This article will provide a code writing guide for selection sorting, and attach specific Java sample code. Algorithm Principle The basic principle of selection sort is to divide the array to be sorted into two parts, sorted and unsorted. Each time, the smallest (or largest) element is selected from the unsorted part and placed at the end of the sorted part. Repeat the above
