1.外洋短信这里引见:短信宝
用的是thinkphp 框架
在TP模块下的目次新建Service文件夹,在内里新建service效劳类用于短信宝发送短信。
更多概况可参考官网:
namespace Home\Service;
class SmsbaoService {
function __construct() {
$config = array(
'user' => D('Config')->get('msg_user'),
'pass' => D('Config')->get('msg_pass'),
'smsapi' => '接口地点',
);
$statusCode = array(
"0" => "短信发送胜利",
"-1" => "参数不全",
"-2" => "效劳器空间不撑持,请确认撑持curl或fsocket,接洽您的空间商处理或改换空间!",
"30" => "暗码毛病",
"40" => "账号不存在",
"41" => "余额缺乏",
"42" => "帐户已过期",
"43" => "IP地点限制",
"50" => "内容含有敏感词"
);
$this->config = $config;
$this->statusCode = $statusCode;
}
/**
* 发送考证码
* @param $phone
* @param $code 考证码
* @return mixed
*/
public function sendMsg($phone, $code) {
$config = $this->config;
$statusCode = $this->statusCode;
$autograph = D('Config')->get('msg_autograph');
$content = D('Config')->get('msg_content');
$content = '【' . $autograph . '】' . str_replace('{code}', $code, $content);
$sendurl = $config['smsapi'] . "sms?u=" . $config['user'] . "&p=" . md5($config['pass']) . "&m=" . $phone . "&c=" . urlencode($content);
$status = file_get_contents($sendurl);
$reData['status'] = $status;
$reData['info'] = $statusCode[$status];
return $reData;
}
}
数据库中要建设置装备陈设参数:
msg_user(短信宝用户名)
msg_pass(短信宝暗码)
msg_autograph(短信宝署名)
msg_content(短信内容,必须包括考证码调换符{code})
2.外洋的引见QcloudSMS腾讯短信
能够发送海内短信的接口有很多,之前也有收拾整顿比较好用的。当有效户需求发送国际短信时,比较经常应用就是阿里和腾讯的了。下面是腾讯短信简单发送对接TP的Service
下面以国际短信为例
1、在腾讯短信节制台要求“外洋文本短信”,只需求要求短信模板便可,外洋短信不需求要求署名,海内短信必须要求署名。
2、下载官方的phpSDK,在TP应用时需求小改一下定名空间,文章下有供给可下载。放到TP的Vendor/Qcloudsms文件夹中。
3、在要应用的模块下新建QcloudsmsService.class.php,代码以下:
namespace Home\Service;
class QcloudsmsService {
function __construct() {
$config = array(
'appid' => '14054******',//节制台检察
'appkey' => '6fe55********************',//节制台检察
'templId' => '295555**',
'nationCode' => '852555', //国度或地区区号,香港852,
品牌建网站公司,大陆86
);
$this->config = $config;
}
/**
* 发送考证码
* @param $phone
* @param $code 考证码
* @return mixed
*/
public function sendMsg($phone, $code) {
vendor('Qcloudsms.SmsSender');
$config = $this->config;
$singleSender = new \SmsSingleSender($config['appid'], $config['appkey']);
// 通俗单发
$result = $singleSender->send(0, $config['nationCode'], $phone, "您好,您的考证码为" . $code, "", "");
//前往的胜利示例:{"result":0,"errmsg":"OK","ext":"","sid":"2:670479-0268698729-028972-001510040916","fee":1}
//result为0表示发送胜利
$rsp = json_decode($result, tru