支付宝PHP版本5.3兼容

PHP5.3 支付宝会报这两个错

 Use of undefined constant OPENSSL_ALGO_SHA256 - assumed 'OPENSSL_ALGO_SHA256'

Use of undefined constant JSON_UNESCAPED_UNICODE - assumed 'JSON_UNESCAPED_UNICODE'

解决方案

1. php 5.3  没有这个,那么  只需要 OPENSSL_ALGO_SHA256 改为 "sha256WithRSAEncryption" 

2.json_encode  自己写个function ,不用PHP自带的json_encode

function my_json_encode($array)
    {
        if(version_compare(PHP_VERSION,'5.4.0','<')){
            $str = json_encode($array);
            $str = preg_replace_callback("#\\\u([0-9a-f]{4})#i",function($matchs){
                 return iconv('UCS-2BE', 'UTF-8', pack('H4', $matchs[1]));
            },$str);
            return $str;
        }else{
            return json_encode($array, JSON_UNESCAPED_UNICODE);
        }
    }

猜你喜欢

转载自blog.csdn.net/abc564643122/article/details/79530767