调整初始化

This commit is contained in:
Anyon 2019-12-09 14:52:15 +08:00
parent f68ce9ad4c
commit 457c3336fa
2 changed files with 12 additions and 5 deletions

View File

@ -72,7 +72,7 @@ class Client extends Controller
} }
return WechatService::__callStatic($class, [$appid]); return WechatService::__callStatic($class, [$appid]);
} catch (\Exception $exception) { } catch (\Exception $exception) {
return new \Exception($exception->getMessage(), $exception->getCode()); return new \Exception($exception->getMessage(), 404);
} }
} }
} }

View File

@ -37,15 +37,22 @@ class ClientService extends WechatService
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']}");
$code = 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&code={$code}"; $url = "http://127.0.0.1:1231/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&code={$code}"; $url = "http://127.0.0.1:1231/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"]);
} }
dump($client->getMessage()); try {
$exception = new \think\Exception($client->getMessage(), $client->getCode());
} catch (\Exception $exception) {
$exception = null;
}
if ($exception instanceof \Exception) {
throw $exception;
}
return $client; return $client;
} }