2.我尝试向用户“ members.1”发送消息。
我用:
-语言-C#;
-WinForm;
-建议-https://developers.viber.com/docs/api/rest-bot-api/#send-message;
-对于“ Receiver”:“ 01234567890A =”我使用item.1中的“ id”->图片4-> id
我使用代码。
class ViberMessage
{
public string Receiver { get; set; }
/// <summary>
/// Minimum API version required by clients for this message (default 1)
/// </summary>
public int Min_api_version { get; set; } = 1;
public ViberSender Sender { get; set; }
public string Tracking_data { get; set; }
public string Type { get; set; } = "text";
public string Text { get; set; }
}
public class ViberSender
{
public string Name { get; set; }
public string Avatar { get; set; }
}
/// <summary>
/// Send a message. Member Account.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void bt_SendMessMemb_Click(object sender, EventArgs e)
{
string json = FillMember_2();
Encoding utf = Encoding.UTF8;
byte[] jsonUTF = utf.GetBytes(json);
string jsonUTFstr = utf.GetString(jsonUTF);
MessageWork messageWork = new MessageWork();
messageWork.ViberCall(jsonUTFstr);
}
public string FillMember_2()
{
string json = "";
var msg = new ViberMessage
{
Receiver = "Хu7LХХХ+wyD/ХХХХХХХХХ==", // text conditionally hidden
Min_api_version = 1,
Sender = new ViberSender
{
Name = "Лидия",
Avatar = ""
},
Tracking_data = "tracking data",
Type = "text",
Text = "Test message - 1"
};
json = JsonConvert.SerializeObject(msg);
return json;
}
class MessageWork
{
public void ViberCall(string json)
{
var request = (HttpWebRequest)WebRequest.Create("https://chatapi.viber.com/pa/send_message");
request.ContentType = "application/json";
request.Method = "POST";
request.Headers.Add("X-Viber-Auth-Token", "49c9a7b9a9e7d096-XXXXXXXXXXXX-XXXXXXXXX"); // text conditionally hidden
using (var streamWriter = new StreamWriter(request.GetRequestStream()))
{
streamWriter.Write(jsonN);
streamWriter.Flush();
}
string resultStr;
var response = (HttpWebResponse)request.GetResponse();
using (var streamReader = new StreamReader(response.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
resultStr = result.ToString();
}
jsonN = jsonN + "/r/n " + resultStr;
}
}
在“ jsonN = jsonN +” \ r \ n“ + resultStr;行中 “我明白了
{"Receiver":"Хu7LХХХ+wyD/ХХХХХХХХХ==", // text conditionally hidden
"Min_api_version":1,
"Sender":{"Name":"Лидия","Avatar":""},
"Tracking_data":"tracking data","Type":"text",
"Text":"Test message - 1"}
{"status":999,
"status_message":"Bad receiver ID",
"message_token":5324763260407665007,
"chat_hostname":"SN-CHAT-05_"}
问题。
1.为什么会出现错误“ status_message”:“错误的接收者ID”?
2.如何排除此错误?