php网云发短信

Posted 打你一下

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php网云发短信相关的知识,希望对你有一定的参考价值。

<?php

 

namespace lib;

/**
* Description of Qrcode
* 网云发送短信
* @author lsf
*/
class Wangyuncms {

/**
* 多个发送短信
* @param type $mobile
* @param type $setting
* @param type $content
*/
public function groupMessage($mobile, $setting, $content) {
header("Content-Type: text/html;charset=utf-8");
$url = ‘http://api.smschn.cn‘;
$post = ‘user=‘ . URLEncode($setting["wangyun_user"]) . ‘&key=‘ . $setting["wangyun_key"] . ‘&mobile=‘ . $mobile . ‘&content=‘ . $content;
$this->curl_request($url, $post);
}

/**
* 网云发送短信
*/
public function sendMessage($mobile, $setting, $content) {
header("Content-Type: text/html;charset=utf-8");
$url = ‘http://api.smschn.cn‘;
$post = ‘user=‘ . URLEncode($setting["wangyun_user"]) . ‘&key=‘ . $setting["wangyun_key"] . ‘&mobile=‘ . $mobile . ‘&content=‘ . $content;
$res = $this->curl_request($url, $post);
if (!$res["success"]) {
return array("success" => false, "msg" => $res["msg"]);
} else {
if ($res["data"] >= 0) {
return array("success" => true, "msg" => "");
} else {
return array("success" => false, "msg" => $this->errorCode($res["data"]));
}
}
}

/**
* 请求
* @param type $url
* @param type $post
* @return type
*/
function curl_request($url, $post = ‘‘) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER[‘HTTP_USER_AGENT‘]);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //有请求的返回值
curl_setopt($curl, CURLOPT_AUTOREFERER, 1); //重定向时
curl_setopt($curl, CURLOPT_NOSIGNAL, 1); //以毫秒为超时计时单位一定要设置这个
curl_setopt($curl, CURLOPT_TIMEOUT_MS, 10000); //2秒超时PHP 5.2.3起可使用
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
$data = curl_exec($curl);
if (curl_errno($curl)) {
return array("success" => false, "msg" => curl_error($curl));
}
curl_close($curl);
return array("success" => true, "msg" => "", "data" => $data);
}

/**
* 错误代码
* @param type $code
* @return string
*/
public function errorCode($code) {
$data = array("-11" => "用户名不匹配",
"-12" => "接口鉴权KEY不匹配,非登录密码",
"-13" => "账户余额不足",
"-14" => "账户被屏蔽",
"-21" => "手机号码错误",
"-22" => "手机号码超过限制",
"-23" => "短信内容为空",
"-24" => "短信内容出现非法字符",
"-25" => "短信签名为空",
"-26" => "短信签名超长",
"-30" => "接口IP被限制访问");
try {
return$data[$code];
} catch (Exception $exc) {
return "短信发送失败";
}
}

}

以上是关于php网云发短信的主要内容,如果未能解决你的问题,请参考以下文章

SpringBoot整合容联云发短信验证码

Java之使用阿里云发短信项目案例以及源代码

Java之使用阿里云发短信项目案例以及源代码

请问 哪有阿里云 短信服务 api 请求签名PHP教程

怎么发短信炸别人的手机

为啥网易云发布作品发过来的短信是不同号码