Jamers Posted November 14, 2014 Report Share Posted November 14, 2014 银行支票支付密码是一组4*4位的十进制数,参数为设备、支票号、日期、金额生成唯一的密码,支付时只需要将支付密码核对一下即可确认是否正确。近来无 事,随意写了一个函数,当然这个算出来的密码想付钱是不可能的,哈哈,纯粹演示。结尾处还有个guid生成的函数,可以将程序改成如果无GUID自动生成 一个。 <?php $id = ['{4F22D4F8-E600-4D15-BCAC-F987E27A4BBC}']; $date = '2014-6-19'; $ta = [['1034890901','20000'],['1034890901','20001'],['1034890902','30000']]; foreach ($ta as $v) { echo general_pass($id,$date,$v[0],$v[1])." {$date},{$v[0]},{$v[1]}".'<br>'; } //echo general_pass(['{4233D4B1-3704-41BB-AC56-F6921D27C59F}'],'2014-6-19','10334890901','10000.2'); function general_pass($guid,$date,$no,$money) { //演示生成支票密码函数 //$guid 设备编码 $date 日期 $no 支票编号 $money 金额 //生成密码 4组 4位十进制数字 $gid = GUID2Value($guid); $md = strtotime($date); $yy = intval(date('Y',$md)); $mm = intval(date('m',$md)); $dd = intval(date('d',$md)); $no = intval($no); $mo = intval(round($money,0)); $r = array(); $r[0] = ((($gid & 0xffffff)-($no*($yy+$mm-$dd)))*intval($mo/2))%10000; $r[1] = (($gid >> 2 & 0xfffffff) + $no - ($yy+($mm*$dd)) + $mo*2)%10000; $r[2] = (($gid >> 4 & 0xfffff) - $no - $yy - $mm*$mo + $dd)%10000; $r[3] = (($gid >> 3 & 0xffffff) - $no + $mo*($yy+$mm+$dd)*2) % 10000; foreach ($r as $k => $v) { $r[$k] = abs($v); } return sprintf('%04d-%04d-%04d-%04d',$r[0],$r[1],$r[2],$r[3]); } function GUID2Value($guid) { //组合值 $aa = array(1024,308,999,2048,10240); if (is_array($guid)) { $id = substr($guid[0],1,-1); } if (is_string($guid)) { if (strpos($guid,'}')>0) { $id = substr($guid,1,-1); }else{ $id = trim($guid); } } if ($id == '') return 0; $fa = explode('-',$id); $result = 0; foreach ($fa as $k=>$v) { $t = str_split($v,4); $x = 0; foreach ($t as $m) { $x += hexdec($m); } $result += $x*$aa[$k]; } $result &= 0xffffffff; //echo dechex($result); return $result; } function guid(){ if (function_exists('com_create_guid')){ return com_create_guid(); }else{ mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up. $charid = strtoupper(md5(uniqid(rand(), true))); $hyphen = chr(45);// "-" $uuid = chr(123)// "{" .substr($charid, 0, 8).$hyphen .substr($charid, 8, 4).$hyphen .substr($charid,12, 4).$hyphen .substr($charid,16, 4).$hyphen .substr($charid,20,12) .chr(125);// "}" return $uuid; } } ?> Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now