zoukankan      html  css  js  c++  java
  • 微信获取code

    //用户同意授权,获取code
        public static string Get_code(string RedirectUri)
        {

            string MyAppid = "";//微信应用Id
            string URL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + MyAppid + "&redirect_uri=" + RedirectUri + "&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
            return URL;
        }

    //获得Token
        public static volume_OAuth_Token Get_token(string Code)
        {
            string Appid = "";
            string appsecret = "";
            string Str = GetJson("https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + Appid + "&secret=" + appsecret + "&code=" + Code + "&grant_type=authorization_code");
            volume_OAuth_Token Oauth_Token_Model = Volume_JsonHelper.ParseFromJson<volume_OAuth_Token>(Str);
            return Oauth_Token_Model;
        }
        //下载数据
        public static string GetJson(string url)
        {
            string res = "";
            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
            req.Method = "GET";
            using (WebResponse wr = req.GetResponse())
            {
                HttpWebResponse myResponse = (HttpWebResponse)req.GetResponse();
                StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
                res = reader.ReadToEnd();
            }

            return res;
        }

  • 相关阅读:
    关于linux curl 地址参数的问题
    mac系统安装php redis扩展
    Shell获取上一个月、星期的时间范围
    python redis使用
    python pycurl模块
    Memcached常规应用与分布式部署方案
    mysql忘记密码重置(mac)
    shell命令从目录中循环匹配关键词
    python两个文件的对比
    MySQL优化方案
  • 原文地址:https://www.cnblogs.com/zhubenxi/p/5169219.html
Copyright © 2011-2022 走看看