pickmap/service-request

客户端到客户端发送请求的常规结构

0.2.0 2024-01-20 11:49 UTC

This package is not auto-updated.

Last update: 2024-09-28 15:08:28 UTC


README

如果你在一个宏观服务结构中工作,或者你需要一个非常轻量的库来在简单服务或应用程序中发送和接收重发,这个库将大大帮助你。

目前,它只实现了从 https://keycloak.com.cn/ 接收令牌,但你也可以完成它。最佳的用法示例显示在这张图表中,这样你可以使用这个库完成“使用令牌请求服务”步骤。

enter image description here

步骤 #1

composer require pickmap/service-request

步骤 #2

在您的 .env 文件中定义以下变量

KEYCLOAK_CLIENT_ID=client-id
KEYCLOAK_CLIENT_SECRET=keycloak-secret-key
KEYCLOAK_USERNAME=usernameOrEmail
KEYCLOAK_PASSWORD=password
KEYCLOAK_LOGIN_URL='https://...openid-connect/token?grant_type=password'

步骤 #2

在您希望装备发送请求的任何类中,例如模型或控制器,执行以下操作

class  sample {
use  ServiceRequest;

public  function  aMethod()
	{
		self::requestPost('https:://service.com/list');
	}
}

您可以单独访问这些方法

//If $refreshToken is equal to true, the token will be refreshed regardless of the cache
self::getToken($refreshToken);

self::requestToKeyCloak();

/*
Authorization is set in all tokens, but with this method, it is overwritten by the third parameter of post and get methods.
*/
self::HeadersProcess($newHeader);

self::requestPost(string  $url,array  $data  = [],$headers  = []);

self::requestGet(string  $url,array  $data  = [],$headers  = []);