日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

阿里云 短信验证

發布時間:2024/3/13 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 阿里云 短信验证 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
/** ????? *?阿里云?短信驗證 ????? *?@param?$phone????手機號碼 ????? *?@param?null?$mobile_code?????驗證碼 ????? *?@param?null?$template_code???短信模版 ????? */ ???? public? function? phoneCode( $phone , $mobile_code =null, $template_code =null){ ???????? if? (! $mobile_code ){ $mobile_code? =? $this ->random(6,1);} ???????? if (! $template_code ){ $template_code = 'SMS_37650042' ;} ???????? $target? =? "https://sms.aliyuncs.com/?" ; ???????? //?注意使用GMT時間 ???????? date_default_timezone_set( "GMT" ); ???????? $dateTimeFormat? =? 'Y-m-d\TH:i:s\Z' ;? //?ISO8601規范 ???????? $accessKeyId? =? 'LTAIGsgBVt8MDTyf' ;?????? //?這里填寫您的Access?Key?ID ???????? $accessKeySecret? =? '5koNqwSpKi0SfjfyHUWqF0lCLIwuoS' ;?? //?這里填寫您的Access?Key?Secret ???????? $ParamString = "{\"code\":\"" . strval ( $mobile_code ). "\",\"time\":\"15\"}" ; ???????? $data? =? array ( ???????????? //?公共參數 ???????????? 'SignName' => '代碼派' , ???????????? 'Format'? =>? 'XML' , ???????????? 'Version'? =>? '2016-09-27' , ???????????? 'AccessKeyId'? =>? $accessKeyId , ???????????? 'SignatureVersion'? =>? '1.0' , ???????????? 'SignatureMethod'? =>? 'HMAC-SHA1' , ???????????? 'SignatureNonce' =>?uniqid(), ???????????? 'Timestamp'? =>? date ( $dateTimeFormat ), ???????????? //?接口參數 ???????????? 'Action'? =>? 'SingleSendSms' , ???????????? 'TemplateCode'? =>? $template_code , ???????????? 'RecNum'? =>? $phone , ???????????? 'ParamString'? =>? $ParamString ???????? ); ???????? //?計算簽名并把簽名結果加入請求參數 ???????? //echo?$data['Version']."<br>"; ???????? //echo?$data['Timestamp']."<br>"; ???????? $data [ 'Signature' ]?=? $this ->computeSignature( $data ,? $accessKeySecret ); ???????? //?發送請求 ???????? $result? =? $this ->xml_to_array( $this ->https_request( $target .http_build_query( $data ))); ???????? print_r( $result ); ???? } ???? public? function? https_request( $url ) ???? { ???????? $curl? =?curl_init(); ???????? curl_setopt( $curl ,?CURLOPT_URL,? $url ); ???????? curl_setopt( $curl ,?CURLOPT_SSL_VERIFYPEER,?FALSE); ???????? curl_setopt( $curl ,?CURLOPT_SSL_VERIFYHOST,?FALSE); ???????? curl_setopt( $curl ,?CURLOPT_RETURNTRANSFER,?1); ???????? $data? =?curl_exec( $curl ); ???????? if? (curl_errno( $curl ))?{ return? 'ERROR?' .curl_error( $curl );} ???????? curl_close( $curl ); ???????? return? $data ; ???? } ???? public? function? xml_to_array( $xml ){ ???????? $reg? =? "/<(\w+)[^>]*>([\\x00-\\xFF]*)<\\/\\1>/" ; ???????? if (preg_match_all( $reg ,? $xml ,? $matches )){ ???????????? $count? =? count ( $matches [0]); ???????????? for ( $i? =?0;? $i? <? $count ;? $i ++){ ???????????????? $subxml =? $matches [2][ $i ]; ???????????????? $key? =? $matches [1][ $i ]; ???????????????? if (preg_match(? $reg ,? $subxml? )){ ???????????????????? $arr [ $key ]?=? $this ->xml_to_array(? $subxml? ); ???????????????? } else { ???????????????????? $arr [ $key ]?=? $subxml ; ???????????????? } ???????????? } ???????? } ???????? return? @ $arr ; ???? } ???? public? function? random( $length? =?6?,? $numeric? =?0)?{ ???????? PHP_VERSION?<? '4.2.0'? &&?mt_srand((double)microtime()?*?1000000); ???????? if ( $numeric )?{ ???????????? $hash? =?sprintf( '%0' . $length . 'd' ,?mt_rand(0,?pow(10,? $length )?-?1)); ???????? }? else? { ???????????? $hash? =? '' ; ???????????? /*?$chars?=?'ABCDEFGHJKLMNPQRSTUVWXYZ23456789abcdefghjkmnpqrstuvwxyz';*/ ???????????? $chars? =? '0123456789' ; ???????????? $max? =? strlen ( $chars )?-?1; ???????????? for ( $i? =?0;? $i? <? $length ;? $i ++)?{ ???????????????? $hash? .=? $chars [mt_rand(0,? $max )]; ???????????? } ???????? } ???????? return? $hash ; ???? } ???? public? function? percentEncode( $str ) ???? { ???????? //?使用urlencode編碼后,將"+","*","%7E"做替換即滿足ECS?API規定的編碼規范 ???????? $res? =?urlencode( $str ); ???????? $res? =?preg_replace( '/\+/' ,? '%20' ,? $res ); ???????? $res? =?preg_replace( '/\*/' ,? '%2A' ,? $res ); ???????? $res? =?preg_replace( '/%7E/' ,? '~' ,? $res ); ???????? return? $res ; ???? } ???? public? function? computeSignature( $parameters ,? $accessKeySecret ) ???? { ???????? //?將參數Key按字典順序排序 ???????? ksort( $parameters ); ???????? //?生成規范化請求字符串 ???????? $canonicalizedQueryString? =? '' ; ???????? foreach ( $parameters? as? $key? =>? $value ) ???????? { ???????????? $canonicalizedQueryString? .=? '&'? .? $this ->percentEncode( $key ) ???????????????? .? '='? .? $this ->percentEncode( $value ); ???????? } ???????? //?生成用于計算簽名的字符串?stringToSign ???????? $stringToSign? =? 'GET&%2F&'? .? $this ->percentencode( substr ( $canonicalizedQueryString ,?1)); ???????? //echo?"<br>".$stringToSign."<br>"; ???????? //?計算簽名,注意accessKeySecret后面要加上字符'&' ???????? $signature? =? base64_encode (hash_hmac( 'sha1' ,? $stringToSign ,? $accessKeySecret? .? '&' ,?true)); ???????? return? $signature ; ???? }

總結

以上是生活随笔為你收集整理的阿里云 短信验证的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。