PHP calls Huyi wireless SMS interface to send SMS messages

WBOY
Release: 2023-05-23 11:42:02
Original
1812 people have browsed it

As one of the most influential SMS service providers in China, Huyi Wireless provides an SMS interface that can easily send SMS messages and supports various programming languages, including PHP. The following will introduce in detail how to use PHP to call the Huyi wireless SMS interface to send SMS messages.

  1. Register a Huyi Wireless account and apply for the SMS interface

Before using the Huyi Wireless SMS service, you need to register a Huyi Wireless account and apply for the SMS interface. After registration and application are completed, you can obtain the following important information:

  • APIID: used to identify the user's identity, just like an account number;
  • APIKY: used to Encrypt and verify the user's identity;
  • SMS interface address: URL address used to send SMS messages.
  1. Writing PHP code to send text messages

When using PHP to call the SMS interface to send text messages, you need to pay attention to the following points:

  • Use the CURL extension library to implement HTTP requests;
  • Splice the SMS interface address and parameters according to the prescribed format;
  • Use the POST method to send the request, and set the request header and request body information;
  • Process the returned results and obtain the sending results.

The following is an example of PHP code to implement SMS sending:

// 短信接口地址
$url = "http://xxxxxxxxxxxxxxxxxxxxxx/sms/send.html";
// APIID和APIKEY
$apiid = "xxxxxxxxxx";
$apikey = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
// 接收短信的手机号码
$mobile = "xxxxxxxxxxx";
// 短信内容
$content = "您的验证码是123456,有效期为5分钟,请尽快使用!";
// 拼接参数
$params = array(
    'apikey' => $apikey,
    'mobile' => $mobile,
    'content' => $content,
);
// 发送请求
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$output = curl_exec($ch);
curl_close($ch);
// 对返回结果进行处理
$result = json_decode($output, true);
if ($result['code'] == '2') {
    echo '短信发送成功!';
} else {
    echo '短信发送失败!错误码:' . $result['code'] . ' 错误信息:' . $result['msg'];
}
Copy after login
  1. Notes on SMS sending

Use Huyi wireless SMS interface to implement SMS Please note the following points when sending:

  • Sensitive words are not allowed in text message content, otherwise they will be intercepted directly;
  • The same mobile phone number can only send up to 10 text messages per day;
  • When sending text messages, you need to pay attention to the specifications of the text message signature, and the signature must be reviewed and approved by Huyi Wireless Platform before it can be used.

In short, it is very simple to use PHP to call the Huyi wireless SMS interface to send SMS messages. You only need to follow the above steps. If you encounter problems, you can refer to the official documentation of Huyi Wireless or contact customer service for consultation.

The above is the detailed content of PHP calls Huyi wireless SMS interface to send SMS messages. For more information, please follow other related articles on the PHP Chinese website!

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