




已阅读5页,还剩39页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
urlencode($key),num=urlencode($num),show=urlencode($show),);foreach($fieldsas$key=$value)$fields_string.=$key.=.$value.&;/把变量组装成username=mayuchao&password=123456&成功了mayuchao密码laoma这个格式rtrim($fields_string,&);/从末端开始去掉删除多余&符号$ch=curl_init();/开启一个curl对话curl_setopt($ch,CURLOPT_URL,$url);/把要对话的url地址设置好curl_setopt($ch,CURLOPT_POST,count($fields);/把要发送的变量数量设置好curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);/把要post的变量url组装好化后设置好curl_exec($ch);/执行上面设置好的一个curl操作,把变量数据发送完后,返回的是ok.php页面获得post变量执行后的结果curl_close($ch);/关闭curl对话?secretKey;foreach($paramsas$k=$v)if(!=substr($v,0,1)$stringToBeSigned.=$k$v;unset($k,$v);$stringToBeSigned.=$this-secretKey;returnstrtoupper(md5($stringToBeSigned);protectedfunctioncurl($url,$postFields=null)$ch=curl_init();curl_setopt($ch,CURLOPT_URL,$url);curl_setopt($ch,CURLOPT_FAILONERROR,false);curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);if(is_array($postFields)&0$v)if(!=substr($v,0,1)/判断是不是文件上传$postBodyString.=$k=.urlencode($v).&;else/文件上传用multipart/form-data,否则用www-form-urlencoded$postMultipart=true;unset($k,$v);curl_setopt($ch,CURLOPT_POST,true);if($postMultipart)curl_setopt($ch,CURLOPT_POSTFIELDS,$postFields);elsecurl_setopt($ch,CURLOPT_POSTFIELDS,substr($postBodyString,0,-1);$reponse=curl_exec($ch);if(curl_errno($ch)thrownewException(curl_error($ch),0);else$httpStatusCode=curl_getinfo($ch,CURLINFO_HTTP_CODE);if(200!=$httpStatusCode)thrownewException($reponse,$httpStatusCode);curl_close($ch);return$reponse;protectedfunctionlogCommunicationError($apiName,$requestUrl,$errorCode,$responseTxt)$localIp=isset($_SERVERSERVER_ADDR)?$_SERVERSERVER_ADDR:CLI;$logger=newLtLogger;$logger-conflog_file=rtrim(TOP_SDK_WORK_DIR,/)./.logs/top_comm_err_.$this-appkey._.date(Y-m-d).log;$logger-confseparator=_;$logData=array(date(Y-m-dH:i:s),$apiName,$this-appkey,$localIp,PHP_OS,$this-sdkVersion,$requestUrl,$errorCode,str_replace(n,$responseTxt);$logger-log($logData);publicfunctionexecute($request,$session=null)if($this-checkRequest)try$request-check();catch(Exception$e)$result-code=$e-getCode();$result-msg=$e-getMessage();return$result;/组装系统参数$sysParamsapp_key=$this-appkey;$sysParamsv=$this-apiVersion;$sysParamsformat=$this-format;$sysParamssign_method=$this-signMethod;$sysParamsmethod=$request-getApiMethodName();$sysParamstimestamp=date(Y-m-dH:i:s);$sysParamspartner_id=$this-sdkVersion;if(null!=$session)$sysParamssession=$session;/获取业务参数$apiParams=$request-getApiParas();/签名$sysParamssign=$this-generateSign(array_merge($apiParams,$sysParams);/系统参数放入GET请求串$requestUrl=$this-gatewayUrl.?;foreach($sysParamsas$sysParamKey=$sysParamValue)$requestUrl.=$sysParamKey=.urlencode($sysParamValue).&;$requestUrl=substr($requestUrl,0,-1);/发起HTTP请求try$resp=$this-curl($requestUrl,$apiParams);catch(Exception$e)$this-logCommunicationError($sysParamsmethod,$requestUrl,HTTP_ERROR_.$e-getCode(),$e-getMessage();$result-code=$e-getCode();$result-msg=$e-getMessage();return$result;/解析TOP返回结果$respWellFormed=false;if(json=$this-format)$respObject=json_decode($resp);if(null!=$respObject)$respWellFormed=true;foreach($respObjectas$propKey=$propValue)$respObject=$propValue;elseif(xml=$this-format)$respObject=simplexml_load_string($resp);if(false!=$respObject)$respWellFormed=true;/返回的HTTP文本不是标准JSON或者XML,记下错误日志if(false=$respWellFormed)$this-logCommunicationError($sysParamsmethod,$requestUrl,HTTP_RESPONSE_NOT_WELL_FORMED,$resp);$result-code=0;$result-msg=HTTP_RESPONSE_NOT_WELL_FORMED;return$result;/如果TOP返回了错误码,记录到业务错误日志中if(isset($respObject-code)$logger=newLtLogger;$logger-conflog_file=rtrim(TOP_SDK_WORK_DIR,/)./.logs/top_biz_err_.$this-appkey._.date(Y-m-d).log;$logger-log(array(date(Y-m-dH:i:s),$resp);return$respObject;publicfunctionexec($paramsArray)if(!isset($paramsArraymethod)trigger_error(Noapinamepassed);$inflector=newLtInflector;$inflector-confseparator=.;$requestClassName=ucfirst($inflector-camelize(substr($paramsArraymethod,7).Request;if(!class_exists($requestClassName)trigger_error(Nosuchapi:.$paramsArraymethod);$session=isset($paramsArraysession)?$paramsArraysession:null;$req=new$requestClassName;foreach($paramsArrayas$paraKey=$paraValue)$inflector-confseparator=_;$setterMethodName=$inflector-camelize($paraKey);$inflector-confseparator=.;$setterMethodName=set.$inflector-camelize($setterMethodName);if(method_exists($req,$setterMethodName)$req-$setterMethodName($paraValue);return$this-execute($req,$session);?以下为引用的内容:/创建两个cURL资源$ch1=curl_init();$ch2=curl_init();/指定URL和适当的参数curl_setopt($ch1,CURLOPT_URL,/);curl_setopt($ch1,CURLOPT_HEADER,0);curl_setopt($ch2,CURLOPT_URL,/);curl_setopt($ch2,CURLOPT_HEADER,0);/创建cURL批处理句柄$mh=curl_multi_init();/加上前面两个资源句柄curl_multi_add_handle($mh,$ch1);curl_multi_add_handle($mh,$ch2);/预定义一个状态变量$active=null;/执行批处理do$mrc=curl_multi_exec($mh,$active);while($mrc=CURLM_CALL_MULTI_PERFORM);while($active&$mrc=CURLM_OK)if(curl_multi_select($mh)!=-1)do$mrc=curl_multi_exec($mh,$active);while($mrc=CURLM_CALL_MULTI_PERFORM);/关闭各个句柄curl_multi_remove_handle($mh,$ch1);curl_multi_remove_handle($mh,$ch2);curl_multi_close($mh);这里要做的就是打开多个cURL句柄并指派给一个批处理句柄。然后你就只需在一个while循环里等它执行完毕。这个示例中有两个主要循环。第一个do-while循环重复调用curl_multi_exec()。这个函数是无隔断(non-blocking)的,但会尽可能少地执行。它返回一个状态值,只要这个值等于常量CURLM_CALL_MULTI_PERFORM,就代表还有一些刻不容缓的工作要做(例如,把对应URL的http头信息发送出去)。也就是说,我们需要不断调用该函数,直到返回值发生改变。而接下来的while循环,只在$active变量为true时继续。这一变量之前作为第二个参数传给了curl_multi_exec(),代表只要批处理句柄中是否还有活动连接。接着,我们调用curl_multi_select(),在活动连接(例如接受服务器响应)出现之前,它都是被“屏蔽”的。这个函数成功执行后,我们又会进入另一个do-while循环,继续下一条URL?php/*Snoopy-thePHPnetclientAuthor:MonteOhrtCopyright(c):1999-2000ispi,allrightsreservedVersion:1.01*Thislibraryisfreesoftware;youcanredistributeitand/or*modifyitunderthetermsoftheGNULesserGeneralPublic*LicenseaspublishedbytheFreeSoftwareFoundation;either*version2.1oftheLicense,or(atyouroption)anylaterversion.*Thislibraryisdistributedinthehopethatitwillbeuseful,*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.SeetheGNU*LesserGeneralPublicLicenseformoredetails.*YoushouldhavereceivedacopyoftheGNULesserGeneralPublic*Licensealongwiththislibrary;ifnot,writetotheFreeSoftware*Foundation,Inc.,59TemplePlace,Suite330,Boston,MA02111-1307USAYoumaycontacttheauthorofSnoopybye-mailat:Or,writeto:MonteOhrtCTO,ispi237S.70thsuite220Lincoln,NE68510ThelatestversionofSnoopycanbeobtainedfrom:/*/classSnoopy/*Publicvariables*/*userdefinablevars*/var$host=;/hostnameweareconnectingtovar$port=80;/portweareconnectingtovar$proxy_host=;/proxyhosttousevar$proxy_port=;/proxyporttousevar$proxy_user=;/proxyusertousevar$proxy_pass=;/proxypasswordtousevar$agent=Snoopyv1.2.3;/agentwemasqueradeasvar$referer=;/refererinfotopassvar$cookies=array();/arrayofcookiestopass/$cookiesusername=joe;var$rawheaders=array();/arrayofrawheaders/$rawheadersContent-type=text/html;var$maxredirs=5;/httpredirectiondepthmaximum.0=disallowvar$lastredirectaddr=;/containsaddressoflastredirectedaddressvar$offsiteok=true;/allowsredirectionoff-sitevar$maxframes=0;/framecontentdepthmaximum.0=disallowvar$expandlinks=true;/expandlinkstofullyqualifiedURLs./thisonlyappliestofetchlinks()/submitlinks(),andsubmittext()var$passcookies=true;/passsetcookiesbackthroughredirects/NOTE:thiscurrentlydoesnotrespect/dates,domainsorpaths.var$user=;/userforhttpauthenticationvar$pass=;/passwordforhttpauthentication/httpaccepttypesvar$accept=image/gif,image/x-xbitmap,image/jpeg,image/pjpeg,*/*;var$results=;/wherethecontentisputvar$error=;/errormessagessentherevar$response_code=;/responsecodereturnedfromservervar$headers=array();/headersreturnedfromserversentherevar$maxlength=500000;/maxreturndatalength(body)var$read_timeout=0;/timeoutonreadoperations,inseconds/supportedonlysincePHP4Beta4/setto0todisallowtimeoutsvar$timed_out=false;/ifareadoperationtimedoutvar$status=0;/httprequeststatusvar$temp_dir=/tmp;/temporarydirectorythatthewebserver/haspermissiontowriteto./underWindows,thisshouldbeC:tempvar$curl_path=/usr/local/bin/curl;/SnoopywillusecURLforfetching/SSLcontentifafullsystempathto/thecURLbinaryissuppliedhere./settofalseifyoudonothave/cURLinstalled.Seehttp:/curl.haxx.se/fordetailsoninstallingcURL./Snoopydoes*not*usethecURL/libraryfunctionsbuiltintophp,/asthesefunctionsarenotstable/asofthisSnoopyrelease./*Privatevariables*/var$_maxlinelen=4096;/maxlinelength(headers)var$_httpmethod=GET;/defaulthttprequestmethodvar$_httpversion=HTTP/1.0;/defaulthttprequestversionvar$_submit_method=POST;/defaultsubmitmethodvar$_submit_type=application/x-www-form-urlencoded;/defaultsubmittypevar$_mime_boundary=;/MIMEboundaryformultipart/form-datasubmittypevar$_redirectaddr=false;/willbesetifpagefetchedisaredirectvar$_redirectdepth=0;/incrementsonanhttpredirectvar$_frameurls=array();/framesrcurlsvar$_framedepth=0;/incrementsonframedepthvar$_isproxy=false;/setifusingaproxyservervar$_fp_timeout=30;/timeoutforsocketconnection/*=Function:fetchPurpose:fetchthecontentsofawebpage(andpossiblyotherprotocolsinthefuturelikeftp,nntp,gopher,etc.)Input:$URIthelocationofthepagetofetchOutput:$this-resultstheoutputtextfromthefetch=*/functionfetch($URI)/preg_match(|(:+):/(:/+)(:d+)*(.*)|,$URI,$URI_PARTS);$URI_PARTS=parse_url($URI);if(!empty($URI_PARTSuser)$this-user=$URI_PARTSuser;if(!empty($URI_PARTSpass)$this-pass=$URI_PARTSpass;if(empty($URI_PARTSquery)$URI_PARTSquery=;if(empty($URI_PARTSpath)$URI_PARTSpath=;switch(strtolower($URI_PARTSscheme)casehttp:$this-host=$URI_PARTShost;if(!empty($URI_PARTSport)$this-port=$URI_PARTSport;if($this-_connect($fp)if($this-_isproxy)/usingproxy,sendentireURI$this-_httprequest($URI,$fp,$URI,$this-_httpmethod);else$path=$URI_PARTSpath.($URI_PARTSquery?.$URI_PARTSquery:);/noproxy,sendonlythepath$this-_httprequest($path,$fp,$URI,$this-_httpmethod);$this-_disconnect($fp);if($this-_redirectaddr)/*urlwasredirected,checkifwevehitthemaxdepth*/if($this-maxredirs$this-_redirectdepth)/onlyfollowredirectifitsonthissite,oroffsiteokistrueif(preg_match(|http:/.preg_quote($this-host).|i,$this-_redirectaddr)|$this-offsiteok)/*followtheredirect*/$this-_redirectdepth+;$this-lastredirectaddr=$this-_redirectaddr;$this-fetch($this-_redirectaddr);if($this-_framedepthmaxframes&count($this-_frameurls)0)$frameurls=$this-_frameurls;$this-_frameurls=array();while(list(,$frameurl)=each($frameurls)if($this-_framedepthmaxframes)$this-fetch($frameurl);$this-_framedepth+;elsebreak;elsereturnfalse;returntrue;break;casehttps:if(!$this-curl_path)returnfalse;if(function_exists(is_executable)if(!is_executable($this-curl_path)returnfalse;$this-host=$URI_PARTShost;if(!empty($URI_PARTSport)$this-port=$URI_PARTSport;if($this-_isproxy)/usingproxy,sendentireURI$this-_httpsrequest($URI,$URI,$this-_httpmethod);else$path=$URI_PARTSpath.($URI_PARTSquery?.$URI_PARTSquery:);/noproxy,sendonlythepath$this-_httpsrequest($path,$URI,$this-_httpmethod);if($this-_redirectaddr)/*urlwasredirected,checkifwevehitthemaxdepth*/if($this-maxredirs$this-_redirectdepth)/onlyfollowredirectifitsonthissite,oroffsiteokistrueif(preg_match(|http:/.preg_quote($this-host).|i,$this-_redirectaddr)|$this-offsiteok)/*followtheredirect*/$this-_redirectdepth+;$this-lastredirectaddr=$this-_redirectaddr;$this-fetch($this-_redirectaddr);if($this-_framedepthmaxframes&count($this-_frameurls)0)$frameurls=$this-_frameurls;$this-_frameurls=array();while(list(,$frameurl)=each($frameurls)if($this-_framedepthmaxframes)$this-fetch($frameurl);$this-_framedepth+;elsebreak;returntrue;break;default:/notavalidprotocol$this-error=Invalidprotocol.$URI_PARTSscheme.n;returnfalse;break;returntrue;/*=Function:submitPurpose:submitanhttpformInput:$URIthelocationtopostthedata$formvarstheformvarstouse.format:$formvarsvar=val;$formfilesanarrayoffilestosubmitformat:$formfilesvar=/dir/filename.ext;Output:$this-resultsthetextoutputfromthepost=*/functionsubmit($URI,$formvars=,$formfiles=)unset($postdata);$postdata=$this-_prepare_post_body($formvars,$formfiles);$URI_PARTS=parse_url($URI);if(!empty($URI_PARTSuser)$this-user=$URI_PARTSuser;if(!empty($URI_PARTSpass)$this-pass=$URI_PARTSpass;if(empty($URI_PARTSquery)$URI_PARTSquery=;if(empty($URI_PARTSpath)$URI_PARTSpath=;switch(strtolower($URI_PARTSscheme)casehttp:$this-host=$URI_PARTShost;if(!empty($URI_PARTSport)$this-port=$URI_PARTSport;if($this-_connect($fp)if
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025至2030中国皮质类固醇反应性皮肤病行业产业运行态势及投资规划深度研究报告
- 2025至2030中国用于增强现实的智能眼镜行业产业运行态势及投资规划深度研究报告
- 2025至2030中国生物搅拌器行业产业运行态势及投资规划深度研究报告
- 2025至2030中国玩具烟花市场产销规模与未来需求量研究报告
- 2025至2030中国特种植物油行业市场深度研究与战略咨询分析报告
- 教师合同管理与权益维护
- 个性化学习路径在医疗培训中的实践案例分析
- 促进学困生发展的个性化心理干预与指导方案研究
- 教育技术对幼儿心理健康的积极作用
- 商业创新中的在线教育平台法律风险分析
- SAP S4HANA 用户操作手册-FICO-006-财务月结
- 攀岩运动项目介绍
- 经济纠纷和解协议书
- 2023年芜湖市湾沚区国有资本建设投资有限公司招聘考试真题
- 棋牌室四人合作协议书范文
- 中国医院质量安全管理第2-13部分:患者服务临床用血
- 《篮球原地运球》教案 (共三篇)
- 思维模型之六顶思考帽
- 2025年高考化学复习备考策略讲座
- 《网络系统建设与运维》课件-第3章 路由技术
- 常用建筑类型疏散宽度计算表格
评论
0/150
提交评论