Appearance
同意新客户
对方主动申请添加你为好友/客户时,调用本接口同意。
请求参数
| 参数 | 必填 | 类型 | 说明 |
|---|---|---|---|
appid | 是 | string | 实例 appid,标识操作哪个已登录账号。示例:we_xxxxxxxxxxxxxxx |
userId | 是 | int64 | 申请添加的客户 id。示例:7881300286335405 |
请求示例
http
POST {BASE_URL}/wx-api/api/contact/agreeToNewCustomer
Authorization: Bearer <你的 App Token>
Content-Type: application/json
{
"appid": "we_xxxxxxxxxxxxxxx",
"userId": 7881300286335405
}bash
curl -X POST '{BASE_URL}/wx-api/api/contact/agreeToNewCustomer' \
-H 'Authorization: Bearer <你的 App Token>' \
-H 'Content-Type: application/json' \
--data-raw '{
"appid": "we_xxxxxxxxxxxxxxx",
"userId": 7881300286335405
}'python
import requests
url = "{BASE_URL}/wx-api/api/contact/agreeToNewCustomer"
headers = {"Authorization": "Bearer <你的 App Token>", "Content-Type": "application/json"}
body = """{
"appid": "we_xxxxxxxxxxxxxxx",
"userId": 7881300286335405
}"""
resp = requests.post(url, headers=headers, data=body.encode("utf-8"))
print(resp.text)java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
String url = "{BASE_URL}/wx-api/api/contact/agreeToNewCustomer";
String body = "{\n" +
" \"appid\": \"we_xxxxxxxxxxxxxxx\",\n" +
" \"userId\": 7881300286335405\n" +
"}";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
.header("Authorization", "Bearer <你的 App Token>")
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());php
<?php
$url = '{BASE_URL}/wx-api/api/contact/agreeToNewCustomer';
$body = <<<'JSON'
{
"appid": "we_xxxxxxxxxxxxxxx",
"userId": 7881300286335405
}
JSON;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer <你的 App Token>',
'Content-Type: application/json',
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;响应示例
响应字段
| 字段 | 类型 | 说明 |
|---|---|---|
code | int64 | 统一封套状态码:0=成功,负数=失败 |
detail | string | 附加明细,通常为空 |
message | string | 文案:成功为 ok;失败形如 -码|描述 |
time | string | 服务端处理时间 YYYY-MM-DD HH:MM:SS |
常见错误
下表为企微错误码。业务失败时顶层 code=-1,具体错误码在 message 的 | 前,例如 -3004|参数错误;鉴权与网关错误见错误码。
| 错误码 | 含义 | 怎么办 |
|---|---|---|
-18000003 | 无对应好友申请 | — |