1为什么做这个写这个文章。
通过系列文章手把手教你自己打造一套打码系统,不用去调取收费几里一次的收费api如下是笔者已经搭建的打码平台的效果
系统自带中英文你切换。已经实现了英文的识别。中文的模型将会后续继续更上。功能如下
2功能介绍:**
1中英文切换(方便外国友人使用)
2自带充值扣费系统
3自带客户端登陆
4自带admin 后台管理
3 技术架构如下,
前段管理使用php-lavarel 我之前就是phper
后端使用Python-pytorch 实现模型核心部分(重点介绍)
现在介绍第一部分前端管理。
1 lavarel compoers 安装
2路由
Route::any('/nlp/qa', 'Api\[email protected]');#识别接口
Route::any('/nlp/tag_train_tool', 'Api\[email protected]_train_tool');#识别接口
//===================================================================
Route::any('/captcha/code', 'Api\[email protected]');#识别接口
Route::any('/status/code', 'Api\[email protected]');#验证成功接口
3权限管理 省略
4 请求python api 部分
<?php
namespace App\Http\Controllers\Api;
use Illuminate\Http\Request;
use App\Http\Controllers\Api\ApiController;
use DB;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use Storage;
use App\Models\Service;
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Methods: *");
header("Access-Control-Allow-Headers: Content-Type,Access-Token");
header("Access-Control-Expose-Headers: *");
class CaptchaApiController extends ApiController
{
private $user;
public function __construct(Request $request){
$where=[];
$where['api_key']=$request->key;
$this->service =Service::where($where)->first();
if(empty($this->service)){
$info=[];
$info['error']=1;
$info['info']='error_key';
die(json_encode($info));
}
if((int)$this->service->has_month>=(int)$this->service->limit_month){
$info=[];
$info['error']=1;
$info['info']='Account exceeds month limit';
die(json_encode($info));
}
}
#亚马逊验证码s识别
public function getcode(Request $request){
header('Content-type: application/json');
$captcha_url=Request('captcha_url');
if(!$this->is_base64($captcha_url)){
$info['error']=1;
$info['info']='captcha_url未使用base64加密';
die(json_encode($info));
}
if(empty($captcha_url)){
$info['error']=1;
$info['info']='参数为空';
die(json_encode($info));
}
Service::where('id',$this->service->id)->increment('has_month');
$post_data=[];
$post_data['img_link']=$captcha_url;
$post_data['uid']=$this->service->uid;
$post_data['ip'] = $request->getClientIp();;
$postdata = http_build_query($post_data);
$options = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type:application/x-www-form-urlencoded',
'content' => $postdata,
'timeout' => 15 * 60 // 超时时间(单位:s)
)
);
$context = stream_context_create($options);
$result = file_get_contents("http://127.0.0.1:87/solve", false, $context);
die($result);
}
#亚马逊验证码识别回调
public function statuscode(Request $request){
header('Content-type: application/json');
$id=Request('id');
if( empty($id)){
$info['error']=1;
$info['info']='参数为空';
die(json_encode($info));
}
$where=[];
$where['id']=$id;
$where['gen']=1;
DB::table('amazon_code')->where($where)->update(['status' => 2]);
#$img_link=urldecode($img_link);
$info['error']=0;
$info['info']="success";
die(json_encode($info));
}
public function is_base64($str)
{
return $str == base64_encode(base64_decode($str)) ? true : false;
}
}
5,注意url 采用base64 加密post 传入,具体js加密方式请直接使用扒站工具下载
[www.886it.cn](亚马逊验证码GIF验证码识别在线测试 http://www.886it.cn)
前端部分上线逻辑较为简单。
6 admin管理端采用优美的dact-admin 实现
7想要前端的源码可以和作者联系