原由是在本人在某個除了技術其餘都聊的技術羣裏的得知一位老哥所在的公司開發了個叫ccvt的幣種,在羣裏宣傳,能夠經過邀請新用戶得到50個ccvt幣,而後還說起這個會在明年2月份上交易所並開通提現功能,我一想這個不就能夠套現,並且這個邀請註冊估計就那麼回事,可能能夠投機倒把,果斷註冊看了一把,發現能夠經過利用接碼平臺來實現虛擬號碼註冊從而達到邀請的目的。php
歡迎到本人博客上查看。html
Postman 懂得都懂
PHP7 (若是須要發送郵件報警須要 PHPMailer)
laravel5.6
chrome瀏覽器(廢話)
易碼(接碼平臺)
百度雲--文字識別之數字識別(免費的 天天500次上限)
smtp郵箱(非必須)
服務器一臺(也能夠是本身的破機)
複製代碼
本文編程語言使用PHP,其餘語言大同小異,至於爲啥用PHP--PHP是世界上最好的語言!百度雲鬚要申請文字識別的應用,由於免費的識別率不是很高,不過夠用了。易碼平臺是一個接碼平臺--至關於一個虛擬手機號能夠接收驗證碼。laravel
手機號 圖片驗證碼 短信驗證碼 2次密碼 邀請碼
複製代碼
隨便註冊一下,用chrome控制檯看下:git
能夠獲取主要請求參數:callback jq的回調
country_code 手機號所屬的國家編號 中國的是 86
cellphone 手機號
sms_code 短信驗證碼
pass_word 密碼
pass_word_hash 密碼的hash
invit_code 邀請碼
_ 時間戳
複製代碼
其餘可有可無的就不寫了,發現參數裏沒有涉及到圖片驗證碼,因此應該用於短信發送的時候驗證了,測試一把發現果真如此。github
看下接口: 能夠獲取發送驗證碼的請求參數:callback
cellphone
country_code
bind_type 默認1
cfm_code 圖片驗證碼
複製代碼
那麼再獲取到有效的驗證碼的圖片就能開始開發正式投機倒把。 驗證碼圖片接口:sql
https://ccvt.io/api/inc/code.php
複製代碼
生成的PHPSession Cookie:chrome
根據目前的幾個接口能夠有如下流程:編程
可能遇到的問題:json
3.1 獲取圖片驗證碼api
/**
* 獲取圖片驗證碼
*/
public function getAuthCode()
{
//這個請求會生成惟一的 sessionId 須要注意接口異常問題
$errorTime = 10;
$start = 0;
Resend:
//todo 獲取代理ip
$ip = "";
if ($ip) {
$this->request->set_proxy($ip);
}
$this->request->set_referer($this->referer);
$code = $this->request->get($this->code_url);
if ($code) {
$cookie = $this->request->get_cookies(self::CCVT_URL);
if (!$cookie) {
if ($start < $errorTime) {
$start++;
goto Resend;
}
$this->sendEmail('腳本告警', "獲取cookie失敗" . date("Y-m-d H:i:s"));
exit;
} else {
self::$session = $cookie;
$this->downloadCode($code);
$this->getCode();
}
}
}
/**
* 保存驗證碼圖片
* @param $image
*/
public function downloadCode($image)
{
$file = app_path('Storage/ccvt/code/');
if (!is_dir($file)) {
mkdir($file, 0777, true);
}
$file .= 'code.png';
file_put_contents($file, $image);
}
/**
* 獲取驗證碼
*/
public function getCode()
{
//經過百度ocr接口拿驗證碼存在必定的準確率
$file = app_path('Storage/ccvt/code/');
$file = $file . "code.png";
if (!file_exists($file)) {
$this->sendEmail('腳本告警', "獲取驗證碼圖片失敗!" . date("Y-m-d H:i:s"));
} else {
$ocr = new Ocr();
$code = $ocr->getCode($file);
if (is_numeric($code)) {
self::$code = $code;
} else {
$this->sendEmail('腳本告警', "百度接口識別錯誤!返回內容:</br>" . json_encode($code, JSON_UNESCAPED_UNICODE), true);
exit;
}
}
}
複製代碼
流程是: 獲取驗證碼->保存驗證碼->請求百度雲
請求百度雲的方法,具體實現能夠查看 百度雲 的接口:
public function getCode($path)
{
if (!$path) {
return false;
}
$request = new Request();
$request->set_header('Content-Type', 'application/x-www-form-urlencoded');
//圖片base64
$image = $this->base64Image($path);
$postUrl = self::OCR_NUMBER_URL . '?access_token=' . $this->getAccessToken();
$param = [
'image' => $image,
];
$result = $request->post($postUrl, $param);
$code = '';
if ($result) {
$result = json_decode($result);
if (isset($result->words_result)) {
//由於百度雲返回的不是一次識別,須要循環拿出
foreach ($result->words_result as $key => $value) {
$code .= $value->words;
}
$code = (int)$code;
} else {
return $result;
}
}
return $code;
}
複製代碼
3.2 獲取手機號併發送驗證碼
易碼的相關接口就不貼了,能夠看下 文檔:
/**
* 獲取手機號碼
*/
public function getTelephone()
{
$getUrl = sprintf($this->Telephone_Api, $this->token, $this->item_num);
$result = $this->request->get($getUrl);
if ($result) {
$results = explode('|', $result);
if ($results[0] == 'success') {
if (is_numeric($results[1])) {
self::$yima_telephone = $results[1];
} else {
//發送郵件告警
$this->sendEmail('腳本告警', "獲取yima手機號失敗 code 2!接口返回內容:</br>" . $result, true);
exit;
}
} else {
//發送郵件告警
$this->sendEmail('腳本告警', "獲取yima手機號失敗 code 1!接口返回內容:</br>" . $result, true);
exit;
}
}
}
/**
* 發送驗證碼
*/
public function sendSmsCode()
{
$getUrl = sprintf($this->send_sms, self::$yima_telephone, self::$code, time() * 1000);
$errorTime = 10;
$start = 0;
Resend:
$this->request->set_referer($this->referer);
$result = $this->request->get($getUrl);
if ($result) {
$_result = str_replace("(", '', $result);
$_result = str_replace(');', '', $_result);
$_result = json_decode($_result) ?? '';
if (isset($_result->errcode) && $_result->errcode != 0) {
$this->freeTelephone();
$this->sendEmail('腳本告警', "驗證碼發送失敗: 內容以下:</br>" . "url:" . $getUrl . "</br>返回內容:" . $result, true);
exit;
} elseif (!isset($_result->errcode)) {
if ($start < $errorTime) {
$start++;
goto Resend;
}
$this->freeTelephone();
$this->sendEmail('腳本告警', "驗證碼發送失敗3: 內容以下:</br>" . "url:" . $getUrl . "</br>返回內容:" . $result, true);
exit;
}
} else {
if ($start < $errorTime) {
$start++;
goto Resend;
}
$this->freeTelephone();
$this->sendEmail('腳本告警', "驗證碼發送失敗2: 返回數據爲空 內容以下:</br>" . "url:" . $getUrl . "</br>返回內容:" . $result, true);
exit;
}
}
/**
* 獲取短信驗證碼
*/
public function getSmsCode()
{
//須要輪詢 60秒已經很長了
$getUrl = sprintf($this->GetMessage_Api, $this->token, $this->item_num, self::$yima_telephone);
$nowTime = time();
$endTime = $nowTime + 60;
do {
if ($endTime < time()) {
//超時
break;
}
$result = $this->request->get($getUrl);
if ($result) {
$_result = explode('|', $result);
if ($_result[0] == 'success') {
$content = $_result[1];
echo "短信獲取成功:" . $content . PHP_EOL;
//釋放
if (preg_match("/\d+/", $content, $codes)) {
self::$sms_code = $codes[0];
} else {
$this->sendEmail('腳本告警', "獲取驗證碼失敗! :</br>" . $content, true);
$this->freeTelephone();
break;
}
$this->freeTelephone();
break;
} elseif ($_result[0] != 3001) {
//不是3001狀態的直接不要此次的註冊 發送郵件
$this->freeTelephone();
$this->sendEmail('腳本告警', "輪詢手機號碼異常!返回內容以下:</br>" . $result, true);
break;
}
}
//5秒要一次 可能一次要到了 睡5秒也無妨
sleep(5);
} while (!self::$sms_code);
}
/**
* 釋放手機號
*/
public function freeTelephone()
{
$getUrl = sprintf($this->Free_Telephone_Api, $this->token, $this->item_num, self::$yima_telephone);
echo "手機號釋放:" . $this->request->get($getUrl) . PHP_EOL;
}
複製代碼
腳本跑下來這裏通常是由於圖片驗證碼錯誤失敗,百度雲這個識別率真的感人。。。。
3.3 最後一步!!註冊 拼裝好參數,請求就完事兒了:
/**
* 5.註冊
*/
public function register()
{
if ($this->checkParam()) {
$getUrl = sprintf($this->register_url, self::$yima_telephone, self::$sms_code, time() * 100);
$result = $this->request->get($getUrl);
if ($result) {
//由於有callback因此須要解析
$_result = str_replace("(", '', $result);
$_result = str_replace(');', '', $_result);
$_result = json_decode($_result) ?? '';
if (isset($_result->errcode) && $_result->errcode == 0) {
//註冊成功
$this->sendEmail('註冊成功通知', "使用的手機號爲:</br>" . self::$yima_telephone . "註冊時間:</br>" . date("Y-m-d H:i:s"), true);
} else {
echo "註冊失敗!" . date('Y-m-d H:i:s') . PHP_EOL;
echo "使用手機號:" . self::$yima_telephone . "使用驗證碼:" . self::$sms_code . PHP_EOL;
echo "返回數據結構:" . json_encode($_result, JSON_UNESCAPED_UNICODE) . PHP_EOL;
}
}
}
}
/**
* 校驗必要的參數
* @return bool
*/
private function checkParam()
{
if (!self::$yima_telephone) {
return false;
}
if (!self::$sms_code) {
return false;
}
return true;
}
複製代碼
到此主要代碼就魯完了,還能夠加上代理啊,郵件報警系統呀,餘額預警呀,之類的, 註冊成功後,進我的中心看到到帳的ccvt幣內心仍是很美滋滋的。
而後將代碼放到laravel的任務調度(定時任務)去,發佈到服務器上就能夠全自動投機倒把了~~~~惋惜好景不長,在代碼運行了3天后發現註冊成功郵件都不發了,上服務器一看日誌,發現都是註冊失敗的提示,本人果斷手動執行一下發現仍是註冊失敗,而後去掉了邀請碼,發現就註冊成功了,emmmmm,我以爲仍是由於沒加代理,被他們的技術人員把邀請碼拉入黑名單了。投機倒把就這麼沒了,本人也寫下這邊文章記錄下本身當時的過程~最後,投機倒把仍是少幹,xD。
PS:這個網站好幾個接口存在sql注入的可能,以前測數據的時候發現接口會報sql錯誤,可能有sql注入的點,我沒深刻研究,後來再訪問就沒有報錯了,應該是修復了(滑稽)。
最後附上該項目的 gayhub 歡迎各位 start 或 follow