|
|
<?php
|
|
|
|
|
|
class JdmsClient {
|
|
|
private static $msApiConfig;
|
|
|
|
|
|
private static function getMsApiConfig() {
|
|
|
self::$msApiConfig = Zc::C('jdmsApi');
|
|
|
|
|
|
return self::$msApiConfig;
|
|
|
}
|
|
|
|
|
|
public static function execute($route, $params, $tryTimes = 3) {
|
|
|
self::getMsApiConfig();
|
|
|
|
|
|
$sysParams['appKey'] = self::$msApiConfig['appKey'];
|
|
|
$sysParams['timestamp'] = date('Y-m-d H:i:s');
|
|
|
$sysParams['paramJson'] = json_encode($params);
|
|
|
$sysParams['sign'] = self::generateSign($sysParams);
|
|
|
|
|
|
$requestUrl = self::$msApiConfig['gatewayUrl'] . $route;
|
|
|
|
|
|
$maxTimes = $tryTimes ? $tryTimes : 1;
|
|
|
for ($tt = 1; $tt <= $maxTimes; $tt++) {
|
|
|
try {
|
|
|
$ywCurl = CommonTool::getCurl(10);
|
|
|
|
|
|
$resp = $ywCurl->get($requestUrl, $sysParams);
|
|
|
$resp = json_decode($resp, true);
|
|
|
if (empty($resp)) {
|
|
|
throw new Exception('请求异常', 500);
|
|
|
}
|
|
|
return $resp;
|
|
|
} catch (Exception $e) {
|
|
|
Zc::getLog('ms_client/execute')->info("execute error route[$route] params[" . ZcArrayHelper::sp($params) . "] curlInfo:" . print_r($ywCurl->getInfo(), true) . ", errorMsg:" . $e->getMessage());
|
|
|
return CommonTool::failCodeResult($e->getCode(), '请求异常');
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private static function generateSign($sysParams) {
|
|
|
ksort($sysParams);
|
|
|
$stringToBeSigned = self::$msApiConfig['secretKey'];
|
|
|
foreach ($sysParams as $k => $v) {
|
|
|
$stringToBeSigned .= "$k$v";
|
|
|
}
|
|
|
unset($k, $v);
|
|
|
$stringToBeSigned .= self::$msApiConfig['secretKey'];
|
|
|
|
|
|
return md5($stringToBeSigned);
|
|
|
}
|
|
|
} |