<?php
// 助通短信接口集成
function SendSMS($mobile, $content)
{
$apiUrl = "http://api.mix2.zthysms.com/v2/sendSms";
$username = "username";
$password = "api-password";
$tkey = time();
$pwd = md5(md5($password) . $tkey);
$params = [
"content" => $content,
"mobile" => $mobile,
"username" => $username,
"password" => $pwd,
"tKey" => $tkey
];
$data = json_encode($params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json; charset=utf-8',
'Content-Length: ' . strlen($data)
));
$res = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($code != 200) {
return false;
}
$res = json_decode($res, true);
if (empty($res) || $res['code'] != 200) {
return false;
}
return true;
}
?>
助通短信接口集成 - PHP
最新推荐文章于 2023-07-21 14:13:26 发布
本文详细介绍了如何在PHP环境中集成助通短信接口,包括步骤解析、所需库的安装、API调用示例及错误处理,助力开发者实现高效稳定的短信发送功能。
1029

被折叠的 条评论
为什么被折叠?



