Appearance
外呼充值
接口信息
- 接口:
/agent-api/user/{user_id}/recharge - 请求方式:
PUT
路由参数
| 参数 | 类型 | 示例 | 解释 | 必填 |
|---|---|---|---|---|
| user_id | string | 5433b412-07d5-44e6-9fa4-deb65e43bc93 | 用户 id | 是 |
请求参数
| 参数 | 类型 | 示例 | 解释 | 必填 |
|---|---|---|---|---|
| amount | int | 100 | 充值金额 | 是 |
| type | int | 1 | 操作类型 1-充值 2-扣费(默认值:1) | 否 |
| remark | string | API-外呼充值 | 备注 | 否 |
请求示例
cURL
curl -X PUT "https://ai.api.longlonglong.cn/agent-api/user/5433b412-07d5-44e6-9fa4-deb65e43bc93/recharge" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{
"amount": 100,
"type": 1,
"remark": "API-外呼充值"
}'Go
package main
import (
"bytes"
"fmt"
"io"
"net/http"
)
func main() {
jsonData := []byte(`{"amount": 100, "type": 1, "remark": "API-外呼充值"}`)
client := &http.Client{}
req, err := http.NewRequest("PUT", "https://ai.api.longlonglong.cn/agent-api/user/5433b412-07d5-44e6-9fa4-deb65e43bc93/recharge", bytes.NewBuffer(jsonData))
if err != nil {
panic(err)
}
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Authorization", "Bearer YOUR_TOKEN")
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}JavaScript
const response = await fetch("https://ai.api.longlonglong.cn/agent-api/user/5433b412-07d5-44e6-9fa4-deb65e43bc93/recharge", {
method: "PUT",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_TOKEN"
},
body: JSON.stringify({
amount: 100,
type: 1,
remark: "API-外呼充值"
})
});
const data = await response.json();
console.log(data);Java
import java.net.HttpURLConnection;
import java.net.URL;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
public class Main {
public static void main(String[] args) throws Exception {
URL url = new URL("https://ai.api.longlonglong.cn/agent-api/user/5433b412-07d5-44e6-9fa4-deb65e43bc93/recharge");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("PUT");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Authorization", "Bearer YOUR_TOKEN");
conn.setDoOutput(true);
String jsonInputString = "{\"amount\": 100, \"type\": 1, \"remark\": \"API-外呼充值\"}";
try (OutputStream os = conn.getOutputStream()) {
byte[] input = jsonInputString.getBytes("utf-8");
os.write(input, 0, input.length);
}
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
StringBuilder response = new StringBuilder();
while ((line = br.readLine()) != null) {
response.append(line);
}
br.close();
System.out.println(response.toString());
}
}PHP
<?php
$curl = curl_init();
$data = [
"amount" => 100,
"type" => 1,
"remark" => "API-外呼充值"
];
curl_setopt_array($curl, [
CURLOPT_URL => "https://ai.api.longlonglong.cn/agent-api/user/5433b412-07d5-44e6-9fa4-deb65e43bc93/recharge",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode($data),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"Authorization: Bearer YOUR_TOKEN"
],
]);
$response = curl_exec($curl);
curl_close($curl);
echo $response;
?>Python
import requests
url = "https://ai.api.longlonglong.cn/agent-api/user/5433b412-07d5-44e6-9fa4-deb65e43bc93/recharge"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_TOKEN"
}
data = {
"amount": 100,
"type": 1,
"remark": "API-外呼充值"
}
response = requests.put(url, json=data, headers=headers)
print(response.json())C++
#include <iostream>
#include <curl/curl.h>
#include <string>
int main() {
CURL* curl;
CURLcode res;
curl = curl_easy_init();
if (curl) {
struct curl_slist* headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
headers = curl_slist_append(headers, "Authorization: Bearer YOUR_TOKEN");
std::string jsondata = "{\"amount\": 100, \"type\": 1, \"remark\": \"API-外呼充值\"}";
curl_easy_setopt(curl, CURLOPT_URL, "https://ai.api.longlonglong.cn/agent-api/user/5433b412-07d5-44e6-9fa4-deb65e43bc93/recharge");
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, jsondata.c_str());
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}json
{
"amount": 100,
"type": 1,
"remark": "API-外呼充值"
}返回成功示例
json
{
"code": 200,
"status": "success",
"message": "AI外呼扣款操作成功",
"data": []
}错误响应
json
{
"code": 10004,
"status": "error",
"message": "用户未开通账单权限",
"data": []
}