YunShang API

Buy (buy)

Purchases a package per-call and returns the order with dedicated credentials. Package-priced APIs only; buyout APIs cannot be purchased per-call. Sales/admin only.

API info

ItemValue
EndpointPOST /api.php
actionbuy
AuthenticationGlobal APP ID / APP KEY
Role restrictionSales / admin only

Request parameters

ParameterTypeRequiredDescription
api_idintYesAPI ID
callsintYesNumber of calls (>0)
monthsintYesValidity in months (1-12)

Request example

{
    "action": "buy",
    "app_id": "68B0FA47FEC9E7EBC4BF80F8",
    "app_key": "2b901515a427b6c0b68f866eece70e0d2ecf687146022412",
    "api_id": 4,
    "calls": 100,
    "months": 1
}

PHP

<?php
$app_id = '68B0FA47FEC9E7EBC4BF80F8';
$app_key = '2b901515a427b6c0b68f866eece70e0d2ecf687146022412';
$url = 'https://yunsapi.com/api.php';

$params = [
    'action'  => 'buy',
    'app_id'  => $app_id,
    'app_key' => $app_key,
    'api_id'  => 4,
    'calls'   => 100,
    'months'  => 1,
];

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$resp = curl_exec($ch);
curl_close($ch);
echo $resp;

Java

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class ApiDemo {
    static final String URL = "https://yunsapi.com/api.php";
    static final String APP_ID = "68B0FA47FEC9E7EBC4BF80F8";
    static final String APP_KEY = "2b901515a427b6c0b68f866eece70e0d2ecf687146022412";

    public static void main(String[] args) throws Exception {
        String body = "{\"action\":\"buy\",\"app_id\":\"" + APP_ID + "\",\"app_key\":\"" + APP_KEY + "\",\"api_id\":4,\"calls\":100,\"months\":1}";
        HttpClient client = HttpClient.newHttpClient();
        HttpRequest req = HttpRequest.newBuilder()
                .uri(URI.create(URL))
                .header("Content-Type", "application/json")
                .POST(HttpRequest.BodyPublishers.ofString(body))
                .build();
        HttpResponse<String> resp = client.send(req, HttpResponse.BodyHandlers.ofString());
        System.out.println(resp.body());
    }
}

Response example

{
    "code": 0,
    "msg": "purchased",
    "data": {
        "order_id": "34",
        "amount": 2.8000,
        "calls": 100,
        "expire_time": "2027-08-14 01:45:01",
        "order_app_id": "15AC1BF22009DB47C72358E0",
        "order_app_key": "f3847539631cc4c4e4da1e8bece180b129e02bb60ec3234a"
    }
}

Response parameters

ParameterTypeDescription
data.order_idstringOrder ID
data.amountfloatAmount actually paid
data.callsintCalls purchased
data.expire_timestringExpiry time
data.order_app_idstringDedicated APP ID
data.order_app_keystringDedicated APP KEY