C# 使用C中的whatsappAPI将消息发送到另一个号码#
我想使用C#中的whatsApp API将我的号码发送给whatsApp上的另一个号码。为此,我在visual studio 2013中安装了WhatsApp for.NET 这是我正在使用的代码C# 使用C中的whatsappAPI将消息发送到另一个号码#,c#,nuget,whatsapp,C#,Nuget,Whatsapp,我想使用C#中的whatsApp API将我的号码发送给whatsApp上的另一个号码。为此,我在visual studio 2013中安装了WhatsApp for.NET 这是我正在使用的代码 string from = "919586896325"; string to = "919856745896"; string msg = "hello"; WhatsApp wa = new WhatsApp(from, "357168069647463", "abc", false, fals
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\12.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()
已连接到whatsapp
mscorlib.dll中发生类型为“System.FormatException”的第一次意外异常
“iisexpress.exe”(CLR v4.0.30319:/LM/W3SVC/3/ROOT-1-130858337690371973):已加载“C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\12.0.0.0_uuB03F5F7F11D50A3A\Microsoft.VisualStudio.Debugger.Runtime.dll”。
无法连接=System.FormatException:Base-64字符数组或字符串的长度无效。
在System.Convert.FromBase64_解码(Char*startInputPtr,Int32 inputLength,Byte*startDestPtr,Int32 destLength)
在System.Convert.FromBase64CharPtr处(Char*inputPtr,Int32 inputLength)
在System.Convert.FromBase64String处(字符串s)
在WhatsAppApi.WhatsAppBase.encryptPassword()上
在WhatsAppApi.WhatsSendBase.addAuthResponse()中
在WhatsAppApi.WhatsSendBase.Login(字节[]nextChallenge)
在c:\Users\vitana\Documents\Visual Studio 2013\Projects\MessageDiversity\MessageDiversity\services\MessageDiversity.c__中显示Class5.b_u 0():第48行
在WhatsAppApi.WhatsEventBase.fireonnectsuccess()上
在WhatsAppApi.WhatsAppBase.Connect()上
有人能告诉我如何解决这个问题吗
Base-64字符数组或字符串的长度无效
指示您应该在某处使用base-64编码字符串。从(第29行)判断,密码似乎是base64编码的。请确保遵循与中相同的模式。由于法律原因,.net版本所源自的php版本已停止。如果你在谷歌上搜索whatsapp api,就没有真正的whatsapp api。你需要将密码编码到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);
是的,我做到了,我现在得到了我的编码密码,上面写着“未授权”,我很高兴它成功了。所以我们解决了这个问题。未经授权是另一个问题。