Skip to content

Device Service Request APIs

This page describes WeChat VoIP calling service APIs that the device accesses through TiRtcServiceRequest.

These APIs are accessed by Nano SDK using the device identity. The SDK internally sends an HTTP request to the TiRTC cloud. Device applications only need to pass the API path, JSON request body, and callback; do not build HTTP URLs, signing headers, or access tokens manually.

c
int TiRtcServiceRequest(const char *path,
                        const char *json_body,
                        const char *token,
                        TIRTCSERVICEREQUESTCALLBACK cb,
                        void *user_data);
ParameterDescription
pathService API path, for example /v1/wxvoip/reject.
json_bodyRequest JSON string. Passing NULL uses GET; otherwise POST is used.
tokenAuthorization token when accessing as a client; pass NULL when accessing as a device.
cbCallback for platform response data, if any.
user_dataUser context pointer passed through to cb.

API List

MethodPathDescription
POST/v1/wxvoip/rejectReject or busy before the call is connected.

Reject: POST /v1/wxvoip/reject

Purpose

When the Mini Program calls the device and the device rejects or is busy before connection, call this API to notify the WeChat VoIP calling cloud to end the waiting call.

At this point the device has not established a TiRTC connection, so it cannot send the hang-up command (cmdw=0x2001) over the command channel. After a TiRTC connection has been established, hang-up, reject, busy, and similar states use the hang-up command (cmdw=0x2001) as defined in WeChat VoIP Calling Commands.

Request

c
TiRtcServiceRequest("/v1/wxvoip/reject", json_body, NULL, cb, user_data);

Body (JSON)

FieldTypeRequiredDescription
wx_app_idstringYesMini Program appId. From wxa_join_voip_room delivered by the business server.
wx_model_idstringYesWeChat hardware device model ID for WeChat VoIP calling.
wx_session_tokenstringYesserver_token from the WeChat join_voip_room notification; your business payload may name the same value wxa_server_token.
wx_room_idstringYesWeChat room ID.
wx_payloadstringNoCaller passthrough payload. Defaults to an empty string when omitted.
hangup_reasonnumberYesHang-up reason value; see Hang-up reasons.

Common hangup_reason values:

ScenarioValue
Device busy5
User rejects7

Example

json
{
  "wx_app_id": "wx0123456789abcdef",
  "wx_model_id": "model-1",
  "wx_session_token": "server-token",
  "wx_room_id": "room-123",
  "wx_payload": "",
  "hangup_reason": 7
}

Response

On success, the callback response body has this shape:

json
{
  "code": 0,
  "msg": "ok"
}

On failure, code is non-zero and msg contains the reason. Device applications should log failed responses and, if needed, end the local ringing state according to business policy.

Possible error codes:

codeTypical scenario
40001Failed to read request body.
40013JSON parsing failed, a required field is missing, or hangup_reason is outside 0..20.
40103Authorization failed, usually because the device secret is wrong or the device clock skew is too large.
50001tgwxvoip --hangup execution failed or the executable path is not configured.

Return Value

The synchronous return value of TiRtcServiceRequest indicates whether the request was started; the actual business response is returned through the callback:

Return valueDescription
0Request started successfully; response is returned through the callback.
< 0SDK parameter, state, network, or similar error.
> 0HTTP status is not 200; see the platform callback data for details.

WeChat VoIP calling