如何从特定联系人处获取消息? [英] How can I get a message from a specific contact?

查看:30
本文介绍了如何从特定联系人处获取消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从 Whats App 上的联系人检索消息(当然,在用户许可的情况下,我想到了 oAuth 之类的东西),但据我所知,哪些应用程序没有 API.所以我尝试在 WebBrowser 中加载网络版本并从那里获取消息,但我无法使其工作.

I'd like to retrieve a message from a contact on Whats App (with user's permission, of course, I thought something like oAuth) but as far I found, what apps doesn't have an API. So I tried load the web version in a WebBrowser and get the messag from there but I can't make it work.

它开始加载页面以请求扫描二维码,但它重定向到一个页面,说当前浏览器不受支持.所以我尝试在 IE 上使用仿真模式,将其设置为 IE11 并将 http 用户代理更改为正确的 IE11,但它也不起作用.我该如何解决这个问题?

It start loading the page to request the Qr code to be scanned but it redirects to a page saying the current browser isn't supported. So I tried to use emulation mode on IE, setting it to IE11 and changing http user agent to proper IE11's but it doesn't work either. How can I fix this?

这是我当前的代码:

 public partial class Form1 : Form
    {
        [DllImport("urlmon.dll", CharSet = CharSet.Ansi)]
        private static extern int UrlMkSetSessionOption(
           int dwOption, string pBuffer, int dwBufferLength, int dwReserved);

        const int URLMON_OPTION_USERAGENT = 0x10000001;
        const int URLMON_OPTION_USERAGENT_REFRESH = 0x10000002;
        const string usersAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393";

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            SetEmulation();
            ChangeUserAgent(usersAgent);
        }

        public static void ChangeUserAgent(string UserAgent)
        {
            UrlMkSetSessionOption(URLMON_OPTION_USERAGENT_REFRESH, null, 0, 0);
            UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, UserAgent, UserAgent.Length, 0);
        }

        public void SetEmulation()
        {
            const int BROWSER_EMULATION_IE11 = 0x2AF9;  
            var appName = Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName);
            Registry.SetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION",
                             appName, BROWSER_EMULATION_IE11, RegistryValueKind.DWord);
        }

        void UnsetEmulation()
        {
            using (RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true))
            {
                var appName = Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName);
                key.DeleteValue(appName);
            }
        }
}

我试着像这样打开:

webBrowser1.Navigate(@"http://web.whatsapp.com/");

非常受欢迎的 AA 完全不同的解决方案.

AA totally different solution to accomplish this is very welcome.

推荐答案

如果您浏览 https://web.whatsapp.com/ 使用 Internet Explorer,您将在主页中看到支持的浏览器,内容为:

If you browse https://web.whatsapp.com/ using Internet Explorer you will see supported browsers in the home page which says:

我们建议您通过以下浏览器之一使用 WhatsApp:

We recommend using WhatsApp with one of the following browsers:

  • 谷歌浏览器
  • Mozilla 火狐
  • Opera WhatsApp

还支持:

  • 微软边缘
  • Safari(仅限 MacOS 10.8+)

所以目前该站点似乎不支持 Internet Explorer.作为替代方案,您可以使用 Cefsharp浏览器.为此,请将合适的 CefSharp.WinForms nuget 包安装到 Visual Studio 中,然后将控件添加到您的表单并运行应用程序:

So it seems currently the site doesn't support Internet Explorer .As an alternative you can use Cefsharp browser. To do so, install a suitable CefSharp.WinForms nuget package into visual studio and then add the control to your form and run the application:

var browser = new CefSharp.WinForms.ChromiumWebBrowser("https://web.whatsapp.com/");
browser.Dock = DockStyle.Fill;
this.Controls.Add(browser);

运行程序后,它会显示一个二维码,如果您使用手机扫描,您将登录.

After you run the program, it shows a QR code which if you scan using your phone you will be logged in.

要扫描二维码,您应该在手机上安装 WhatsApp.然后打开应用程序→聊天→打开菜单→选择WhatApp Web然后扫描代码.

To scan the QR code, you should have WhatsApp installed on your mobile. Then open the application → CHATS → Open menu → Choose WhatApp Web then scan the code.

这篇关于如何从特定联系人处获取消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆