123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <?php
-
- class SendMsg
- {
- private static $url = 'http://ads.726p.com/api/Code/V1/sendCode';
- private static $urls = 'http://ads.726p.com/api/Code/V1/sendCodes';
- private static $secretKey = 'e2635363a2ddc4404fb8706a89420b0d';
-
- # 阿里云短信
- public static function AliSendMsg($params){
- if(!isset($params['mobile']) || !isset($params['SignName'])){
- return ['code'=>4003,'message'=>'参数有误'];
- }
- $param = array();
- $param['mobile'] = $params['mobile']; //必填
- $param['type'] = 1;
- $param['tpl_id'] = 'SMS_74745003';
- if( isset($params['tpl_id']) ){
- $param['tpl_id'] = $params['tpl_id']; //选填模板id
- }
- $param['aisle'] = 3; //阿里
- $content = array();
- $content['SignName'] = $params['SignName']; //必填
- $content['TemplateParam']['code'] = mt_rand(1000,9999); //验证码
-
- //自定义模板变量
- if(isset($params['extra']) && !empty($params['extra'])){
- $content['TemplateParam'] = $params['extra'];
- }
- $param['parameter'] = json_encode($content);
-
- $res = self::curl_post(self::$url, $param);
- return $res;
- }
-
- # 阿里云短信多条
- public static function AliSendMoreMsg($params){
- if(!isset($params['mobiles']) || !isset($params['SignName'])){
- return ['code'=>4003,'message'=>'参数有误'];
- }
- $param = array();
- $param['mobiles'] = $params['mobiles']; //必填
- $param['type'] = 1;
- $param['tpl_id'] = 'SMS_74745003';
- if( isset($params['tpl_id']) ){
- $param['tpl_id'] = $params['tpl_id']; //选填模板id
- }
- $param['aisle'] = 3; //阿里
- $content = array();
- $content['SignName'] = $params['SignName']; //必填
- $content['TemplateParam']['code'] = mt_rand(1000,9999); //验证码
-
- //自定义模板变量
- if(isset($params['extra']) && !empty($params['extra'])){
- $content['TemplateParam'] = $params['extra'];
- }
- $param['parameter'] = json_encode($content);
-
- $res = self::curl_post(self::$urls, $param);
- return $res;
- }
-
-
- # 天瑞云短信
- public static function TruiSendMsg($params){
- if(!isset($params['mobile']) || !isset($params['SignName'])){
- return ['code'=>4003,'message'=>'参数有误'];
- }
- $param = array();
- $param['mobile'] = $params['mobile']; //必填
- $param['type'] = 1;
- $param['tpl_id'] = '30233';
- if( isset($params['tpl_id']) ){
- $param['tpl_id'] = $params['tpl_id']; //选填模板id
- }
-
- $param['aisle'] = 2; //天瑞
- $content = array();
- $content['sign'] = '【'.$params['SignName'].'】'; //必填
- $content['content'] = mt_rand(1000,9999).'##3';
-
- //自定义模板变量
- if(isset($params['extra']) && !empty($params['extra'])){
- $content['content'] = implode('##',$params['extra']);
- }
- $param['parameter'] = json_encode($content);
-
- $res = self::curl_post(self::$url, $param);
- return $res;
- }
-
- # 云片短信
- public static function YpianSendMsg($params){
- if(!isset($params['mobile'])){
- return ['code'=>4003,'message'=>'参数有误'];
- }
- $param = array();
- $param['mobile'] = $params['mobile']; //必填
- $param['type'] = 1;
- $param['tpl_id'] = '2122814';
- if( isset($params['tpl_id']) ){
- $param['tpl_id'] = $params['tpl_id']; //选填模板id
- }
-
- $param['aisle'] = 1; //云片
- $content = array();
- $content['code'] = mt_rand(1000,9999);
- $content['minutes'] = 3;
-
- //自定义模板变量
- if(isset($params['extra'])){
- $content = $params['extra'];
- }
- $param['parameter'] = json_encode($content);
-
- $res = self::curl_post(self::$url, $param);
- return $res;
- }
-
- private static function curl_post($url, $param){
- $time=time();
- $sign = self::getSignature($param, $time, self::$secretKey);
- $param['sign'] = $sign;
- $param = http_build_query($param);
- //var_dump($param,$sign,$time);
- $header = array('Content-Type:application/x-www-form-urlencoded;charset=utf-8','sign:'.$sign,'time:'.$time,'appkey:de34as');
- $ch = curl_init();//初始化curl
- curl_setopt($ch, CURLOPT_URL,$url);
- curl_setopt($ch, CURLOPT_HEADER, 0);//
- curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//绕过ssl验证
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
- curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
- $data = curl_exec($ch);//运行curl
- curl_close($ch);
- return json_decode($data,true);
- }
-
- private static function getSignature($params, $time, $secretKey)
- {
- // 按数组键名 正序排序
- ksort($params);
- $tem = array();
- foreach ($params as $k => $v) {
- if ($k !== 'sign') {
- $tem[] = "$k=$v";
- }
- }
- if (empty($tem)) {
- $sk = 'time=' . $time . $secretKey;
- } else {
- $sk = implode('&', $tem) . '&time=' . $time . $secretKey;
- }
- return md5($sk);
- }
-
- }
|