Home > Backend Development > PHP Tutorial > Introduction and usage steps of Alibaba SMS service

Introduction and usage steps of Alibaba SMS service

零下一度
Release: 2023-03-12 16:42:01
Original
2789 people have browsed it

Alibaba SMS Service: Supports high-quality capabilities such as text messages and smart pipes from the three major operators. Product features: 3 seconds reachability, 99% arrival rate, and ultra-low rates.

Steps to use Alibaba SMS service:

1. Purchase service

Go to purchase SMS service

2.Set signature file

3 .Create SMS template

4.Access Alibaba SMS service according to demo

Request parameters:

##SignNameSTRINGOptionalSignature NameTemplateCodeSTRINGOptionalTemplateCODE
Name Type Must Description
ParamString STRING Optional Template variable, where the number must be converted to a string, the length of each variable must be less than 15 for individual users characters. For example: the SMS template is: "SMS verification code ${no}". If the parameter passed is {"no":"123456"}, the content of the text message the user will receive is: [SMS Signature] SMS Verification Code 123456
RecNum STRING Optional Target mobile phone number, multiple records can be separated by English commas
Access to Alibaba SMS service DEMO:

<?php
class Sms{public function send($ParamString,$RecNum,$SignName=’哈哈体育’,$TemplateCode=’SMS_73780003′){$host = “;;$path = “/singleSendSms”;$method = “GET”;$appcode = “这里写你的appcode “;$headers = array();array_push($headers, “Authorization:APPCODE ” . $appcode);$querys = “ParamString=”.$ParamString.”&RecNum=”.$RecNum.”&SignName=”.$SignName.”&TemplateCode=”.$TemplateCode;$bodys = “”;$url = $host . $path . “?” . $querys;
$curl = curl_init();curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);curl_setopt($curl, CURLOPT_URL, $url);curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);curl_setopt($curl, CURLOPT_FAILONERROR, false);curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);curl_setopt($curl, CURLOPT_HEADER, true);if (1 == strpos(“$”.$host, “https://”)){curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);}return curl_exec($curl);}
}
Copy after login

Code explanation:

$ParamString: SMS content, be sure to install your template combination In json format, for example, my SMS template is:

Alibaba SMS Template

Then my $ParamString is written as:

$validate_code =mt_rand(10000,99999);//Generate a random number

$param_string =”{\”msg\”:\””.$validate_code.”\”}”;

Do you think $param_string is strange, but it needs to be combined into json format before your text message can be sent. This is why I wrote a tutorial!

$RecNum: Target mobile phone number, which is where you want to send it

$SignName: SMS signature, I set 'Haha Sports' by default here.

$TemplateCode: SMS template, I set my default template 'SMS_73780003′

The above is the detailed content of Introduction and usage steps of Alibaba SMS service. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template