优惠券订单及其他脚本

DingTalkClient.php 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. <?php
  2. class DingTalkClient
  3. {
  4. /**@Author chaohui.zch copy from TopClient and modify 2016-12-14 **/
  5. /**@Author chaohui.zch modify $gatewayUrl 2017-07-18 **/
  6. public $gatewayUrl = "https://eco.taobao.com/router/rest";
  7. public $format = "xml";
  8. public $connectTimeout;
  9. public $readTimeout;
  10. public $apiCallType;
  11. public $httpMethod;
  12. /** 是否打开入参check**/
  13. public $checkRequest = true;
  14. protected $apiVersion = "2.0";
  15. protected $sdkVersion = "dingtalk-sdk-php-20161214";
  16. public function __construct($apiCallType = null, $httpMethod = null, $format = "xml"){
  17. $this->apiCallType = $apiCallType;
  18. $this->httpMethod = $httpMethod;
  19. $this->format = $format;
  20. }
  21. public function curl($url, $postFields = null)
  22. {
  23. $ch = curl_init();
  24. curl_setopt($ch, CURLOPT_URL, $url);
  25. curl_setopt($ch, CURLOPT_FAILONERROR, false);
  26. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  27. if ($this->readTimeout) {
  28. curl_setopt($ch, CURLOPT_TIMEOUT, $this->readTimeout);
  29. }
  30. if ($this->connectTimeout) {
  31. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectTimeout);
  32. }
  33. curl_setopt ( $ch, CURLOPT_USERAGENT, "dingtalk-sdk-php" );
  34. //https 请求
  35. if(strlen($url) > 5 && strtolower(substr($url,0,5)) == "https" ) {
  36. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  37. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  38. }
  39. if (is_array($postFields) && 0 < count($postFields))
  40. {
  41. $postBodyString = "";
  42. $postMultipart = false;
  43. foreach ($postFields as $k => $v)
  44. {
  45. if("@" != substr($v, 0, 1))//判断是不是文件上传
  46. {
  47. $postBodyString .= "$k=" . urlencode($v) . "&";
  48. }
  49. else//文件上传用multipart/form-data,否则用www-form-urlencoded
  50. {
  51. $postMultipart = true;
  52. if(class_exists('\CURLFile')){
  53. $postFields[$k] = new \CURLFile(substr($v, 1));
  54. }
  55. }
  56. }
  57. unset($k, $v);
  58. curl_setopt($ch, CURLOPT_POST, true);
  59. if ($postMultipart)
  60. {
  61. if (class_exists('\CURLFile')) {
  62. curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
  63. } else {
  64. if (defined('CURLOPT_SAFE_UPLOAD')) {
  65. curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
  66. }
  67. }
  68. curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
  69. }
  70. else
  71. {
  72. $header = array("content-type: application/x-www-form-urlencoded; charset=UTF-8");
  73. curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
  74. curl_setopt($ch, CURLOPT_POSTFIELDS, substr($postBodyString,0,-1));
  75. }
  76. }
  77. $reponse = curl_exec($ch);
  78. if (curl_errno($ch))
  79. {
  80. throw new Exception(curl_error($ch),0);
  81. }
  82. else
  83. {
  84. $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  85. if (200 !== $httpStatusCode)
  86. {
  87. throw new Exception($reponse,$httpStatusCode);
  88. }
  89. }
  90. curl_close($ch);
  91. return $reponse;
  92. }
  93. public function curl_get($url,$apiFields = null)
  94. {
  95. $ch = curl_init();
  96. foreach ($apiFields as $key => $value)
  97. {
  98. $url .= "&" ."$key=" . urlencode($value);
  99. }
  100. curl_setopt($ch, CURLOPT_URL, $url);
  101. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  102. curl_setopt($ch, CURLOPT_FAILONERROR, false);
  103. curl_setopt($ch, CURLOPT_HEADER, false);
  104. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  105. if ($this->readTimeout)
  106. {
  107. curl_setopt($ch, CURLOPT_TIMEOUT, $this->readTimeout);
  108. }
  109. if ($this->connectTimeout)
  110. {
  111. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectTimeout);
  112. }
  113. curl_setopt ( $ch, CURLOPT_USERAGENT, "dingtalk-sdk-php" );
  114. //https ignore ssl check ?
  115. if(strlen($url) > 5 && strtolower(substr($url,0,5)) == "https" )
  116. {
  117. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  118. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  119. }
  120. $reponse = curl_exec($ch);
  121. if (curl_errno($ch))
  122. {
  123. throw new Exception(curl_error($ch),0);
  124. }
  125. else
  126. {
  127. $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  128. if (200 !== $httpStatusCode)
  129. {
  130. throw new Exception($reponse,$httpStatusCode);
  131. }
  132. }
  133. curl_close($ch);
  134. return $reponse;
  135. }
  136. public function curl_json($url, $postFields = null)
  137. {
  138. $ch = curl_init();
  139. curl_setopt($ch, CURLOPT_URL, $url);
  140. curl_setopt($ch, CURLOPT_FAILONERROR, false);
  141. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  142. if ($this->readTimeout) {
  143. curl_setopt($ch, CURLOPT_TIMEOUT, $this->readTimeout);
  144. }
  145. if ($this->connectTimeout) {
  146. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectTimeout);
  147. }
  148. curl_setopt ( $ch, CURLOPT_USERAGENT, "dingtalk-sdk-php" );
  149. //https 请求
  150. if(strlen($url) > 5 && strtolower(substr($url,0,5)) == "https" ) {
  151. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  152. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  153. }
  154. if (is_array($postFields) && 0 < count($postFields))
  155. {
  156. $postBodyString = "";
  157. $postMultipart = false;
  158. foreach ($postFields as $k => $v)
  159. {
  160. if("@" != substr($v, 0, 1))//判断是不是文件上传
  161. {
  162. $postBodyString .= "$k=" . urlencode($v) . "&";
  163. }
  164. else//文件上传用multipart/form-data,否则用www-form-urlencoded
  165. {
  166. $postMultipart = true;
  167. if(class_exists('\CURLFile')){
  168. $postFields[$k] = new \CURLFile(substr($v, 1));
  169. }
  170. }
  171. }
  172. unset($k, $v);
  173. curl_setopt($ch, CURLOPT_POST, true);
  174. if ($postMultipart)
  175. {
  176. if (class_exists('\CURLFile')) {
  177. curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
  178. } else {
  179. if (defined('CURLOPT_SAFE_UPLOAD')) {
  180. curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
  181. }
  182. }
  183. curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
  184. }
  185. else {
  186. $header = array("Content-Type: application/json; charset=utf-8", "Content-Length:".strlen(json_encode($postFields)));
  187. curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
  188. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postFields));
  189. }
  190. }
  191. $reponse = curl_exec($ch);
  192. if (curl_errno($ch))
  193. {
  194. throw new Exception(curl_error($ch),0);
  195. }
  196. else
  197. {
  198. $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  199. if (200 !== $httpStatusCode)
  200. {
  201. throw new Exception($reponse,$httpStatusCode);
  202. }
  203. }
  204. curl_close($ch);
  205. return $reponse;
  206. }
  207. public function curl_with_memory_file($url, $postFields = null, $fileFields = null)
  208. {
  209. $ch = curl_init();
  210. curl_setopt($ch, CURLOPT_URL, $url);
  211. curl_setopt($ch, CURLOPT_FAILONERROR, false);
  212. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  213. if ($this->readTimeout) {
  214. curl_setopt($ch, CURLOPT_TIMEOUT, $this->readTimeout);
  215. }
  216. if ($this->connectTimeout) {
  217. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectTimeout);
  218. }
  219. curl_setopt ( $ch, CURLOPT_USERAGENT, "dingtalk-sdk-php" );
  220. //https 请求
  221. if(strlen($url) > 5 && strtolower(substr($url,0,5)) == "https" ) {
  222. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  223. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  224. }
  225. //生成分隔符
  226. $delimiter = '-------------' . uniqid();
  227. //先将post的普通数据生成主体字符串
  228. $data = '';
  229. if($postFields != null){
  230. foreach ($postFields as $name => $content) {
  231. $data .= "--" . $delimiter . "\r\n";
  232. $data .= 'Content-Disposition: form-data; name="' . $name . '"';
  233. //multipart/form-data 不需要urlencode,参见 http:stackoverflow.com/questions/6603928/should-i-url-encode-post-data
  234. $data .= "\r\n\r\n" . $content . "\r\n";
  235. }
  236. unset($name,$content);
  237. }
  238. //将上传的文件生成主体字符串
  239. if($fileFields != null){
  240. foreach ($fileFields as $name => $file) {
  241. $data .= "--" . $delimiter . "\r\n";
  242. $data .= 'Content-Disposition: form-data; name="' . $name . '"; filename="' . $file['name'] . "\" \r\n";
  243. $data .= 'Content-Type: ' . $file['type'] . "\r\n\r\n";//多了个文档类型
  244. $data .= $file['content'] . "\r\n";
  245. }
  246. unset($name,$file);
  247. }
  248. //主体结束的分隔符
  249. $data .= "--" . $delimiter . "--";
  250. curl_setopt($ch, CURLOPT_POST, true);
  251. curl_setopt($ch, CURLOPT_HTTPHEADER , array(
  252. 'Content-Type: multipart/form-data; boundary=' . $delimiter,
  253. 'Content-Length: ' . strlen($data))
  254. );
  255. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  256. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  257. $reponse = curl_exec($ch);
  258. unset($data);
  259. if (curl_errno($ch))
  260. {
  261. throw new Exception(curl_error($ch),0);
  262. }
  263. else
  264. {
  265. $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  266. if (200 !== $httpStatusCode)
  267. {
  268. throw new Exception($reponse,$httpStatusCode);
  269. }
  270. }
  271. curl_close($ch);
  272. return $reponse;
  273. }
  274. protected function logCommunicationError($apiName, $requestUrl, $errorCode, $responseTxt)
  275. {
  276. $localIp = isset($_SERVER["SERVER_ADDR"]) ? $_SERVER["SERVER_ADDR"] : "CLI";
  277. $logger = new TopLogger;
  278. $logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/') . '/' . "logs/top_comm_err_" . "_" . date("Y-m-d") . ".log";
  279. $logger->conf["separator"] = "^_^";
  280. $logData = array(
  281. date("Y-m-d H:i:s"),
  282. $apiName,
  283. $localIp,
  284. PHP_OS,
  285. $this->sdkVersion,
  286. $requestUrl,
  287. $errorCode,
  288. str_replace("\n","",$responseTxt)
  289. );
  290. $logger->log($logData);
  291. }
  292. public function execute($request, $session = null,$bestUrl = null){
  293. if(DingTalkConstant::$CALL_TYPE_OAPI == $this->apiCallType){
  294. return $this->_executeOapi($request, $session, $bestUrl, null, null, null, null);
  295. }else{
  296. return $this->_execute($request, $session, $bestUrl);
  297. }
  298. }
  299. public function executeWithAccessKey($request, $bestUrl = null, $accessKey, $accessSecret){
  300. return $this->executeWithCorpId($request, $bestUrl, $accessKey, $accessSecret, null, null);
  301. }
  302. public function executeWithSuiteTicket($request,$bestUrl = null, $accessKey, $accessSecret, $suiteTicket){
  303. return $this->executeWithCorpId($request,$bestUrl, $accessKey, $accessSecret, $suiteTicket, null);
  304. }
  305. public function executeWithCorpId($request, $bestUrl = null, $accessKey, $accessSecret, $suiteTicket, $corpId) {
  306. if(DingTalkConstant::$CALL_TYPE_OAPI == $this->apiCallType){
  307. return $this->_executeOapi($request, null, $bestUrl,$accessKey, $accessSecret, $suiteTicket, $corpId);
  308. }else{
  309. return $this->_execute($request, null, $bestUrl);
  310. }
  311. }
  312. private function _executeOapi($request, $session = null,$bestUrl = null,$accessKey, $accessSecret, $suiteTicket, $corpId){
  313. $result = new ResultSet();
  314. if($this->checkRequest) {
  315. try {
  316. $request->check();
  317. } catch (Exception $e) {
  318. $result->code = $e->getCode();
  319. $result->msg = $e->getMessage();
  320. return $result;
  321. }
  322. }
  323. $sysParams["method"] = $request->getApiMethodName();
  324. //系统参数放入GET请求串
  325. if($bestUrl){
  326. $requestUrl = $bestUrl."?";
  327. }else{
  328. $requestUrl = $this->gatewayUrl."?";
  329. }
  330. if(null != $accessKey){
  331. $timestamp = $this->getMillisecond();
  332. // 验证签名有效性
  333. $canonicalString = $this->getCanonicalStringForIsv($timestamp, $suiteTicket);
  334. $signature = $this->computeSignature($accessSecret, $canonicalString);
  335. $queryParams["accessKey"] = $accessKey;
  336. $queryParams["signature"] = $signature;
  337. $queryParams["timestamp"] = $timestamp+"";
  338. if($suiteTicket != null) {
  339. $queryParams["suiteTicket"] = $suiteTicket;
  340. }
  341. if($corpId != null){
  342. $queryParams["corpId"] = $corpId;
  343. }
  344. foreach ($queryParams as $queryParamKey => $queryParamValue) {
  345. $requestUrl .= "$queryParamKey=" . urlencode($queryParamValue) . "&";
  346. }
  347. }else{
  348. $requestUrl .= "access_token=" . urlencode($session) . "&";
  349. }
  350. $apiParams = array();
  351. //获取业务参数
  352. $apiParams = $request->getApiParas();
  353. $fileFields = array();
  354. foreach ($apiParams as $key => $value) {
  355. if(is_array($value) && array_key_exists('type',$value) && array_key_exists('content',$value) ){
  356. $value['name'] = $key;
  357. $fileFields[$key] = $value;
  358. unset($apiParams[$key]);
  359. }
  360. }
  361. // $requestUrl .= "timestamp=" . urlencode($sysParams["timestamp"]) . "&";
  362. $requestUrl = substr($requestUrl, 0, -1);
  363. //发起HTTP请求
  364. try
  365. {
  366. if(count($fileFields) > 0){
  367. $resp = $this->curl_with_memory_file($requestUrl, $apiParams, $fileFields);
  368. }else{
  369. if(DingTalkConstant::$METHOD_POST == $this->httpMethod){
  370. $resp = $this->curl_json($requestUrl, $apiParams);
  371. }else{
  372. $resp = $this->curl_get($requestUrl, $apiParams);
  373. }
  374. }
  375. }
  376. catch (Exception $e)
  377. {
  378. $this->logCommunicationError($sysParams["method"],$requestUrl,"HTTP_ERROR_" . $e->getCode(),$e->getMessage());
  379. $result->code = $e->getCode();
  380. $result->msg = $e->getMessage();
  381. return $result;
  382. }
  383. unset($apiParams);
  384. unset($fileFields);
  385. //解析TOP返回结果
  386. $respWellFormed = false;
  387. if ("json" == $this->format)
  388. {
  389. $respObject = json_decode($resp);
  390. if (null !== $respObject)
  391. {
  392. $respWellFormed = true;
  393. }
  394. }
  395. else if("xml" == $this->format)
  396. {
  397. $respObject = @simplexml_load_string($resp);
  398. if (false !== $respObject)
  399. {
  400. $respWellFormed = true;
  401. }
  402. }
  403. //返回的HTTP文本不是标准JSON或者XML,记下错误日志
  404. if (false === $respWellFormed)
  405. {
  406. $this->logCommunicationError($sysParams["method"],$requestUrl,"HTTP_RESPONSE_NOT_WELL_FORMED",$resp);
  407. $result->code = 0;
  408. $result->msg = "HTTP_RESPONSE_NOT_WELL_FORMED";
  409. return $result;
  410. }
  411. //如果TOP返回了错误码,记录到业务错误日志中
  412. if (isset($respObject->code))
  413. {
  414. $logger = new TopLogger;
  415. $logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/') . '/' . "logs/top_biz_err_" . "_" . date("Y-m-d") . ".log";
  416. $logger->log(array(
  417. date("Y-m-d H:i:s"),
  418. $resp
  419. ));
  420. }
  421. return $respObject;
  422. }
  423. private function getMillisecond() {
  424. list($s1, $s2) = explode(' ', microtime());
  425. return (float)sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000);
  426. }
  427. private function getCanonicalStringForIsv($timestamp, $suiteTicket) {
  428. $result = $timestamp;
  429. if($suiteTicket != null) {
  430. $result .= "\n".$suiteTicket;
  431. }
  432. return $result;
  433. }
  434. private function computeSignature($accessSecret, $canonicalString){
  435. $s = hash_hmac('sha256', $canonicalString, $accessSecret, true);
  436. return base64_encode($s);
  437. }
  438. private function _execute($request, $session = null,$bestUrl = null)
  439. {
  440. $result = new ResultSet();
  441. if($this->checkRequest) {
  442. try {
  443. $request->check();
  444. } catch (Exception $e) {
  445. $result->code = $e->getCode();
  446. $result->msg = $e->getMessage();
  447. return $result;
  448. }
  449. }
  450. //组装系统参数
  451. $sysParams["v"] = $this->apiVersion;
  452. $sysParams["format"] = $this->format;
  453. $sysParams["method"] = $request->getApiMethodName();
  454. $sysParams["timestamp"] = date("Y-m-d H:i:s");
  455. if (null != $session)
  456. {
  457. $sysParams["session"] = $session;
  458. }
  459. $apiParams = array();
  460. //获取业务参数
  461. $apiParams = $request->getApiParas();
  462. //系统参数放入GET请求串
  463. if($bestUrl){
  464. $requestUrl = $bestUrl."?";
  465. $sysParams["partner_id"] = $this->getClusterTag();
  466. }else{
  467. $requestUrl = $this->gatewayUrl."?";
  468. $sysParams["partner_id"] = $this->sdkVersion;
  469. }
  470. foreach ($sysParams as $sysParamKey => $sysParamValue)
  471. {
  472. // if(strcmp($sysParamKey,"timestamp") != 0)
  473. $requestUrl .= "$sysParamKey=" . urlencode($sysParamValue) . "&";
  474. }
  475. $fileFields = array();
  476. foreach ($apiParams as $key => $value) {
  477. if(is_array($value) && array_key_exists('type',$value) && array_key_exists('content',$value) ){
  478. $value['name'] = $key;
  479. $fileFields[$key] = $value;
  480. unset($apiParams[$key]);
  481. }
  482. }
  483. // $requestUrl .= "timestamp=" . urlencode($sysParams["timestamp"]) . "&";
  484. $requestUrl = substr($requestUrl, 0, -1);
  485. //发起HTTP请求
  486. try
  487. {
  488. if(count($fileFields) > 0){
  489. $resp = $this->curl_with_memory_file($requestUrl, $apiParams, $fileFields);
  490. }else{
  491. $resp = $this->curl($requestUrl, $apiParams);
  492. }
  493. }
  494. catch (Exception $e)
  495. {
  496. $this->logCommunicationError($sysParams["method"],$requestUrl,"HTTP_ERROR_" . $e->getCode(),$e->getMessage());
  497. $result->code = $e->getCode();
  498. $result->msg = $e->getMessage();
  499. return $result;
  500. }
  501. unset($apiParams);
  502. unset($fileFields);
  503. //解析TOP返回结果
  504. $respWellFormed = false;
  505. if ("json" == $this->format)
  506. {
  507. $respObject = json_decode($resp);
  508. if (null !== $respObject)
  509. {
  510. $respWellFormed = true;
  511. foreach ($respObject as $propKey => $propValue)
  512. {
  513. $respObject = $propValue;
  514. }
  515. }
  516. }
  517. else if("xml" == $this->format)
  518. {
  519. $respObject = @simplexml_load_string($resp);
  520. if (false !== $respObject)
  521. {
  522. $respWellFormed = true;
  523. }
  524. }
  525. //返回的HTTP文本不是标准JSON或者XML,记下错误日志
  526. if (false === $respWellFormed)
  527. {
  528. $this->logCommunicationError($sysParams["method"],$requestUrl,"HTTP_RESPONSE_NOT_WELL_FORMED",$resp);
  529. $result->code = 0;
  530. $result->msg = "HTTP_RESPONSE_NOT_WELL_FORMED";
  531. return $result;
  532. }
  533. //如果TOP返回了错误码,记录到业务错误日志中
  534. if (isset($respObject->code))
  535. {
  536. $logger = new TopLogger;
  537. $logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/') . '/' . "logs/top_biz_err_" . "_" . date("Y-m-d") . ".log";
  538. $logger->log(array(
  539. date("Y-m-d H:i:s"),
  540. $resp
  541. ));
  542. }
  543. return $respObject;
  544. }
  545. public function exec($paramsArray)
  546. {
  547. if (!isset($paramsArray["method"]))
  548. {
  549. trigger_error("No api name passed");
  550. }
  551. $inflector = new LtInflector;
  552. $inflector->conf["separator"] = ".";
  553. $requestClassName = ucfirst($inflector->camelize(substr($paramsArray["method"], 7))) . "Request";
  554. if (!class_exists($requestClassName))
  555. {
  556. trigger_error("No such dingtalk-api: " . $paramsArray["method"]);
  557. }
  558. $session = isset($paramsArray["session"]) ? $paramsArray["session"] : null;
  559. $req = new $requestClassName;
  560. foreach($paramsArray as $paraKey => $paraValue)
  561. {
  562. $inflector->conf["separator"] = "_";
  563. $setterMethodName = $inflector->camelize($paraKey);
  564. $inflector->conf["separator"] = ".";
  565. $setterMethodName = "set" . $inflector->camelize($setterMethodName);
  566. if (method_exists($req, $setterMethodName))
  567. {
  568. $req->$setterMethodName($paraValue);
  569. }
  570. }
  571. return $this->execute($req, $session);
  572. }
  573. private function getClusterTag()
  574. {
  575. return substr($this->sdkVersion,0,11)."-cluster".substr($this->sdkVersion,11);
  576. }
  577. }