laravelʵÏÖË¢Á³µÇ¼
Ëæ×ÅÒƶ¯»¥ÁªÍøµÄ¿ìËÙÉú³¤£¬ÈËÁ³Ê¶±ðÊÖÒÕÖð½¥±»ÆÕ±éÓ¦Ó᣶øË¢Á³µÇ¼£¬×÷ΪһÖÖÈËÁ³Ê¶±ðµÄÓ¦Ó÷½·¨£¬Ë²¼ä¾Í³ÉΪÁËÒƶ¯¶ËÓ¦ÓÃÖйãÊܽӴýµÄµÇ¼·½·¨Ö®Ò»¡£ÄÇô£¬ÈôÊÇʹÓà laravel ¿ò¼ÜÀ´ÊµÏÖË¢Á³µÇ¼ÄØ£¿ÕâƪÎÄÕ½«Îª¶ÁÕßÏÈÈÝÔõÑùÔÚ laravel ÖÐʹÓÃÈËÁ³Ê¶±ðÊÖÒÕʵÏÖË¢Á³µÇ¼¹¦Ð§¡£
ʲôÊÇÈËÁ³Ê¶±ðÊÖÒÕ
ÈËÁ³Ê¶±ðÊÖÒÕÊÇÒ»ÖÖ¿ÉÒÔʶ±ðÈËÁ³ÐÅÏ¢µÄÊÖÒÕ£¬Í¨³£Ê¹ÓÃÉãÏñÍ·»ñÈ¡ÈËÁ³Í¼Ïñ£¬ÍŽáͼÏñ´¦Àí¡¢È˹¤ÖÇÄܵÈÊÖÒÕ£¬ÆÊÎöͼƬÖеÄÌØÕ÷ÐÅÏ¢£¬Í¨¹ý±ÈÕÕÒÑÓеÄÈËÁ³¿âÊý¾Ý£¬µÖ´ï׼ȷʶ±ðһСÎÒ˽ÈËÉí·ÝµÄÄ¿µÄ¡£
ÏÖÏÖÔÚ£¬ÈËÁ³Ê¶±ðÊÖÒÕÒѱ»ÆÕ±éÓ¦ÓÃÓÚ¸÷¸öÐÐÒµ¡£ÀýÈ磬ÔÚ¹«°²ºÍÁìÍÁÇå¾²µÈÁìÓò£¬ÈËÁ³Ê¶±ðÊÖÒÕÒѳÉΪ±Ø±¸ÊÖÒÕ£»ÔÚ½ðÈں͵çÉÌÁìÓò£¬ÈËÁ³Ê¶±ðÊÖÒÕÒ²±»ÆÕ±éÓ¦ÓÃÓÚÉí·ÝÈÏÖ¤ºÍÖ§¸¶µÈÓªÒµ³¡¾°¡£
Laravel ÖÐʹÓÃÈËÁ³Ê¶±ðÊÖÒÕʵÏÖË¢Á³µÇ¼ÓÐÄÄЩÓÅÊÆ
Laravel ÊÇÏÖÔÚÊ®·ÖÊ¢ÐÐµÄ PHP ¿ª·¢¿ò¼ÜÖ®Ò»£¬ÏÕЩӵÓÐÍêÕûµÄ¹¦Ð§ºÍ×é¼þ£¬¿ÉÒÔ¼«´óµØïÔÌÖظ´±àдºÍά»¤´úÂëµÄʱ¼ä±¾Ç®¡£Laravel Ö§³ÖʹÓÃÖÖÖÖµÚÈý·½¿âºÍ°üÀ´ÊµÏÖÖØ´óµÄ¹¦Ð§£¬ÈËÁ³Ê¶±ðÊÖÒÕÒ²²»ÆÆÀý¡£
¹ØÓÚʹÓÃÈËÁ³Ê¶±ðÊÖÒÕʵÏÖË¢Á³µÇ¼£¬Laravel ¾ßÓÐÐí¶àÓÅÊÆ¡£Ê×ÏÈ£¬Laravel ÊÖÒÕÕ»½ÏÁ¿³ÉÊ죬СÎÒ˽È˺ÍСÍŶӶ¼¿ÉÒÔÇáËÉʹÓÃËüÀ´ÊµÏÖÖØ´óµÄÓªÒµ³¡¾°¡£Æä´Î£¬Laravel Ö§³ÖʹÓà Composer ×°ÖõÚÈý·½°ü£¬ÎÒÃÇ¿ÉÒÔºÜÈÝÒ׵ؽ«ÈËÁ³Ê¶±ðÊÖÒÕ¼¯³Éµ½ÎÒÃÇµÄ Laravel ÏîÄ¿ÖС£×îºó£¬Laravel ÄÚÖÃÁËÐí¶àÓÅÒìµÄÀ©Õ¹°ü£¬ÀýÈç Passport£¨ÊÚȨ°ü£©¡¢Socialite£¨Éç½»ÊÚȨ°ü£©µÈ£¬ÕâЩÀ©Õ¹°üµÄ±£´æ£¬Ê¹µÃ Laravel ÔÚʵÏÖ¶àÖֵǼÈÏÖ¤·½·¨Ê±Ô½·¢ÇáËɺ͸ßЧ¡£
ÔõÑùʹÓà Laravel ʵÏÖË¢Á³µÇ¼
ÔÚ Laravel ÖÐʹÓÃÈËÁ³Ê¶±ðÊÖÒÕʵÏÖË¢Á³µÇ¼£¬Ö÷Òª·ÖΪÒÔϼ¸¸ö°ì·¨£º
µÚÒ»²½£º×°Öà Laravel
×°Öà Laravel ÊÇʹÓà Laravel ÊÖÒÕջʵÏÖË¢Á³µÇ¼±ØÐèµÄµÚÒ»²½¡£ÔÚ±¾ÎÄÖУ¬ÎÒÃÇʹÓà Laragon ¹¤¾ßÀ´×°ÖúÍÉèÖà Laravel¡£
µÚ¶þ²½£º×°Öà OpenCV
OpenCV ÊÇÒ»ÖÖ¿ªÔ´µÄÈ˹¤ÖÇÄÜÊÓ¾õ¿â£¬¿ÉÒÔ×ÊÖúÎÒÃÇÔÚ Laravel Öй¹½¨ÈËÁ³Ê¶±ð¹¦Ð§¡£ÔÚ±¾ÎÄÖУ¬ÎÒÃÇʹÓà OpenCV À´ÊµÏÖÈËÁ³¼ì²âºÍÉí·ÝÈ·ÈÏÊÖÒÕ¡£
µÚÈý²½£º×°Öà FaceSDK
FaceSDK ÊÇÒ»¸ö»ùÓÚ HTTP µÄ¿ªÔ´ÈËÁ³Ê¶±ðЧÀÍ£¬ÌṩÁËʶ±ðÈËÁ³¡¢±È¶ÔÈËÁ³¡¢ÆÊÎöÈËÁ³µÈ¹¦Ð§£¬»¹Ö§³Ö×Ô½ç˵ÈËÁ³¿âºÍÈËÁ³¼ìË÷¹¦Ð§¡£ÔÚ±¾ÎÄÖУ¬ÎÒÃÇʹÓà FaceSDK À´Íê³ÉÈËÁ³Ê¶±ðÊÖÒÕ¡£
µÚËIJ½£ºÇ°¶ËÒ³ÃæÖÆ×÷
½¹µã°ì·¨
ÏÂÃæÊÇʵÏÖË¢Á³µÇ¼¹¦Ð§µÄ½¹µã°ì·¨£º
µÚÒ»²½£¬ÔÚ app/Http/Controllers/Auth/LoginController.php ÖÐÐÂÔöÒ»¸ö faceLogin ÒªÁ죬¸ÃÒªÁìÓÃÓÚ´¦ÀíË¢Á³µÇ¼µÄÏà¹ØÂß¼£¬ÈçÏÂËùʾ£º
public function faceLogin(Request $request) { // ŲÓà FaceSDK ¾ÙÐÐÈËÁ³¼ìË÷ }
µÇ¼ºó¸´ÖÆ
µÚ¶þ²½£¬ÔÚ routes/web.php ÖÐÔöÌíÒ»¸öеķÓÉ£¬ÈçÏÂËùʾ£º
Route::post('/face-login', 'AuthLoginController@faceLogin')->name('face-login');
µÇ¼ºó¸´ÖÆ
µÚÈý²½£¬Ç°¶ËÒ³Ãæ¾ÙÐÐˢУ¬ÔöÌíÒ»¸ö¡°Ë¢Á³µÇ¼¡±°´Å¥£¬µ±Óû§µã»÷¡°Ë¢Á³µÇ¼¡±°´Å¥Ê±£¬Ç°¶ËÒ³Ãæͨ¹ýÉãÏñÍ·½«Óû§µÄÈËÁ³Í¼ÏñÉÏ´«µ½ºó¶Ë¾ÙÐÐÈËÁ³Ê¶±ð£¬Ê¶±ðͨʺ󣬽«Óû§ÐÅÏ¢´æÈë»á»°²¢Ìøתµ½Ê×Ò³¡£
<button class="btn btn-primary" type="button" id="face-login">Ë¢Á³µÇ¼</button> <script type="text/javascript"> $('#face-login').click(function() { // »ñÈ¡ÉãÏñÍ·²¢ÉÏ´«ÈËÁ³Í¼Ïñµ½ºó¶Ë¾ÙÐÐʶ±ð }); </script>
µÇ¼ºó¸´ÖÆ
µÚËIJ½£¬Ê¹Óà FaceSDK ¶ÔÓû§ÈËÁ³Í¼Ïñ¾ÙÐмìË÷£¬Æ¥Åäºǫ́ÉúÑĵÄÈËÁ³¿âÐÅÏ¢£¬È·ÈϸÃÓû§ÊÇ·ñÊÇÕýµ±Óû§¡£
function checkFaceImage(faceImage, callback) { var formData = new FormData(); formData.append("api_key", "FaceSDK_API_Key"); formData.append("api_secret", "FaceSDK_API_Secret"); formData.append("faceset_token", "Your_Faceset_Token"); formData.append("image_file", faceImage); $.ajax({ url: "https://api-cn.faceplusplus.com/facepp/v3/search", cache: false, contentType: false, processData: false, data: formData, type: "POST", dataType: "JSON", success: function (result) { if (result.results[0].confidence > 70) { callback(true); } else { callback(false); } }, error: function () { callback(false); } }); }
µÇ¼ºó¸´ÖÆ
µÚÎå²½£¬ÈôÊÇÈËÁ³Ê¶±ðÀֳɣ¬½«Óû§ÐÅÏ¢´æÈë»á»°²¢Ìøתµ½Ê×Ò³£»²»È»£¬ÌáÐÑÓû§¾ÙÐÐÖØÐÂʵÑéÉÏ°¶¡£
if (result.results[0].confidence > 70) { $.ajax({ url: "/login", data: {email: "face-login@laravel.com"}, type: "POST", success: function () { callback(true); } }); } else { alert("ÈËÁ³Ñé֤Ƿºà¹ý"); }
µÇ¼ºó¸´ÖÆ
×ܽá
ʹÓà Laravel ÊÖÒÕջʵÏÖË¢Á³µÇ¼¹¦Ð§£¬¿ÉÒÔΪÓû§ÌṩԽ·¢¿ì½Ý¡¢Çå¾²¡¢¸ßЧµÄµÇ¼ÌåÑ飬ïÔÌÓû§µÄÈÏ֤ʱ¼ä£¬¿ÉÒÔͨ¹ýïÔÌ·±ËöµÄ×¢²áÀú³Ì£¬ÎüÒý¸ü¶àÓû§µÄ×¢²áºÍʹÓá£ÔÚʵÏÖË¢Á³µÇ¼µÄÀú³ÌÖУ¬ÎÒÃÇʹÓÃÁË OpenCV ¾ÙÐÐÈËÁ³¼ì²â£¬Ê¹Óà FaceSDK ¾ÙÐÐÈËÁ³Ê¶±ðµÈÊÖÒÕ£¬Æ½Ì¨µÄÇå¾²ÐÔºÍÎȹÌÐÔ»ñµÃ°ü¹Ü¡£Ï£Íû±¾ÎÄÄܹ»×ÊÖú¶ÁÕßÏàʶÔõÑùÔÚ Laravel ÖÐʹÓÃÈËÁ³Ê¶±ðÊÖÒÕʵÏÖË¢Á³µÇ¼µÄÒªÁì¼°ÆäÀûÒæ¡£
ÒÔÉϾÍÊÇlaravelʵÏÖË¢Á³µÇ¼µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡