新版sdk下载下来了,集成了很多东西,自己看很烦,不多说了,我在源码上写了两个类AliSms.class.phpclassAliSms{//网上的地址constAPI_DOAMIN='http://dysmsapi.aliyuncs.com/';protected$env;protected$accesskey;protected$secretKey;protectedstatic$method='POST';protectedstatic$header=array('x-sdk-client'=>'php/2.0.0',);//30secondpublicstatic$connectTimeout=30;//80secondpublicstatic$readTimeout=80;//公共参数受保护$requestParams=array();公共函数__construct($accessKey,$secretKey){$this->accesskey=$accessKey;$this->secretKey=$secretKey;$this->requestParams["AccessKeyId"]=$this->accesskey;$this->requestParams["RegionId"]='cn-杭州';$this->requestParams["格式"]='JSON';$this->requestParams["SignatureMethod"]='HMAC-SHA1';$this->requestParams["SignatureVersion"]='1.0';$this->requestParams["SignatureNonce"]=uniqid();date_default_timezone_set("GMT");$this->requestParams["Timestamp"]=date('Y-m-d\TH:i:s\Z');$this->requestParams["Action"]='SendSms';$this->requestParams["Version"]='2017-05-25';}/***发送短信*@param$phoneNumbers电话号码*@param$signName短信签名*@param$templateCode短信模板代码*@param$tempalteParamSMS模板参数*@returnHttpResponse*@throws\Think\Exception*/publicfunctionexecute($phoneNumbers,$signName,$templateCode,$tempalteParam){$params=array('PhoneNumbers'=>$phoneNumbers,'SignName'=>$signName,'TemplateCode'=>$templateCode,'TemplateParam'=>$tempalteParam,);if(empty($params['PhoneNumbers'])){thrownewException('缺少参数PhoneNumbers');}if(empty($params['SignName'])){thrownewException('缺少参数SignName');}if(empty($params['TemplateCode'])){thrownewException('缺少参数TemplateCode');}if(empty($params['TemplateParam'])){thrownewException('缺少参数TemplateParam');}foreach($paramsas$key=>$value){$apiParams[$key]=$this->prepareValue($value);}$params=array_merge($params,$this->requestParams);$params["Signature"]=$this->computeSignature($params,$this->secretKey);$response=$this->curl(self::API_DOAMIN,self::$method,$params,self::$header);return$response;}//计算签名publicfunctioncomputeSignature($parameters,$accessKeySecret){ksort($parameters);$canonicalizedQueryString='';foreach($parametersas$key=>$value){$canonicalizedQueryString.='&'.$this->percentEncode($key)。'='。$this->percentEncode($value);$stringToSign=self::$method.'&%2F&'。$this->percentencode(substr($canonicalizedQueryString,1));$signature=base64_encode(hash_hmac('sha1',$stringToSign,$accessKeySecret."&",true));返回$signature;}私有函数prepareValue($value){如果(is_bool($value)){如果($value){返回“真”;}else{返回“假”;}}else{返回$值;}}publicfunctionpercentEncode($str){$res=urlencode($str);$res=preg_replace('/\+/','%20',$res);$res=preg_replace('/\*/','%2A',$res);$res=preg_replace('/%7E/','~',$res);return$res;}/***网络请求*@param$url*@paramstring$httpMethod*@paramnull$postFields*@paramnull$headers*@returnmixed*@throws\Think\Exception*/publicfunctioncurl($url,$httpMethod="GET",$postFields=null,$headers=null){$ch=curl_init();curl_setopt($ch,CURLOPT_CUSTOMREQUEST,$httpMethod);curl_setopt($ch,CURLOPT_URL,$url);curl_setopt($ch,CURLOPT_FAILONERROR,false);curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);curl_setopt($ch,CURLOPT_POSTFIELDS,is_array($postFields)?self::getPostHttpBody($postFields):$postFields);如果(自我::$readTimeout){curl_setopt($ch,CURLOPT_TIMEOUT,self::$readTimeout);}if(self::$connectTimeout){curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,self::$connectTimeout);}//https请求if(strlen($url)>5&&strtolower(substr($url,0,5))=="https"){curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);}if(is_array($headers)&&0
