发送短信不适用于 Laravel 中的控制器。
我已经做了所有事情,但我不知道还能做什么。
我正在尝试使用 php functio 发送短信,但我没有收到任何信息。
但我不知道。是不是少了什么?
您可以在下面看到我的代码。
if ($isInsertSuccess) {
$access_token = 'djfghghsjhfgjdfh.eyJzdWIiOiJkbXJjYWhhamphZEBnbWFpbC5jb20iLCJ0eXBlIjoiYWNjZXNzVG9rZW4iLCJleHAiOjE3MDE0Mjc3MDMsImlhdCI6MTcwMTM0MTMwM30.b8Mm8oMDLl-_dQB9dgfpbVIgdeJ8E6y4CG7N_aOB_Z3A5jTGSBjY7Y5d5vcnzyhoxfwWQxridlC74aqGHm2nIQ';
$post_data = [
"numbers" => $mob1, // Assuming $mob1 is already defined
"content" => "2024 Reference Hajj Application. Reg. No - $registration_id Your application is being processed & it is pending. Once the process is completed, we will confirm you.",
];
$username = "[email protected]";
$password = "XXXXXXX";
$text = urlencode("2024 Reference Hajj Application. Reg. No - $registration_id Your application is being processed & it is pending. Once the process is completed, we will confirm you.");
$curl = 'https://bsms.hutch.lk/api/sendsms';
$curl .= "?id=$username&pw=$password&to=$mob1&content=$text";
$curl = curl_init($curl);
// Set cURL options as needed
curl_setopt($curl, CURLOPT_POST, true); // Use CURLOPT_POST instead of $curlOPT_POST
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Accept: */*',
'X-API-VERSION: v1',
'Authorization: Bearer ' . $access_token
]);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($post_data));
$response = curl_exec($curl);
if ($response) {
echo "SMS Sent to $mob1";
$notification = [
'message' => 'Application Registered Successfully',
'alert-type' => 'success',
];
return redirect()->back()->with($notification);
} else {
echo curl_error($curl);
}
// Close cURL session
curl_close($curl);
}
CURLOPT_POSTFIELDS
- 如果您使用 'Content-Type: application/json
,此参数可以作为 urlencoded 字符串传递,如 'para1=val1¶2=val2&...'
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));