Heim >Backend-Entwicklung >PHP-Tutorial >支付宝支付错误返回ILLEGAL_SIGN,签名验证错误
用的是ECSHOP商城框架,在本地测试(windows系统)的时候,正常交易。但到了生产环境(Centos系统)后,支付宝就会报ILLEGAL_SIGN(签名验证错误)错误。网上看过一些解决方法,但都没作用。下面是生成支付宝支付代码的代码:
<code> function get_code($order, $payment) { if (!defined('EC_CHARSET')) { $charset = 'utf-8'; } else { $charset = EC_CHARSET; } $real_method = $payment['alipay_pay_method']; switch ($real_method){ case '0': $service = 'trade_create_by_buyer'; break; case '1': $service = 'create_partner_trade_by_buyer'; break; case '2': $service = 'create_direct_pay_by_user'; break; } $parameter = array( 'agent' => $payment['alipay_agent'], 'service' => $service, 'partner' => $payment['alipay_partner'], //'partner' => ALIPAY_ID, '_input_charset' => $charset, 'notify_url' => return_url(basename(__FILE__, '.php')), 'return_url' => return_url(basename(__FILE__, '.php')), /* 业务参数 */ 'subject' => $order['order_sn'], 'out_trade_no' => $order['order_sn'] . $order['log_id'], 'extra_common_param'=> !empty($order['all_pay'])?$order['all_pay']:0, //判断是不是合并付款 add by ouzhiming 'price' => $order['order_amount'], 'quantity' => 1, 'payment_type' => 1, /* 物流参数 */ 'logistics_type' => 'EXPRESS', 'logistics_fee' => 0, 'logistics_payment' => 'BUYER_PAY_AFTER_RECEIVE', /* 买卖双方信息 */ 'seller_email' => $payment['alipay_account'] ); ksort($parameter); reset($parameter); $param = ''; $sign = ''; foreach ($parameter AS $key => $val) { $param .= "$key=" .urlencode($val). "&"; $sign .= "$key=$val&"; } $param = substr($param, 0, -1); $sign = substr($sign, 0, -1).$payment['alipay_key']; //$sign = substr($sign, 0, -1). ALIPAY_AUTH; $button = '<div style="text-align:center"><input type="button" class="pay_button" onclick="window.open(\'https://www.alipay.com/cooperate/gateway.do?'.$param. '&sign='.md5($sign).'&sign_type=MD5\')" value="' .$GLOBALS['_LANG']['pay_button']. '"></div>'; return $button; } </code>
用的是ECSHOP商城框架,在本地测试(windows系统)的时候,正常交易。但到了生产环境(Centos系统)后,支付宝就会报ILLEGAL_SIGN(签名验证错误)错误。网上看过一些解决方法,但都没作用。下面是生成支付宝支付代码的代码:
<code> function get_code($order, $payment) { if (!defined('EC_CHARSET')) { $charset = 'utf-8'; } else { $charset = EC_CHARSET; } $real_method = $payment['alipay_pay_method']; switch ($real_method){ case '0': $service = 'trade_create_by_buyer'; break; case '1': $service = 'create_partner_trade_by_buyer'; break; case '2': $service = 'create_direct_pay_by_user'; break; } $parameter = array( 'agent' => $payment['alipay_agent'], 'service' => $service, 'partner' => $payment['alipay_partner'], //'partner' => ALIPAY_ID, '_input_charset' => $charset, 'notify_url' => return_url(basename(__FILE__, '.php')), 'return_url' => return_url(basename(__FILE__, '.php')), /* 业务参数 */ 'subject' => $order['order_sn'], 'out_trade_no' => $order['order_sn'] . $order['log_id'], 'extra_common_param'=> !empty($order['all_pay'])?$order['all_pay']:0, //判断是不是合并付款 add by ouzhiming 'price' => $order['order_amount'], 'quantity' => 1, 'payment_type' => 1, /* 物流参数 */ 'logistics_type' => 'EXPRESS', 'logistics_fee' => 0, 'logistics_payment' => 'BUYER_PAY_AFTER_RECEIVE', /* 买卖双方信息 */ 'seller_email' => $payment['alipay_account'] ); ksort($parameter); reset($parameter); $param = ''; $sign = ''; foreach ($parameter AS $key => $val) { $param .= "$key=" .urlencode($val). "&"; $sign .= "$key=$val&"; } $param = substr($param, 0, -1); $sign = substr($sign, 0, -1).$payment['alipay_key']; //$sign = substr($sign, 0, -1). ALIPAY_AUTH; $button = '<div style="text-align:center"><input type="button" class="pay_button" onclick="window.open(\'https://www.alipay.com/cooperate/gateway.do?'.$param. '&sign='.md5($sign).'&sign_type=MD5\')" value="' .$GLOBALS['_LANG']['pay_button']. '"></div>'; return $button; } </code>
建议你看看是不是大小写的问题。方法的大小写。类的大小写。参数的大小写。