| $a=time();$b=substr($a, 1);$orderid= $b.mt_rand(10000,99999);$mygoods['partner']="2088011744308664";$mygoods['seller']="2088011744308664";$mygoods['out_trade_no']=$orderid;$mygoods['subject']=$goods_name;$mygoods['body']=$goods_infro;$mygoods['total_fee']=$score;$mygoods['notify_url']= "http://211.149.220.47/php/notify_url.php";$mygoods = argSort($mygoods);$mystr = createLinkstring($mygoods);$sign = rsaSign($mystr);$sign = urlencode($sign);$orderInfor = $mystr."&sign=".$sign."&sign_type=RSA"; $str = 'body=%E7%B2%BE%E5%93%81%E5%84%BF%E7%AB%A5%E4%B9%A6%E5%8C%85%E5%96%9C%E6%B4%8B%E6%B4%8B%E7%9A%84¬ify_url=http%3A%2F%2F211.149.220.47%2Fphp%2Fnotify_url.php&out_trade_no=40609294027478&partner=2088011744308664&seller=2088011744308664&subject=%E4%B9%A6%E5%8C%85&success=true&total_fee=0.01'; $sign = 'Itorzqous2F7kYWWOpmoB%2FJUYgySRzh%2FOOKMhVhv%2BM48CnFk%2BQCp2cKcSsNGcDTs2AsAk%2BRYTuyMYZkGH56t8jcV2GGFkrJr%2FPxcGRlEK08QadAhImYzy9piVjoW0102lhSJYapiXGBTl5eiZ88RiyRA62D2nJEtH%2FBVXpuq63A%3D'; $sign = urldecode($sign);$str = urldecode($str);var_dump(verify($str, $sign)); function createLinkstring($para) { $arg = ""; while (list ($key, $val) = each ($para)) { $arg.=$key."=".$val."&"; } $arg = substr($arg,0,count($arg)-2); if(get_magic_quotes_gpc()){$arg = stripslashes($arg);} return $arg;} function argSort($para) { ksort($para); reset($para); return $para;} function rsaSign($data, $private_key_path) { $priKey = file_get_contents($private_key_path); $res = openssl_get_privatekey($priKey); openssl_sign($data, $sign, $res); openssl_free_key($res); $sign = base64_encode($sign); return $sign;} function verify($data, $sign) { $pubKey = file_get_contents('key/alipay_public_key.pem'); $res = openssl_get_publickey($pubKey); $result = (bool)openssl_verify($data, base64_decode($sign), $res); openssl_free_key($res); return $result;} |