SendSms('13477191977',$data,'330371'); // echo $Sms->SendVoiceSms('13477191977','4564',336953); */ // use \app\base\Common; class Sms { private $AppID=""; private $AppKey=""; private $sign=""; public function __construct() { $config = sysconfig('sms'); if(!empty($config)){ // 短信总开关 if(1!=$config['send_switch']){ return false; }else{ $this->AppID=$config['tencent_sms_appid']; $this->AppKey=$config['tencent_sms_key']; $this->sign=$config['tencent_sms_sign']; } } } //发送短信 public function SendSms($mobile,$params,$tpl_id) { $random=mt_rand(100000,999999); $URL='https://yun.tim.qq.com/v5/tlssmssvr/sendsms?sdkappid='.$this->AppID.'&random='.$random; $time=time(); $string='appkey='.$this->AppKey.'&random='.$random.'&time='.$time.'&mobile='.$mobile; $sign=hash("sha256",$string); $data=array("ext"=>"","extend"=> "","params"=> $params,"sig"=>$sign,"sign"=>$this->sign,"tel"=>array("mobile"=>$mobile,'nationcode'=>86),"time"=>$time,"tpl_id"=>$tpl_id); $aContext = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/json', 'content' => json_encode($data) )); $cxContext = stream_context_create($aContext); $d_json = @file_get_contents($URL,false,$cxContext); $d = json_decode($d_json,true); WLog('tencent_sms_log',$d_json); if(isset($d['errmsg']) && $d['errmsg']=='OK'){ return $d; }else{ return $d; } } //发送模板语音短信 public function SendVoiceSms($mobile,$params,$tpl_id) { $random=mt_rand(100000,999999); $URL='https://cloud.tim.qq.com/v5/tlsvoicesvr/sendtvoice?sdkappid='.$this->AppID.'&random='.$random; $time=time(); $string='appkey='.$this->AppKey.'&random='.$random.'&time='.$time.'&mobile='.$mobile; $sign=hash("sha256",$string); $json='{ "tpl_id": '.$tpl_id.', "params": [ "'.$params.'" ], "playtimes":2, "sig": "'.$sign.'", "tel": { "mobile": "'.$mobile.'", "nationcode": "86" }, "time": '.$time.', "ext": "" }'; $aContext = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/json', 'content' => $json)); $cxContext = stream_context_create($aContext); $d_json = @file_get_contents($URL,false,$cxContext); $d = json_decode($d_json,true); WLog('tencent_voice_sms_log',$d_json); if($d['errmsg']=='OK'){ return $d; }else{ return false; } } } ?>