123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- function curl_post1($url, $data = []) {
- $ch = curl_init ();
- $header = array ("Accept-Charset: utf-8",'Expect:' );
- curl_setopt ( $ch, CURLOPT_URL, $url );
- curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, "POST" );
- curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
- // curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
- // curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, FALSE );
- curl_setopt ( $ch, CURLOPT_HTTPHEADER, $header );
- curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
- curl_setopt($ch, CURLOPT_ENCODING, "gzip");
- curl_setopt ( $ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36
- 15 Accept-Encoding: gzip,deflate,sdch' );
- curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, false );
- // curl_setopt ( $ch, CURLOPT_AUTOREFERER, 1 );
- curl_setopt ( $ch, CURLOPT_TIMEOUT, 10 );
- // 最好加上http_build_query 转换,防止有些服务器不兼容
- if($data){
- curl_setopt ( $ch, CURLOPT_POSTFIELDS, http_build_query ( $data ) );
- }
- curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
- $result = curl_exec ( $ch );
- curl_close ( $ch );
- return $result;
- }
- function curl_post($url, $data = []) {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
- curl_setopt($ch, CURLOPT_POST, 1);
- if($data){
- curl_setopt ( $ch, CURLOPT_POSTFIELDS, http_build_query ( $data ) );
- }
- $output = curl_exec($ch);
- curl_close($ch);
- return $output;
- }
- /**
- * AES 128 ecb 加密 与java加密保持一致
- * @param $data 加密字符串
- * @param $key 加密key
- * @return string 加密串
- */
- function aes_encrypt($data, $key='') {
- if(!$key){
- $key = get_instance()->config->item('encryption_key');
- }
- $data = openssl_encrypt($data, 'aes-128-ecb', $key, OPENSSL_RAW_DATA);
- return base64_encode($data);
- }
- /**
- * AES 128 ecb 解密 与java加密保持一致
- * @param $data 解密字符串
- * @param $key 加密key
- * @return string 解密串
- */
- function aes_decrypt($data, $key='') {
- if(!$key){
- $key = get_instance()->config->item('encryption_key');
- }
- $encrypted = base64_decode($data);
- return openssl_decrypt($encrypted, 'aes-128-ecb', $key, OPENSSL_RAW_DATA);
- }
- /**
- * 多维数组键值下划线转换为驼峰
- * @param $arr
- * @return array
- */
- function array_change_line_to_hump($arr){
- if(!is_array($arr)){
- return $arr;
- }
- $tem = [];
- foreach ($arr as $k=>$v){
- if(is_array($v)){
- $tem[line_to_hump($k)] = array_change_line_to_hump($v);
- }else{
- $tem[line_to_hump($k)] = $v;
- }
- }
- return $tem;
- }
- /**
- * 驼峰转下划线
- * @param $str
- * @return string|string[]|null
- */
- function hump_to_line($str){
- return preg_replace_callback('/([A-Z])/', function ($match) {
- return '_' . lcfirst($match[0]);
- }, $str);
- }
- /**
- * 下划线转驼峰
- * @param $str
- * @return string|string[]|null
- */
- function line_to_hump($str){
- $str = strtolower($str);
- return preg_replace_callback('/(_[a-z])/', function ($match) {
- return ucfirst(trim($match[0], '_'));
- }, $str);
- }
|