Update ClientService.php

This commit is contained in:
Anyon 2019-12-09 14:55:59 +08:00
parent 457c3336fa
commit 228ffe175f

View File

@ -34,15 +34,16 @@ class ClientService extends WechatService
if (count($arguments) !== 2) { if (count($arguments) !== 2) {
throw new \think\Exception('请按顺序传入APPID及APPKEY两个参数'); throw new \think\Exception('请按顺序传入APPID及APPKEY两个参数');
} }
$serviceUri = 'http://127.0.0.1:1231';
list($appid, $appkey) = $arguments; list($appid, $appkey) = $arguments;
$data = ['class' => $name, 'appid' => $appid, 'time' => time(), 'nostr' => uniqid()]; $data = ['class' => $name, 'appid' => $appid, 'time' => time(), 'nostr' => uniqid()];
$data['sign'] = md5("{$data['class']}#{$appid}#{$appkey}#{$data['time']}#{$data['nostr']}"); $data['sign'] = md5("{$data['class']}#{$appid}#{$appkey}#{$data['time']}#{$data['nostr']}");
$token = enbase64url(json_encode($data, JSON_UNESCAPED_UNICODE)); $token = enbase64url(json_encode($data, JSON_UNESCAPED_UNICODE));
if (class_exists('Yar_Client')) { if (class_exists('Yar_Client')) {
$url = "http://127.0.0.1:1231/service/api.client/yar?not_init_session=1&token={$token}"; $url = "{$serviceUri}/service/api.client/yar?not_init_session=1&token={$token}";
$client = new \Yar_Client($url); $client = new \Yar_Client($url);
} else { } else {
$url = "http://127.0.0.1:1231/service/api.client/soap?not_init_session=1&token={$token}"; $url = "{$serviceUri}/service/api.client/soap?not_init_session=1&token={$token}";
$client = new \SoapClient(null, ['location' => $url, 'uri' => "thinkadmin"]); $client = new \SoapClient(null, ['location' => $url, 'uri' => "thinkadmin"]);
} }
try { try {
@ -50,9 +51,7 @@ class ClientService extends WechatService
} catch (\Exception $exception) { } catch (\Exception $exception) {
$exception = null; $exception = null;
} }
if ($exception instanceof \Exception) { if ($exception instanceof \Exception) throw $exception;
throw $exception;
}
return $client; return $client;
} }