首頁  >  文章  >  後端開發  >  取得唯一設備識別符

取得唯一設備識別符

WBOY
WBOY原創
2016-08-08 09:29:523549瀏覽

Cocos2dx下,包含頭檔

std::string uid = "";
    uuid_t uu;
    int i;
    uuid_generate(uu);
    for (i = 0; i < 16; i ++) {
        char aa[10]="";
        sprintf(aa, "%02X",uu[i]);
        uid+=aa;
    }
    return uid;

php下(轉)

<?php
	function create_guid(){
		$micortime = microtime();
		list($a_dec,$a_sec) = explode(" ", $micortime);
		$dec_hex = dechex($a_dec*1000000);
		$sec_hex = dechex($a_sec);
		ensure_length($dec_hex, 5);
		ensure_length($sec_hex, 6);
		$guid = "";
		$guid.=$dec_hex;
		$guid.=create_guid_section(3);
		$guid.=&#39;-&#39;;
		$guid.=create_guid_section(4);
		$guid.=&#39;-&#39;;
		$guid.=create_guid_section(4);
		$guid.=&#39;-&#39;;
		$guid.=create_guid_section(4);
		$guid.=&#39;-&#39;;
		$guid.=$sec_hex;
		$guid.=create_guid_section(6);
		return $guid;
	}
	
	function ensure_length(&$string,$length){
		$strlen = strlen($string);
		if ($strlen<$length) {
			$string = str_pad($string, $length,"0");
		}
		elseif ($strlen>$length){
			$string = substr($string, 0,$length);
		}
	}
	
	function create_guid_section($characters){
		$return = "";
		for ($i = 0;$i < $characters;$i++){
			$return.=dechex(mt_rand(0, 15));
		}
		return $return;
	}
	
?>

以上就介紹了取得唯一設備標識符,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn