12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?php
- // app/Libraries/CommonHelper.php
- namespace App\Libraries;
- use Dcat\Admin\Admin;
- use JsonRPC\Client;
- use Illuminate\Http\Request;
- use JsonRPC\HttpClient;
- class RpcClient
- {
- // RPC超时时间
- public static $timeout = 3;
- /*
- * RPC客户端
- * @param $procedure string 远程过程调用名称
- * @param $params array 远程过程调用参数
- */
- public static function albumExecute ($procedure, $params = []) {
- $apiKey = time();
- $apiSecret = env('ALBUM_RPC_SECRET');
- $payload = json_encode($params);
- $payload = $payload.$apiKey;
- $signature = hash_hmac('sha256', $payload, $apiSecret);
- $clientHost = env('ALBUM_RPC_URL');
- $httpClient = new HttpClient($clientHost);
- $httpClient = $httpClient->withTimeout(self::$timeout);
- $client = new Client($clientHost,true,$httpClient);
- try {
- $result = $client->execute( $procedure, $params,[], null,[
- 'X-API-Key: '.$apiKey,
- 'X-API-Signature: '.$signature,
- ]);
- return $result;
- } catch (\Exception $e) {
- throw new \Exception($e->getMessage());
- }
- }
- }
|