# Tiktok Captcha

## Create task

<mark style="color:green;">`POST`</mark> `https://hmcaptcha.com/Recognition?wait=1`

**1.SLIDE CAPTCHA**

<img src="https://486404770-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZfSw37qFaqBImNsbyjFj%2Fuploads%2FKtOys2FLHziFzkwPCucK%2F7.PNG?alt=media&#x26;token=06607d0a-91f5-4857-9644-8490f97acb01" alt="" data-size="original">

**Example** `https://hmcaptcha.com/Recognition?wait=1`

`{`\
&#x20;    `"Apikey": "YOUR APIKEY",`\
&#x20;    `"Type": "ALL_CAPTCHA_SLIDE",`\
&#x20;    `"Image": "Image as base64 encoded"`\
`}`

**2.SELECT 2 OBJECT**

<div align="left"><figure><img src="https://486404770-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZfSw37qFaqBImNsbyjFj%2Fuploads%2Fle2O7tP7CdLQDAV91ZFy%2F1.jpg?alt=media&#x26;token=c207e81e-5e65-4f67-87fc-2a78dd1f574d" alt="" width="375"><figcaption></figcaption></figure></div>

**Example** `https://hmcaptcha.com/Recognition?wait=1`

`{`\
&#x20;    `"Apikey": "YOUR APIKEY",`\
&#x20;    `"Type": "TIKTOK_OBJ",`\
&#x20;    `"Image": "Image as base64 encoded",`\
&#x20;    `"URL_Image": "Required if Image is missing."`\
`}`

`` Note: chỉ cần 1 trong 2 tham số `Image` hoặc `URL_Image` ``

**3.ROTATE CAPTCHA APP**

<div align="left"><figure><img src="https://486404770-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZfSw37qFaqBImNsbyjFj%2Fuploads%2FjbapJVIjZAFTG1qz8mT8%2Fcaptcha.png?alt=media&#x26;token=05793daa-1af6-4168-9d6e-8f17ad72e1dc" alt="" width="294"><figcaption></figcaption></figure></div>

**Example** `https://hmcaptcha.com/Recognition?wait=1`

`{`\
&#x20;    `"Apikey": "YOUR APIKEY",`\
&#x20;    `"Type": "TIKTOK_ROTATE_APP",`\
&#x20;    `"Image": "Image as base64 encoded"`\
`}`

`Note: Image gửi lên là ảnh chụp màn hình hoặc ảnh chỉ lấy phần captcha`

**4.ROTATE CAPTCHA WEB**

<img src="https://486404770-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZfSw37qFaqBImNsbyjFj%2Fuploads%2FkxFH1Oi6UpfeVniaxZZD%2FCapxoaytest25a.PNG?alt=media&#x26;token=4902087b-ca72-45f8-94d3-f0c60f8781d0" alt="" data-size="original">

**Example** `https://hmcaptcha.com/Recognition?wait=1`

`{`\
&#x20;    `"Apikey": "YOUR APIKEY",`\
&#x20;    `"Type": "TIKTOK_ROTATE_WEB",`\
&#x20;    `"URL_Image1": "url image 1 of captcha (ảnh bên trong)",`\
&#x20;    `"URL_Image2": "url image 2 of captcha (ảnh bên ngoài)"`\
`}`

#### Query Parameters

| Name | Type | Description                                                                                                                                       |
| ---- | ---- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| wait | Bool | If the 'wait=1' parameter is added to the URL, the result will return immediately after the captcha is solved without needing to call 'getResult' |

#### Headers

| Name                                           | Type   | Description      |
| ---------------------------------------------- | ------ | ---------------- |
| Content-Type<mark style="color:red;">\*</mark> | String | application/json |

#### Request Body

<table data-full-width="false"><thead><tr><th width="163">Name</th><th width="87">Type</th><th>Description</th></tr></thead><tbody><tr><td>Apikey<mark style="color:red;">*</mark></td><td>String</td><td>The apikey or subscription key</td></tr><tr><td>Type<mark style="color:red;">*</mark></td><td>String</td><td><p><code>ALL_CAPTCHA_SLIDE</code><br><code>TIKTOK_OBJ</code><br><code>TIKTOK_ROTATE_APP</code></p><p><code>TIKTOK_ROTATE_WEB</code></p></td></tr><tr><td>Image</td><td>String</td><td>Image encoded as base64</td></tr><tr><td>URL_Image</td><td>String</td><td>Required if <code>Image</code> is missing. </td></tr><tr><td>Question</td><td>String</td><td><p>Questions in English,<br>Not required,</p><p>default: "<code>Select 2 objects that are the same shape</code>"</p></td></tr><tr><td>ref</td><td>String</td><td>Add to get referral money</td></tr></tbody></table>

{% tabs %}
{% tab title="200: OK OK" %}

```json
{
    "Code": 0,
    "TaskId": 123456,
    "Message": "OK"
}
```

{% endtab %}

{% tab title="200: OK FAILED" %}

```json
{
    "Code": 1,
    "Message": "Error description"
}
```

{% endtab %}
{% endtabs %}

## Get result

<mark style="color:blue;">`GET`</mark> `https://hmcaptcha.com/getResult?apikey={your_apikey}&taskid={taskid}`

**Example** `https://hmcaptcha.com/getResult?apikey=admin_goiZ4dxa1GNHHRt0He8KEnrfYJCz3JE&taskid=12345`

#### Query Parameters

| Name                                     | Type   | Description                          |
| ---------------------------------------- | ------ | ------------------------------------ |
| apikey<mark style="color:red;">\*</mark> | String | The user apikey. Get it in dashboard |
| taskid<mark style="color:red;">\*</mark> | String | The task id from Create Task step    |

{% tabs %}
{% tab title="200: OK PENDING " %}

```json
{
    "Code": 0,
    "Status": "PENDING",
    "Data": null
}
```

{% endtab %}

{% tab title="200: OK PROCESSING" %}

```json
{
    "Code": 0,
    "Status": "PROCESSING",
    "Data": null
}
```

{% endtab %}

{% tab title="200: OK ERROR" %}

```json
{
    "Code": 0,
    "Status": "ERROR",
    "Message": "Error message detail"
    "Data": null
}
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="200: OK SUCCESS (slide)" %}

```json
{
    "Code": 0,
    "Status": "SUCCESS",
    "Data": {
            "offset": 78, // Drag to right 78px
            "x": 210,
            "y": 652 // point button slide
        }
}
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="200: OK SUCCESS (2 obj)" %}

```json
{
    "Code": 0,
    "Status": "SUCCESS",
    "Data": {
            "x1y1x2y2":"678|427|540|564",
            "raw":"0.61413,0.62064|0.48913,0.819767" // x1,y1|x2,y2 ...
        }
}
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="200: OK SUCCESS (rotate web)" %}

```json
{
    "Code": 0,
    "Status": "SUCCESS",
    "Data": {
            "angle": 78
        }
}
```

{% endtab %}

{% tab title="200: OK SUCCESS (rotate app)" %}

```json
{
    "Code": 0,
    "Status": "SUCCESS",
    "Data": {
            "angle": 78,
            "point_slide": {"x": 210, "y": 652} // point button slide
        }
}
```

{% endtab %}
{% endtabs %}

### Hướng dẫn thêm cho captcha xoay

* Kết quả nhận được sau khi giải là độ (angle), muốn chuyển đổi sang pixel để kéo cần tính theo công thức sau:&#x20;

```python
# Tính offset
offset = angle * width * 0.00446837493
# hoặc
offset = angle * (width_slide/180)
```

* Với width (độ rộng thanh trượt) được lấy như ảnh sau:

<div><figure><img src="https://486404770-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZfSw37qFaqBImNsbyjFj%2Fuploads%2FZhS9LSRPZsIASVX45Yaa%2Fimage.png?alt=media&#x26;token=9cf6b6b7-2507-4cac-b056-d0cb81546107" alt="" width="375"><figcaption></figcaption></figure> <figure><img src="https://486404770-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZfSw37qFaqBImNsbyjFj%2Fuploads%2F4PPb4xCCu49lix3JyRu9%2FNew%20Project%20(51).png?alt=media&#x26;token=bc792f5f-6a12-4c7f-b927-f6eb55efc8ca" alt="" width="375"><figcaption></figcaption></figure></div>

```python
# Some code (TIKTOK_ROTATE_APP)
response = {
    "Code": 0,
    "Status": "SUCCESS",
    "Data": {
            "angle": 78,
            "point_slide": {"x": 210, "y": 652} // point button slide
        }
}

# Lấy kết quả 'angle' trong phản hồi
angle = response["Data"]["angle"]

# Tính offset
# offset = angle * width * 0.00446837493
# hoặc
offset = angle * (width_slide/180)

# Tính lại tọa độ để kéo (trên app tiktok)
x1 = response["Data"]["point_slide"]["x"]
y1 = y2 = response["Data"]["point_slide"]["y"]
x2 = x1 + offset

ADB_exec(f"adb shell input touchscreen swipe {x1} {y1} {x2} {y2}")
```

### Hướng dẫn thêm cho captcha chọn đối tượng giống nhau

* Kết quả nhận được: `{"raw": "0.61413,0.62064|0.48913,0.819767"}`  // x1,y1|x2,y2 ...
* Tính tọa độ click như sau:

```python
# Some code (TIKTOK_OBJ)
response = {
    "raw": "0.61413,0.62064|0.48913,0.819767"
}
for pn in response['raw'].split('|'):
    xn, yn = pn.split(',')
    xn, yn = float(xn), float(yn)
    x = int(xn * image.renderWidth)
    y = int(xn * image.renderHeight)
    click(x, y)
```

<figure><img src="https://486404770-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZfSw37qFaqBImNsbyjFj%2Fuploads%2FGUjnAAFx0lhrfv0zfBUP%2Fimage.png?alt=media&#x26;token=441c2ed3-cc8d-497d-b8f8-b024880d8053" alt=""><figcaption></figcaption></figure>

### Hướng dẫn thêm cho captcha slide trên phone

```python
# Tiktok thêm một số tỉ lệ khiến cho kéo theo offset không chính xác
# (kéo 45px nhưng mảnh ghép chạy đến 57px rồi)
# Nếu bị thì fix bằng công thức sau
offset = offset * (45 / 57)

```
