ImageVerifierCode 换一换
格式:DOCX , 页数:63 ,大小:33.40KB ,
资源ID:10996251      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/10996251.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(api接口教程php.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

api接口教程php.docx

1、api接口教程phpurlencode($key) ,num=urlencode($num) ,show=urlencode($show) ,);foreach($fields as $key=$value) $fields_string .= $key.=.$value.& ;/把变量组装成username=mayuchao&password=123456&成功了mayuchao密码laoma 这个格式rtrim($fields_string ,&) ; /从末端开始去掉删除多余&符号$ch = curl_init() ; / 开启一个curl对话curl_setopt($ch, CURLO

2、PT_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 ($params as $k = $

3、v) if( != substr($v, 0, 1) $stringToBeSigned .= $k$v; unset($k, $v); $stringToBeSigned .= $this-secretKey; return strtoupper(md5($stringToBeSigned); protected function curl($url, $postFields = null) $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FAILONERROR, false);

4、 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 ($post

5、Multipart) curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); else curl_setopt($ch, CURLOPT_POSTFIELDS, substr($postBodyString,0,-1); $reponse = curl_exec($ch); if (curl_errno($ch) throw new Exception(curl_error($ch),0); else $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if (200 != $httpS

6、tatusCode) throw new Exception($reponse,$httpStatusCode); curl_close($ch); return $reponse; protected function logCommunicationError($apiName, $requestUrl, $errorCode, $responseTxt) $localIp = isset($_SERVERSERVER_ADDR) ? $_SERVERSERVER_ADDR : CLI; $logger = new LtLogger; $logger-conflog_file = rtri

7、m(TOP_SDK_WORK_DIR, /) . / . logs/top_comm_err_ . $this-appkey . _ . date(Y-m-d) . .log; $logger-confseparator = _; $logData = array( date(Y-m-d H:i:s), $apiName, $this-appkey, $localIp, PHP_OS, $this-sdkVersion, $requestUrl, $errorCode, str_replace(n,$responseTxt) ); $logger-log($logData); public f

8、unction execute($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; $sysPara

9、mssign_method = $this-signMethod; $sysParamsmethod = $request-getApiMethodName(); $sysParamstimestamp = date(Y-m-d H:i:s); $sysParamspartner_id = $this-sdkVersion; if (null != $session) $sysParamssession = $session; /获取业务参数 $apiParams = $request-getApiParas(); /签名 $sysParamssign = $this-generateSign

10、(array_merge($apiParams, $sysParams); /系统参数放入GET请求串 $requestUrl = $this-gatewayUrl . ?; foreach ($sysParams as $sysParamKey = $sysParamValue) $requestUrl .= $sysParamKey= . urlencode($sysParamValue) . &; $requestUrl = substr($requestUrl, 0, -1); /发起HTTP请求 try $resp = $this-curl($requestUrl, $apiPara

11、ms); 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 = $resp); if (null != $r

12、espObject) $respWellFormed = true; foreach ($respObject as $propKey = $propValue) $respObject = $propValue; else if(xml = $this-format) $respObject = simplexml_load_string($resp); if (false != $respObject) $respWellFormed = true; /返回的HTTP文本不是标准JSON或者XML,记下错误日志 if (false = $respWellFormed) $this-logC

13、ommunicationError($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 = new LtLogger; $logger-conflog_file = rtrim(TOP_SDK_WORK_DIR, /) . / . logs

14、/top_biz_err_ . $this-appkey . _ . date(Y-m-d) . .log; $logger-log(array( date(Y-m-d H:i:s), $resp ); return $respObject; public function exec($paramsArray) if (!isset($paramsArraymethod) trigger_error(No api name passed); $inflector = new LtInflector; $inflector-confseparator = .; $requestClassName

15、 = ucfirst($inflector-camelize(substr($paramsArraymethod, 7) . Request; if (!class_exists($requestClassName) trigger_error(No such api: . $paramsArraymethod); $session = isset($paramsArraysession) ? $paramsArraysession : null; $req = new $requestClassName; foreach($paramsArray as $paraKey = $paraVal

16、ue) $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); ?以

17、下为引用的内容:/ 创建两个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_a

18、dd_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_mul

19、ti_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的ht

20、tp头信息发送出去)。也就是说,我们需要不断调用该函数,直到返回值发生改变。而接下来的 while 循环,只在 $active 变量为 true 时继续。这一变量之前作为第二个参数传给了 curl_multi_exec() ,代表只要批处理句柄中是否还有活动连接。接着,我们调用 curl_multi_select() ,在活动连接(例如接受服务器响应)出现之前,它都是被“屏蔽”的。这个函数成功执行后,我们又会进入另一个 do-while 循环,继续下一条URL?php/*Snoopy - the PHP net clientAuthor: Monte Ohrt Copyright (c): 1

21、999-2000 ispi, all rights reservedVersion: 1.01 * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1