如何在你的 PHP 或其他应用程序中使用代理 IP 发送短信





5.00/5 (2投票s)
在 PHP 应用中调用短信提供商的短信 API。
引言
许多应用程序或公司希望通过短信而非仅电子邮件来通知用户或客户。正因如此以及许多其他原因,我们发现自己需要进行一些短信 API 集成。这是本技巧的主要原因。如何使用代理集成短信 API。
背景
你需要从短信服务提供商处获取可用的短信 API,并掌握 Curl 脚本的知识。
Using the Code
以下描述了如何集成短信 API。在下面的代码中,我隐藏了一些值。在你的情况下,请确保将 xxxx 替换为正确的值。你应拥有有效的短信 API,并且能够在执行期间回显结果以查看响应。
另外请注意,根据你的网络环境,你可能不需要代理。我在这里仅使用代理是为了能够通过代理 IP 从我的安全网络与 API 通信。
$curl = curl_init();
$Number = $mailagentnamenumber;
$countryCode = 'xxx'; // Replace with known country code of user.
$intNumber = preg_replace('/^0/', $countryCode, $Number);
$msg = 'Good day';
$url = "http://xxxx.com/smsapi/gee.aspx?action=sendmsg&username=xxxx&
password=xxxx&type=1&dlr=1&destination=".$intNumber."
&source=APMT&message=".urlencode($msg)."&URL=";
$proxy = 'x:x:x:x:xxxx';
$jsonDataEncoded = json_encode($jsonData);
//Initiate cURL.
$ch = curl_init($url);
//Tell cURL that we want to send a POST request.
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
//Attach our encoded JSON string to the POST fields.
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // false for https
curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
//Set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
//Execute the request
$result = curl_exec($ch);
echo $result;
关注点
代理 IP 可以帮助你与外部网络通信,尤其是在你不想经历请求白名单的问题时。
历史
- 2023 年 7 月 3 日:初始版本