Esempio n. 1
0
 /// <summary>
 /// 发消息 -文字
 /// </summary>
 /// <param name="wxid"></param>
 /// <param name="content"></param>
 public unsafe void Sendmsg(string wxid, string content)
 {
     MsgDelegate.Show(string.Format("发送文字 {0}", content));
     content = content.Replace(" ", "\r\n");
     fixed(int *WxUser = &wxUser, Msgptr = &msgptr)
     {
         IpadDll.WXSendMsg(wxUser, wxid, content, null, (int)Msgptr);
         //var datas = MarshalNativeToManaged((IntPtr)msgptr);
         //var str = datas.ToString();
         WXReleaseEX(ref msgptr);
     }
 }
Esempio n. 2
0
        unsafe void Init()
        {
            this._userStatus = WechatUserStatus.Initing;
            fixed(int *WxUser = &wxUser, PushStr = &pushStr)
            {
                string uuid = IpadDll.FakeUuId();
                var    mac  = IpadDll.FakeMac();

                //var ret = IpadDll.WXSetNetworkVerifyInfo("116.62.17.77", 9000);//ipadtest
                var ret = IpadDll.WXSetNetworkVerifyInfo(this.dllIP, this.dllPort);

                if (ret != 1)
                {
                    MsgDelegate.Show("授权失败:" + ret);
                    return;
                }
                var key = string.Format(@"<softtype><k3>9.0.2</k3><k9>iPad</k9><k10>2</k10><k19>58BF17B5-2D8E-4BFB-A97E-38F1226F13F8</k19><k20>{0}</k20><k21>neihe_5GHz</k21><k22>(null)</k22><k24>{1}</k24><k33>\345\276\256\344\277\241</k33><k47>1</k47><k50>1</k50><k51>com.tencent.xin</k51><k54>iPad4,4</k54></softtype>", uuid, mac);

                IpadDll.WXInitialize((int)WxUser, "鎴戠殑IPAD", key, uuid);
                IpadDll.WXSetRecvMsgCallBack(wxUser, outputDelegate);

                IpadDll.WXGetQRCode(wxUser, (int)PushStr);

                var         msg    = Marshal.PtrToStringAnsi(new IntPtr(Convert.ToInt32(pushStr)));
                WxQrCodeDto qrcode = Newtonsoft.Json.JsonConvert.DeserializeObject <WxQrCodeDto>(msg);//反序列化

                //var img = Base64StringToImage(qrcode.QrCode);
                MsgDelegate.QrLogin(qrcode.QrCode);

                WXReleaseEX(ref pushStr);
                WxQrResultDto qrCoderesult = null;

                while (true)
                {
                    if (!(this._userStatus == WechatUserStatus.Initing || this._userStatus == WechatUserStatus.Scaning))
                    {
                        break;
                    }
                    this._userStatus = WechatUserStatus.Scaning;
                    IpadDll.WXCheckQRCode(wxUser, (int)PushStr);
                    var datas = MarshalNativeToManaged((IntPtr)pushStr);
                    if (datas == null)
                    {
                        continue;
                    }
                    string sstr = datas.ToString();
                    qrCoderesult = Newtonsoft.Json.JsonConvert.DeserializeObject <WxQrResultDto>(sstr);
                    WXReleaseEX(ref pushStr);
                    bool breakok = false;
                    switch (qrCoderesult.Status)
                    {
                    case 0: MsgDelegate.Show("请扫描二维码"); break;

                    case 1: MsgDelegate.Show("请点在手机上点确认"); break;

                    case 2: MsgDelegate.Show("正在登录中.."); breakok = true; break;

                    case 3: MsgDelegate.Show("已过期"); break;

                    case 4: MsgDelegate.Show("取消操作了"); breakok = true; break;
                    }
                    if (breakok)
                    {
                        break;
                    }
                }

                if (qrCoderesult.Status == 2)
                {
                    var username = qrCoderesult.UserName;
                    this.user.wxid = qrCoderesult.UserName;
                    this.user.name = qrCoderesult.NickName;
                    var pass = qrCoderesult.Password;
                    IpadDll.WXQRCodeLogin(wxUser, username, pass, (int)PushStr);
                    var    datas = MarshalNativeToManaged((IntPtr)pushStr);
                    string sstr  = datas.ToString();
                    WXReleaseEX(ref pushStr);
                    WxUserDataDto userdata = Newtonsoft.Json.JsonConvert.DeserializeObject <WxUserDataDto>(sstr);//反序列化
                    if (userdata.Status == -301)
                    {
                        Thread.Sleep(1000);
                        IpadDll.WXQRCodeLogin(wxUser, username, pass, (int)PushStr);
                        datas = MarshalNativeToManaged((IntPtr)pushStr);
                        sstr  = datas.ToString();
                        WXReleaseEX(ref pushStr);
                        MsgDelegate.Show("微信重定向");
                        userdata = Newtonsoft.Json.JsonConvert.DeserializeObject <WxUserDataDto>(sstr);//反序列化

                        if (userdata.Status == 0)
                        {
                            this._userStatus = WechatUserStatus.Logined;
                            MsgDelegate.Show("登录成功");
                            IpadDll.WXHeartBeat(wxUser, (int)PushStr);
                            datas = MarshalNativeToManaged((IntPtr)pushStr);
                            sstr  = datas.ToString();
                            WXReleaseEX(ref pushStr);

                            MsgDelegate.UserLogin(userdata);
                            Task.Run(new Action(this.SyncList));
                            return;
                        }
                        else
                        {
                            this._userStatus = WechatUserStatus.Failed;
                            MsgDelegate.UserLogin(null);
                            MsgDelegate.Show("登录失败");
                        }
                    }

                    if (userdata.Status == 0)
                    {
                        this._userStatus = WechatUserStatus.Logined;
                        MsgDelegate.Show("登录成功");
                        IpadDll.WXHeartBeat(wxUser, (int)PushStr);
                        datas = MarshalNativeToManaged((IntPtr)pushStr);
                        sstr  = datas.ToString();
                        WXReleaseEX(ref pushStr);

                        MsgDelegate.UserLogin(userdata);
                        Task.Run(new Action(this.SyncList));
                        return;
                    }
                    else
                    {
                        this._userStatus = WechatUserStatus.Failed;
                        MsgDelegate.UserLogin(null);
                        MsgDelegate.Show("登录失败");
                    }
                }
                else
                {
                    this._userStatus = WechatUserStatus.Failed;
                    MsgDelegate.UserLogin(null);
                    MsgDelegate.Show("登录失败");
                }
            }
        }
Esempio n. 3
0
 private void WXReleaseEX(ref int hande)
 {
     IpadDll.WXRelease(hande);
     hande = 0;
 }