Home  >  Article  >  Backend Development  >  Get unique device identifier

Get unique device identifier

WBOY
WBOYOriginal
2016-08-08 09:29:523507browse

Under Cocos2dx, include the header file

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 (transfer)

<?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;
	}
	
?>

The above introduces how to obtain the unique device identifier, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn