$appConfig['tokenUrl'], 'params' => $params ); } /** * * @param * $req * @param * $accessToken * @param $returnFormat assoc|object|xml * assoc返回关联数组,object返回stdObject,xml返回SimpleXMLElement * @return Ambigous */ public static function execute($req, $accessToken, $returnFormat = 'assoc') { $tc = self::getTopClient(); if ($returnFormat == 'xml') { $tc->format = 'xml'; } else { $tc->format = 'json'; } $resp = $tc->execute($req, $accessToken); if ($returnFormat == 'xml') { return $resp; } else if ($returnFormat == 'object') { return json_decode($resp); } else if ($returnFormat == 'assoc') { return ZcArrayHelper::objectToArray($resp); } } public static function getTopClient() { $appConfig = self::getAppConfig(); $tc = new TopClient(); $tc->appkey = $appConfig['appkey']; $tc->secretKey = $appConfig['secretKey']; $tc->gatewayUrl = $appConfig['gatewayUrl']; return $tc; } public static function getNeedRetrySubCodePatterns() { return array( '/^isp.[^-]*-service-unavailable$/', '/^isp.remote-service-error$/', '/^isp.remote-service-timeout$/', '/^isp.remote-connection-error$/', '/^isp.top-remote-connection-timeout$/', '/^isp.top-remote-connection-error$/', '/^isp.unknown-error$/', ); } public static function checkTbApiNeedRetry($resp) { $needRetrySubCodePatterns = self::getNeedRetrySubCodePatterns(); $subCode = $resp['sub_code']; if (empty($subCode)) { return false; } foreach ($needRetrySubCodePatterns as $pattern) { if (preg_match($pattern, $subCode)) { return true; } } return false; } }