×ðÁú¿­Ê±¹ÙÍøµÇ¼

thinkphp¶àÖØת·¢

ÔÚ¿ª·¢webÓ¦ÓóÌÐòʱ£¬ÎÒÃǾ­³£ÐèÒª½«ÇëÇóת·¢µ½ÆäËûЧÀÍÆ÷»òapi¡£ÕâÖÖת·¢±»³ÆΪ·´ÏòÊðÀí£¬¿ÉÒÔ×ÊÖúÎÒÃÇʵÏÖÖîÈ縺ÔØƽºâºÍÁ÷Á¿¿ØÖƵȹ¦Ð§¡£ÔÚʹÓÃthinkphp¿ª·¢webÓ¦ÓóÌÐòʱ£¬ÎÒÃÇ¿ÉÒÔʹÓöàÖØת·¢ÊµÏÖ·´ÏòÊðÀí¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚthinkphpÖÐʹÓöàÖØת·¢¡£

Ò»¡¢Ê²Ã´ÊǶàÖØת·¢ £¿

¶àÖØת·¢ÊÇÖ¸½«ÇëÇóת·¢µ½¶à¸öЧÀÍÆ÷»òAPI¡£ÔÚ¶àÖØת·¢ÖУ¬Ã¿¸öÇëÇ󶼾­ÓÉһϵÁеÄÖÐÑë¼þ»ò¹ýÂËÆ÷£¬ÒÔ±ã¶ÔÇëÇó¾ÙÐÐÐ޸Ļòת»»¡£µ±ÇëÇóµÖ´ï×îÖÕÄ¿µÄʱ£¬ÏìÓ¦±»·´Ïòת´ï»ØÈ¥¡£ÕâÖÖ¶àÖØת·¢µÄÉè¼Æ¿ÉÒÔ×ÊÖúÎÒÃÇʵÏÖÖØ´óµÄÁ÷³ÌºÍЧÀÍ¡£

¶þ¡¢Ê¹ÓöàÖØת·¢

ÔÚThinkPHPÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ýÒýÈëHTTP¿Í»§¶ËºÍÖÐÑë¼þÀ©Õ¹À´ÊµÏÖ¶àÖØת·¢¡£HTTP¿Í»§¶Ë¿ÉÒÔ×ÊÖúÎÒÃÇ·¢ËÍHTTPÇëÇó²¢ÎüÊÕÏìÓ¦¡£ÖÐÑë¼þ¿ÉÒÔÔÚÇëÇó±»·¢ËÍÇ°ºÍÏìÓ¦±»ÎüÊÕºó¶ÔÆä¾ÙÐд¦Àí¡£ÔÚÕâЩÀ©Õ¹µÄ»ù´¡ÉÏ£¬ÎÒÃÇ¿ÉÒÔ½¨Éè×Ô¼ºµÄ¶àÖØת·¢ÖÐÑë¼þ£¬ÒÔ±ãƾ֤×Ô¼ºµÄÐèÇó´¦ÀíÇëÇóºÍÏìÓ¦¡£

Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡± £»

ÒÔÏÂÊÇÒ»¸öʹÓöàÖØת·¢µÄʾÀý£º

use GuzzleHttpClient;
use PsrHttpMessageRequestInterface;
use PsrHttpMessageResponseInterface;

class MultipleForwardMiddleware
{
    public function __invoke(callable $handler)
    {
        return function (RequestInterface $request, array $options) use ($handler) {
            // ÐÞ¸ÄÇëÇó
            $request = $request->withHeader('X-Forwarded-For', $_SERVER['REMOTE_ADDR']);

            // ·¢Ë͵ÚÒ»²ãÇëÇó
            $client = new Client();
            $response1 = $client->send($request, $options);

            // ÐÞ¸ÄÏìÓ¦
            $response1 = $response1->withHeader('Pragma', 'no-cache');

            // ·¢Ë͵ڶþ²ãÇëÇó
            $response2 = $handler($request, $options);

            // ÐÞ¸ÄÏìÓ¦
            $response2 = $response2->withHeader('Cache-Control', 'no-cache');

            // ½«ÏìÓ¦·´Ïòת´ï»ØÈ¥
            return $response1->withBody($response2->getBody());
        };
    }
}

$client = new Client([
    'handler' => new MultipleForwardMiddleware(),
]);

$response = $client->get('http://example.com/path/to/api');

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÃæµÄʾÀý´úÂëÖУ¬ÎÒÃǽç˵ÁËÒ»¸ö¶àÖØת·¢ÖÐÑë¼þ¡£ÕâÆäÖÐÑë¼þ½ÓÊÜÒ»¸ö´¦Àí³ÌÐò£¬²¢¶ÔÇëÇóºÍÏìÓ¦¾ÙÐÐһϵÁÐÐ޸ĺÍת´ï¡£ÔÚÖÐÑë¼þÖУ¬ÎÒÃÇʹÓÃÁËGuzzle HTTP¿Í»§¶ËÀ´·¢ËÍÇëÇóºÍÎüÊÕÏìÓ¦¡£¸Ã¿Í»§¶ËʹÓÃÎÒÃǽç˵µÄÖÐÑë¼þÀ´¶ÔÇëÇóºÍÏìÓ¦¾ÙÐд¦Àí¡£

Èý¡¢×ܽá

¶àÖØת·¢ÊÇÒ»¸öºÜÊÇÓÐÓõķ´ÏòÊðÀíÊÖÒÕ£¬¿ÉÓÃÓÚʵÏÖÐí¶àÖØ´óµÄÓ¦Óó¡¾°¡£ÔÚʹÓÃThinkPHP¿ª·¢WebÓ¦ÓóÌÐòʱ£¬ÎÒÃÇ¿ÉÒÔʹÓÃHTTP¿Í»§¶ËºÍÖÐÑë¼þÀ©Õ¹À´ÊµÏÖ¶àÖØת·¢¡£Í¨¹ý±àд×Ô¼ºµÄ¶àÖØת·¢ÖÐÑë¼þ£¬ÎÒÃÇ¿ÉÒÔƾ֤×Ô¼ºµÄÐèÇó´¦ÀíÇëÇóºÍÏìÓ¦¡£

ÒÔÉϾÍÊÇthinkphp¶àÖØת·¢µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ