Appearance
添加群成员为好友
通过共同群聊向群成员发好友申请。成员微信 ID 从获取群成员列表的 userName 拿。
接口地址: POST /addRoomMemberFriend
说明与注意
- 对方隐私设置不允许通过群聊添加时返回
1001,原因看message。
请求参数
| 参数名 | 必选 | 类型 | 说明 |
|---|---|---|---|
wId | 是 | string | 登录实例标识 |
chatRoomId | 是 | string | 群 ID |
memberWcId | 是 | string | 群成员的微信 ID |
content | 否 | string | 好友申请消息 |
请求示例
http
POST {BASE_URL}/addRoomMemberFriend
Authorization: Bearer <你的调用凭证>
Content-Type: application/json
{
"wId": "2c7a5bf6-e23d-4fb0-8f03-b90e844b539f",
"chatRoomId": "18061832422@chatroom",
"memberWcId": "wxid_9z89xz56uie22",
"content": "你好"
}bash
curl -X POST '{BASE_URL}/addRoomMemberFriend' \
-H 'Authorization: Bearer <你的调用凭证>' \
-H 'Content-Type: application/json' \
--data-raw '{
"wId": "2c7a5bf6-e23d-4fb0-8f03-b90e844b539f",
"chatRoomId": "18061832422@chatroom",
"memberWcId": "wxid_9z89xz56uie22",
"content": "你好"
}'python
import requests
url = "{BASE_URL}/addRoomMemberFriend"
headers = {"Authorization": "Bearer <你的调用凭证>", "Content-Type": "application/json"}
body = """{
"wId": "2c7a5bf6-e23d-4fb0-8f03-b90e844b539f",
"chatRoomId": "18061832422@chatroom",
"memberWcId": "wxid_9z89xz56uie22",
"content": "你好"
}"""
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}/addRoomMemberFriend";
String body = "{\n" +
" \"wId\": \"2c7a5bf6-e23d-4fb0-8f03-b90e844b539f\",\n" +
" \"chatRoomId\": \"18061832422@chatroom\",\n" +
" \"memberWcId\": \"wxid_9z89xz56uie22\",\n" +
" \"content\": \"你好\"\n" +
"}";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
.header("Authorization", "Bearer <你的调用凭证>")
.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}/addRoomMemberFriend';
$body = <<<'JSON'
{
"wId": "2c7a5bf6-e23d-4fb0-8f03-b90e844b539f",
"chatRoomId": "18061832422@chatroom",
"memberWcId": "wxid_9z89xz56uie22",
"content": "你好"
}
JSON;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer <你的调用凭证>',
'Content-Type: application/json',
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;成功响应
json
{
"message": "添加群好友成功",
"code": "1000",
"data": "v3_020b3826fd030100000000003c5f0ccafe295400000001ea9a3dba12f95f6b60a0536a1adb690dcccc9bf58cc80765e6eb16b92b937608dcb0a9222f1d6f88492af63e5d2b8a1fd5aa9174f287a8a9dcc631bd81887305777604164a9b37af964bf@stranger"
}错误响应
json
{
"message": "由于对方的隐私设置,你无法通过群聊将其添加至通讯录。",
"code": "1001",
"data": null
}响应参数
| 参数名 | 类型 | 说明 |
|---|---|---|
code | string | 1000 成功;其他值都是失败,通常是 1001 |
message | string | 反馈信息 |
data | string/null | 成功时返回添加好友凭证,失败时通常为空 |