在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#语言基础 → 微信网页版登陆示例源码(weixinHttpApi2.0)

微信网页版登陆示例源码(weixinHttpApi2.0)

C#语言基础

下载此实例
  • 开发语言:C#
  • 实例大小:0.55M
  • 下载次数:30
  • 浏览次数:1178
  • 发布时间:2018-10-20
  • 实例类别:C#语言基础
  • 发 布 人:www213123123
  • 文件格式:.zip
  • 所需积分:3
 相关标签: API http weixin

实例介绍

【实例简介】微信制作后台源码基于sdk 

【实例截图】

from clipboard

【核心代码】


using FluorineFx.Json;
using HttpSocket;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Xml;

namespace demo_win_httpsocket
{
    /// <summary>
    /// 全局信息
    /// </summary>    
    public partial class MainForm : Form
    {
        LxwHttpSocket WEB = new LxwHttpSocket();

        public MainForm()
        {
            InitializeComponent();

            var tt = MimeMapping.GetMimeMapping(".mp3");
            var tt2 = MimeMapping.GetExtByMime("application/x-cpio");
            //return;

            this.Load  = MainForm_Load;
        }
        private void MainForm_Load(object sender, EventArgs e)
        {
            WEB.Add("DEVICEID", generateDeviceId());
            WEB.Add("APPID", "wx782c26e4c19acffb");
            //第一步
            _1_JSLOGIN();

            //第二个 获取二维码
            _2_QRCODE();

            _3_LOGIN();
        }
        /// <summary>
        /// 打开主界面
        /// </summary>
        private void OpenMain()
        {
            foreach (Control c in this.Controls)
            {
                if (c.GetType() == typeof(PictureBox))
                    c.Visible = false;
                else
                    c.Visible = true;
            }

            _4_REDIRECT_URL();

            _5_WEBWXINIT();
            _6_WEBWXGETCONTACT();


            //第七步心跳检测
            _7_SYNCCHECK();
        }

        T Xml2Json<T>(string xml, string root = "error")
        {
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml);

            JavaScriptObject obj = new JavaScriptObject();
            foreach (XmlNode node in doc.SelectSingleNode(root).ChildNodes)
            {
                //获取内容
                obj[node.Name] = node.InnerText;
            }

            return JavaScriptConvert.DeserializeObject<T>(JavaScriptConvert.SerializeObject(obj));
        }

//        string upload_header = @"POST https://file.wx.qq.com/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json HTTP/1.1
//Host: file.wx.qq.com
//Connection: keep-alive
//Content-Length: 3386
//Origin: https://wx.qq.com
//User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36
//Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryuM55vqcAjmXSlVHa
//Accept: */*
//Referer: https://wx.qq.com/?&lang=zh_CN
//Accept-Encoding: gzip, deflate
//Accept-Language: zh-CN,zh;q=0.8";

//        string upload_body = @"------WebKitFormBoundaryuM55vqcAjmXSlVHa
//Content-Disposition: form-data; name=""id""
//
//WU_FILE_0
//------WebKitFormBoundaryuM55vqcAjmXSlVHa
//Content-Disposition: form-data; name=""name""
//
//{filename}
//------WebKitFormBoundaryuM55vqcAjmXSlVHa
//Content-Disposition: form-data; name=""type""
//
//{filetype}
//------WebKitFormBoundaryuM55vqcAjmXSlVHa
//Content-Disposition: form-data; name=""lastModifiedDate""
//
//Thu Jan 07 2016 20:33:28 GMT 0800 (中国标准时间)
//------WebKitFormBoundaryuM55vqcAjmXSlVHa
//Content-Disposition: form-data; name=""size""
//
//[CD]
//------WebKitFormBoundaryuM55vqcAjmXSlVHa
//Content-Disposition: form-data; name=""mediatype""
//
//doc
//------WebKitFormBoundaryuM55vqcAjmXSlVHa
//Content-Disposition: form-data; name=""uploadmediarequest""
//
//{""BaseRequest"":{""Uin"":{UIN},""Sid"":""{SID}"",""Skey"":""{SKEY}"",""DeviceID"":""{DeviceID}""},""ClientMediaId"":{time}363,""TotalLen"":[CD],""StartPos"":0,""DataLen"":[CD],""MediaType"":4}
//------WebKitFormBoundaryuM55vqcAjmXSlVHa
//Content-Disposition: form-data; name=""webwx_data_ticket""
//
//{webwx_data_ticket}
//------WebKitFormBoundaryuM55vqcAjmXSlVHa
//Content-Disposition: form-data; name=""pass_ticket""
//
//{pass_ticket}
//------WebKitFormBoundaryuM55vqcAjmXSlVHa
//Content-Disposition: form-data; name=""filename""; filename=""{filename}""
//Content-Type: {filetype}
//
//
//[FILE]
//------WebKitFormBoundaryuM55vqcAjmXSlVHa--
//";
        //private void button1_Click(object sender, EventArgs e)
        //{
        //    object user = lstBoxUser.SelectedItem;
        //    if (user == null)
        //    {
        //        MessageBox.Show("请选择用户!");
        //        return;
        //    }

        //    string userid = user.ToString().Substring(user.ToString().LastIndexOf('>')   1);



        //    var openFileDialog = new OpenFileDialog();
        //    if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        //    {
        //        _11_SENDFILE(userid, openFileDialog.FileName);
        //    }
        //}
        private void btnSendFile_Click(object sender, EventArgs e)
        {
            object user = lstBoxUser.SelectedItem;
            if (user == null)
            {
                MessageBox.Show("请选择用户!");
                return;
            }

            string userid = user.ToString().Substring(user.ToString().LastIndexOf('>')   1);



            var openFileDialog = new OpenFileDialog();
            if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                _11_SENDFILE(userid,openFileDialog.FileName);
            }
            
            //var openFileDialog = new OpenFileDialog();
            //if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            //{
            //    //_11_SENDFILE(userid, openFileDialog.FileName);

            //    lxwHttp lxw = new lxwHttp();
            //    //var response = lxw.SendHeader(ReplaceKey(upload), filePath);
            //    var response = lxw.SendHeader(ReplaceKey(upload_header), ReplaceKey(upload_body), openFileDialog.FileName);

            //    if (response != null)
            //    {
            //        var ret = Encoding.UTF8.GetString(response.Body.ToArray());
            //        MessageBox.Show(ret);
            //    }
            //}
            
        }

        string ReplaceKey(string s)
        {
            s = ReplaceHeaderKey(s);
            s = s.Replace("{uuid}", WEB[UUID]   "");

            return s;
        }
        int DateTimeToStamp(System.DateTime time)
        {
            System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
            return (int)(time - startTime).TotalSeconds;
        }
        string ReplaceHeaderKey(string s)
        {
            s = s.Replace("{webwx_data_ticket}", WEB["webwx_data_ticket"]);
            s = s.Replace("{UIN}", WEB[WXUIN]   "");
            s = s.Replace("{SID}", WEB[WXSID]   "");
            s = s.Replace("{DeviceID}", WEB[DEVICEID]   "");
            s = s.Replace("{SKEY}", WEB[SKEY]   "");
            s = s.Replace("{time}", DateTimeToStamp(DateTime.Now)   "");
            s = s.Replace("{pass_ticket}", WEB[PASS_TICKET]);
            s = s.Replace("{SyncKey}", WEB[SYNCKEY]   "");
            s = s.Replace("[number]", WEB[NUMBER]);

            return s;
        }

        private void btnSend_Click(object sender, EventArgs e)
        {
            object user = lstBoxUser.SelectedItem;
            if (user == null)
            {
                MessageBox.Show("请选择用户!");
                return;
            }

            if (txtBoxMessage.Text == "")
            {
                MessageBox.Show("请输入信息!");
                return;
            }

            string userid = user.ToString().Substring(user.ToString().LastIndexOf('>')   1);

            //发送消息
            _10_WEBWXSENDMSG(userid, UserName, txtBoxMessage.Text);

            txtBoxMessage.Text = "";
        }

        private void btnGetUserList_Click(object sender, EventArgs e)
        {
            //重新获取用户
            _6_WEBWXGETCONTACT();
        }

        private void MainForm_Load_1(object sender, EventArgs e)
        {

        }

      
    }

   
}


标签: API http weixin

实例下载地址

微信网页版登陆示例源码(weixinHttpApi2.0)

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

第 1 楼 无敌泉水吧 发表于: 2019-10-14 12:14 08
运行不起来~~

支持(0) 盖楼(回复)

发表评论

(您的评论需要经过审核才能显示)

查看所有1条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警