Skip to content

添加好友 ​

向搜索到的联系人发送好友申请。v1、v2 先用搜索联系人拿。

接口地址: POST /addUser

说明与注意 ​

请求参数 ​

参数名必选类型说明
wId是string登录实例标识
v1是string添加好友凭证,从搜索联系人接口获取
v2是string添加好友凭证,从搜索联系人接口获取
type是int添加来源:3 微信号搜索、4 QQ 好友、8 群聊、15 手机号
verify是string验证消息

请求示例 ​

http
POST {BASE_URL}/addUser
Authorization: Bearer <你的调用凭证>
Content-Type: application/json

{
  "wId": "0000016f-a2f0-03e3-0003-65e826091614",
  "v1": "v1_aaf94e13d0058cdc888e388b98952e0fc23212d180e4dacb38b96dfe4b078c488e72772f907517470ac0b9b7311826da@stranger",
  "v2": "v2_13ced007472228cd1545feecf78b99f9a57a88843374513747afc7ac25d8a4cccb77590b7a9b01a96c941e047d137bbb@stranger",
  "type": 3,
  "verify": "你好"
}
bash
curl -X POST '{BASE_URL}/addUser' \
  -H 'Authorization: Bearer <你的调用凭证>' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "wId": "0000016f-a2f0-03e3-0003-65e826091614",
  "v1": "v1_aaf94e13d0058cdc888e388b98952e0fc23212d180e4dacb38b96dfe4b078c488e72772f907517470ac0b9b7311826da@stranger",
  "v2": "v2_13ced007472228cd1545feecf78b99f9a57a88843374513747afc7ac25d8a4cccb77590b7a9b01a96c941e047d137bbb@stranger",
  "type": 3,
  "verify": "你好"
}'
python
import requests

url = "{BASE_URL}/addUser"
headers = {"Authorization": "Bearer <你的调用凭证>", "Content-Type": "application/json"}
body = """{
  "wId": "0000016f-a2f0-03e3-0003-65e826091614",
  "v1": "v1_aaf94e13d0058cdc888e388b98952e0fc23212d180e4dacb38b96dfe4b078c488e72772f907517470ac0b9b7311826da@stranger",
  "v2": "v2_13ced007472228cd1545feecf78b99f9a57a88843374513747afc7ac25d8a4cccb77590b7a9b01a96c941e047d137bbb@stranger",
  "type": 3,
  "verify": "你好"
}"""

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}/addUser";
String body = "{\n" +
    "  \"wId\": \"0000016f-a2f0-03e3-0003-65e826091614\",\n" +
    "  \"v1\": \"v1_aaf94e13d0058cdc888e388b98952e0fc23212d180e4dacb38b96dfe4b078c488e72772f907517470ac0b9b7311826da@stranger\",\n" +
    "  \"v2\": \"v2_13ced007472228cd1545feecf78b99f9a57a88843374513747afc7ac25d8a4cccb77590b7a9b01a96c941e047d137bbb@stranger\",\n" +
    "  \"type\": 3,\n" +
    "  \"verify\": \"你好\"\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}/addUser';
$body = <<<'JSON'
{
  "wId": "0000016f-a2f0-03e3-0003-65e826091614",
  "v1": "v1_aaf94e13d0058cdc888e388b98952e0fc23212d180e4dacb38b96dfe4b078c488e72772f907517470ac0b9b7311826da@stranger",
  "v2": "v2_13ced007472228cd1545feecf78b99f9a57a88843374513747afc7ac25d8a4cccb77590b7a9b01a96c941e047d137bbb@stranger",
  "type": 3,
  "verify": "你好"
}
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
{
  "code": "1000",
  "message": "成功",
  "data": null
}

错误响应 ​

添加失败时 code 为 "1001",message 是微信返回的原因,data.busCode 为 "2001":

json
{
  "code": "1001",
  "message": "微信返回的失败原因",
  "data": {
    "errMsg": "微信返回的失败原因",
    "busCode": "2001"
  }
}

响应参数 ​

参数名类型说明
codestring1000 成功;其他值都是失败,通常是 1001
messagestring反馈信息
datanull / object成功时为空
data.busCodestring添加失败时才有,固定为 "2001";失败原因看 message,常见是添加太频繁
data.errMsgstring添加失败时才有,同 message,是微信返回的原因