| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- <?php
- // +----------------------------------------------------------------------
- // | ThinkPHP [ WE CAN DO IT JUST THINK ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
- // +----------------------------------------------------------------------
- // | Author: 流年 <liu21st@gmail.com>
- // +----------------------------------------------------------------------
- // 应用公共文件
- function flag_options()
- {
- return ['a' => 'a', 'b' => 'b'];
- }
- function post_json_data($url, $data_string)
- {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- 'Content-Type: application/json; charset=utf-8',
- 'Content-Length: ' . strlen($data_string))
- );
- ob_start();
- curl_exec($ch);
- $return_content = ob_get_contents();
- ob_end_clean();
- $return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- return array('code' => $return_code, 'result' => $return_content);
- }
- $arr = array('a' => '555', 'b' => 56454564);
- //dump(post_json_data('http://192.168.211.1/html/dump.php',json_encode($arr)));
- /**
- * curl
- *
- * @param
- * string url
- * @param
- * array 数据
- * @param
- * int 请求超时时间
- * @param
- * bool HTTPS时是否进行严格认证
- * @return string
- */
- function curl_post_json($url, $data,$timeout=100){
- $CA = false;
- // $url = "http://www.baidu.com";
- $cacert = getcwd() . '/cacert.pem'; // CA根证书
- $SSL = substr($url, 0, 8) == "https://" ? true : false;
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- //var_dump($data);exit;
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout - 2);
- //curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727;cli-test)');
- if ($SSL && $CA) {
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); // 只信任CA颁布的证书
- curl_setopt($ch, CURLOPT_CAINFO, $cacert); // CA根证书(用来验证的网站证书是否是CA颁布)
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // 检查证书中是否设置域名,并且是否与提供的主机名匹配
- } else if ($SSL && !$CA) {
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 信任任何证书
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 检查证书中是否设置域名
- }
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //不输出内容到页面
- // curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- // 'Expect:'
- // ));
- // var_dump($data);
- date_default_timezone_set("UTC");
- $nonce = '66C92B11FF8A425FB8D4CCFE';
- //$nonce = $nonce1 = mt_rand(100000,9999999999);
- $time = time();
- $created = date('Y-m-d', $time) . 'T' . date('H:i:s', $time) . 'Z';
- //$created = '2019-07-10T15:02:08Z';
- $password = '33ab0a75ee246f85e41f2c15d867ca5d';
- $nonce = base64_encode($nonce);// . $created . $password;
- $signRawString = $nonce . $created . $password;//;//
- // echo "明文:", $signRawString,"\n";
- // echo "明文:", $signRawString,"\n";
- //$signRawString = '66C92B11FF8A425FB8D4CCFE2019-07-08T17:56:46Z33ab0a75ee246f85e41f2c15d867ca5d';
- //$signRawString='a';
- //var_dump(hash('sha256',$signRawString,true));exit;
- $passwordDigest = base64_encode(hash('sha256',$signRawString,true));
-
- //echo "明文: $signRawString \n";
- //echo "密文: $passwordDigest \n";
- //exit;
- $headerArr[] = 'Authorization: WSSE realm="SDP", profile="UsernameToken", type="Appkey"';
- $headerArr[] = 'X-WSSE:UsernameToken Username="d9c3190120db4b2ab078a543d59ba47d",PasswordDigest="' . $passwordDigest . '",Nonce="' . $nonce . '",Created="' . $created . '"';
- $headerArr[] = 'Content-Type: application/json; charset=UTF-8';
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArr);
- //var_dump(C('test_proxy'));exit;
- //if(C('test_proxy')) {
- //curl_setopt($ch, CURLOPT_PROXY, '192.168.1.211:8888');
- //}
- $ret = curl_exec($ch);
- if (empty($ret)) {
- var_dump(curl_error($ch)); // 查看报错信息
- }
- // exit('x');
- $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- if ($httpCode != 200) {
- }
- curl_close($ch);
- //var_dump($ret);
- return $ret;
- }
- function curl_post_json_pay($url, $data,$headers=[],$timeout=100){
- $CA = false;
- $cacert = getcwd() . '/cacert.pem'; // CA根证书
- $SSL = substr($url, 0, 8) == "https://" ? true : false;
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_POST, true);
- if(!empty($data)) curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- //var_dump($data);exit;
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout - 2);
- //curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727;cli-test)');
- if ($SSL && $CA) {
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); // 只信任CA颁布的证书
- curl_setopt($ch, CURLOPT_CAINFO, $cacert); // CA根证书(用来验证的网站证书是否是CA颁布)
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // 检查证书中是否设置域名,并且是否与提供的主机名匹配
- } else if ($SSL && !$CA) {
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 信任任何证书
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 检查证书中是否设置域名
- }
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //不输出内容到页面
- date_default_timezone_set("UTC");
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
- //var_dump(C('test_proxy'));exit;
- //if(C('test_proxy')) {
- //curl_setopt($ch, CURLOPT_PROXY, '192.168.16.96:8888');
- //}
- $ret = curl_exec($ch);
- if (empty($ret)) {
- var_dump(curl_error($ch)); // 查看报错信息
- }
- $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- //
- // if ($httpCode != 200) {
- // $tmp = array();
- // $tmp['http_code'] = $httpCode;
- // $tmp['data'] = $ret;
- //
- // //echo "\n服务器错误:$httpCode";
- // //echo $ret;
- // $ret = json_encode($tmp);
- // }
- curl_close($ch);
- //var_dump($ret);
- return $ret;
- }
- /**
- * curl
- *
- * @param
- * string url
- * @param
- * array 数据
- * @param
- * int 请求超时时间
- * @param
- * bool HTTPS时是否进行严格认证
- * @return string
- */
- function curl_post_json_sdk($url, $data,$timeout=100){
- $CA = false;
- // $url = "http://www.baidu.com";
- $cacert = getcwd() . '/cacert.pem'; // CA根证书
- $SSL = substr($url, 0, 8) == "https://" ? true : false;
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- //var_dump($data);exit;
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout - 2);
- //curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727;cli-test)');
- if ($SSL && $CA) {
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); // 只信任CA颁布的证书
- curl_setopt($ch, CURLOPT_CAINFO, $cacert); // CA根证书(用来验证的网站证书是否是CA颁布)
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // 检查证书中是否设置域名,并且是否与提供的主机名匹配
- } else if ($SSL && !$CA) {
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 信任任何证书
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 检查证书中是否设置域名
- }
- //curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- // curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- // 'Expect:'
- // ));
- // var_dump($data);
- $headerArr=[];
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArr);
- //var_dump(C('test_proxy'));exit;
- //if(C('test_proxy')) {
- curl_setopt($ch, CURLOPT_PROXY, '192.168.16.96:8888');
- //}
- $ret = curl_exec($ch);
- if (empty($ret)) {
- var_dump(curl_error($ch)); // 查看报错信息
- }
- // var_dump($ret);
- // exit('x');
- $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- if ($httpCode != 200) {
- $tmp = array();
- $tmp['http_code'] = $httpCode;
- $tmp['data'] = $ret;
- //echo "\n服务器错误:$httpCode";
- //echo $ret;
- $ret = json_encode($tmp);
- }
- curl_close($ch);
- //var_dump($ret);
- return $ret;
- }
- function I(string $key = '', $default = null, $filter = ''){
- return input($key,$default,$filter);
- }
|