标签:
1 $ali = array( 2 ‘service‘ => ‘mobile.securitypay.pay‘, 3 ‘partner‘ => ‘xxxxxxxxxx‘,// 4 ‘_input_charset‘ => ‘utf-8‘, 5 ‘sign_type‘ => ‘RSA‘, 6 ‘sign‘ => ‘‘, 7 ‘notify_url‘ => urlencode($url),//回调地址 8 ‘out_trade_no‘ => $ordernu,//商户网站唯一订单号 9 ‘subject‘ => $cpPayName,//商品名称 10 ‘payment_type‘ => 1,//支付类型 11 ‘seller_id‘ => ‘‘,//支付宝账号 12 ‘total_fee‘ => $cpPrice,//总金额 13 ‘body‘ => $cpPayName,//商品详情 14 ); 15 $ali = argSort($ali); 16 $str = ‘‘; 17 18 foreach($ali as $key=>$val){ 19 if($key == ‘sign_type‘ || $key == ‘sign‘){ 20 continue; 21 }else{ 22 if($str == ‘‘){ 23 $str = $key.‘=‘.‘"‘.$val.‘"‘; 24 }else{ 25 $str = $str.‘&‘.$key.‘=‘.‘"‘.$val.‘"‘; 26 } 27 } 28 } 29 30 31 $sign = urlencode(sign($str)); 32 $str = $str.‘&sign=‘.‘"‘.$sign.‘"‘.‘&sign_type=‘.‘"‘.$ali[‘sign_type‘].‘"‘;//传给支付宝接口的数据 33 34 35 function argSort($para) { 35 ksort($para); 36 reset($para); 37 return $para; 38 } 39 40 //RSA签名 41 function sign($data) { 42 43 //读取私钥文件 44 45 $priKey = file_get_contents(‘key/rsa_private_key.pem‘);//私钥文件路径 46 //转换为openssl密钥,必须是没有经过pkcs8转换的私钥 47 48 $res = openssl_get_privatekey($priKey); 49 50 //调用openssl内置签名方法,生成签名$sign 51 52 openssl_sign($data, $sign, $res); 53 54 55 //释放资源 56 57 openssl_free_key($res); 58 59 60 //base64编码 61 62 $sign = base64_encode($sign); 63 64 return $sign; 65 66 }
标签:
原文地址:http://www.cnblogs.com/simayubo/p/5110952.html