短信发送

6771 人参与 | 时间:2024年04月28日 05:35:16
点击跳转 www.17int.cn
内容
  public function send_mobile()
{
$account='账号';
$password='密码';
$sendUrl = 'http://www.17int.cn/xxsmsweb/smsapi/send.json';
$smsConf = array(
'account' => $account,
'password' => strtoupper(md5($password)),
'mobile' => $param_data['mobile'],
'requestId' => time() + rand(1000, 9999),
'content' => '【签名】'.$content
);
$return = $this->juhecurl($sendUrl, json_encode($smsConf, true), 1); //请求发送短信
$shuju = json_decode($return, 1);
if ($shuju['status'] == 10) {
//成功
} else {
//失败
$error = array();
$error['Rejected'] = '请求被拒绝';
$error['NotAuth'] = '用户密码不正确';
$error['RejeBadReqcted'] = '请求参数不正确';
$error['Charge'] = '余额不足';
return array('code' => 0, 'message' => $error[$shuju['errorCode']]);
}
}
public function juhecurl($url, $params = false, $ispost = 0)
{
$headers = array(
"Content-type: application/json;charset='utf-8'",
'Accept: application/json',
'Cache-Control: no-cache',
'Pragma: no-cache',
);
$httpInfo = array();
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if ($ispost) {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_URL, $url);
} else {
if ($params) {
curl_setopt($ch, CURLOPT_URL, $url . '?' . $params);
} else {
curl_setopt($ch, CURLOPT_URL, $url);
}
}
$response = curl_exec($ch);
if ($response === false) {
//echo "cURL Error: " . curl_error($ch);
return false;
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$httpInfo = array_merge($httpInfo, curl_getinfo($ch));
curl_close($ch);
return $response;
}