在 C# 中使用 whatsappAPI 将消息发送到另一个号码
send messages to another number using whatsappAPI in C#
我想在 C# 中使用 whatsApp API 从我的号码向 whatsApp 上的另一个号码发送消息。为此,我在 visual studio 2013 年为 .NET 安装了 WhatsAppi。
这是我正在使用的代码。
string from = "919586896325";
string to = "919856745896";
string msg = "hello";
WhatsApp wa = new WhatsApp(from, "357168069647463", "abc", false, false);
wa.OnConnectSuccess += () =>
{
System.Diagnostics.Debug.WriteLine("connected to whatsapp");
wa.OnLoginSuccess += (phoneNumber, data) =>
{
wa.SendMessage(to, msg);
System.Diagnostics.Debug.WriteLine("Message Sent");
};
wa.OnLoginFailed += (data) =>
{
System.Diagnostics.Debug.WriteLine(data);
};
wa.Login();
};
wa.OnConnectFailed += (ex) =>
{
System.Diagnostics.Debug.WriteLine("could not connect = {0}", ex);
};
wa.Connect();
当我 运行 输出以下代码时。
connected to whatsapp
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
'iisexpress.exe' (CLR v4.0.30319: /LM/W3SVC/3/ROOT-1-130858337690371973): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'.
could not connect = System.FormatException: Invalid length for a Base-64 char array or string.
at System.Convert.FromBase64_Decode(Char* startInputPtr, Int32 inputLength, Byte* startDestPtr, Int32 destLength)
at System.Convert.FromBase64CharPtr(Char* inputPtr, Int32 inputLength)
at System.Convert.FromBase64String(String s)
at WhatsAppApi.WhatsAppBase.encryptPassword()
at WhatsAppApi.WhatsSendBase.addAuthResponse()
at WhatsAppApi.WhatsSendBase.Login(Byte[] nextChallenge)
at MessageDiversification.services.MessageDivertService.<>c__DisplayClass5.<SendMessage>b__0() in c:\Users\vitana\Documents\Visual Studio 2013\Projects\MessageDiversification\MessageDiversification\services\MessageDivertService.asmx.cs:line 48
at WhatsAppApi.WhatsEventBase.fireOnConnectSuccess()
at WhatsAppApi.WhatsAppBase.Connect()
有人可以告诉我如何解决这个问题吗?
Invalid length for a Base-64 char array or string.
表示您应该在某处使用了 base-64 编码的字符串。从https://github.com/andregsilv/WhatsAppApi/blob/master/WhatsTest/Program.cs (line 29), the password seems to be base64-encoded. Be sure to follow the same pattern as e.g. in C# How to send messages with whatsapi.net?
来看
the.net 版本派生的 php 版本由于法律原因已停止。没有真正的 whatsapp api 如果你 google 它
您需要对密码进行Base64编码。
public static string Base64Encode(string text)
{
return System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(text));
}
然后打电话给
WhatsApp wa = new WhatsApp(from, Base64Encode("357168069647463"), "abc", false, false);
我想在 C# 中使用 whatsApp API 从我的号码向 whatsApp 上的另一个号码发送消息。为此,我在 visual studio 2013 年为 .NET 安装了 WhatsAppi。
这是我正在使用的代码。
string from = "919586896325";
string to = "919856745896";
string msg = "hello";
WhatsApp wa = new WhatsApp(from, "357168069647463", "abc", false, false);
wa.OnConnectSuccess += () =>
{
System.Diagnostics.Debug.WriteLine("connected to whatsapp");
wa.OnLoginSuccess += (phoneNumber, data) =>
{
wa.SendMessage(to, msg);
System.Diagnostics.Debug.WriteLine("Message Sent");
};
wa.OnLoginFailed += (data) =>
{
System.Diagnostics.Debug.WriteLine(data);
};
wa.Login();
};
wa.OnConnectFailed += (ex) =>
{
System.Diagnostics.Debug.WriteLine("could not connect = {0}", ex);
};
wa.Connect();
当我 运行 输出以下代码时。
connected to whatsapp
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
'iisexpress.exe' (CLR v4.0.30319: /LM/W3SVC/3/ROOT-1-130858337690371973): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'.
could not connect = System.FormatException: Invalid length for a Base-64 char array or string.
at System.Convert.FromBase64_Decode(Char* startInputPtr, Int32 inputLength, Byte* startDestPtr, Int32 destLength)
at System.Convert.FromBase64CharPtr(Char* inputPtr, Int32 inputLength)
at System.Convert.FromBase64String(String s)
at WhatsAppApi.WhatsAppBase.encryptPassword()
at WhatsAppApi.WhatsSendBase.addAuthResponse()
at WhatsAppApi.WhatsSendBase.Login(Byte[] nextChallenge)
at MessageDiversification.services.MessageDivertService.<>c__DisplayClass5.<SendMessage>b__0() in c:\Users\vitana\Documents\Visual Studio 2013\Projects\MessageDiversification\MessageDiversification\services\MessageDivertService.asmx.cs:line 48
at WhatsAppApi.WhatsEventBase.fireOnConnectSuccess()
at WhatsAppApi.WhatsAppBase.Connect()
有人可以告诉我如何解决这个问题吗?
Invalid length for a Base-64 char array or string.
表示您应该在某处使用了 base-64 编码的字符串。从https://github.com/andregsilv/WhatsAppApi/blob/master/WhatsTest/Program.cs (line 29), the password seems to be base64-encoded. Be sure to follow the same pattern as e.g. in C# How to send messages with whatsapi.net?
来看the.net 版本派生的 php 版本由于法律原因已停止。没有真正的 whatsapp api 如果你 google 它
您需要对密码进行Base64编码。
public static string Base64Encode(string text)
{
return System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(text));
}
然后打电话给
WhatsApp wa = new WhatsApp(from, Base64Encode("357168069647463"), "abc", false, false);