• 判断是否关注公共号


    1,必须用服务号,开发--接口权限--网页服务--网页账号--绑定网站域名不要加http

    <div><a href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=&redirect_uri=http%3a%2f%2fgs.zqnb.com.cn%2fapi%2fwxxs%2fhome%2fGetTemp&response_type=
    code&scope=snsapi_userinfo&state=STATE#wechat_redirect ">点击</a></div>


    public bool GetTemp(string code, string state)
    {
    var openid = "";
    var access_token = "";
    //获取用户openid
    string get_access_token_url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=&secret=&code=" + code + "&grant_type=authorization_code";
    var client = new HttpClient();
    var result = client.GetAsync(get_access_token_url).Result;
    var jsTicket = result.Content.ReadAsStringAsync().Result;
    JObject jo = JObject.Parse(jsTicket);
    if (jo["openid"] != null)
    {
    openid = jo["openid"].ToString();

    }
    //获取公众号的access_token,此access_token不是用户授权后的access_token
    string get_token_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=&secret=";
    var result1 = client.GetAsync(get_token_url).Result;
    var jsTicket1 = result1.Content.ReadAsStringAsync().Result;
    JObject jo1 = JObject.Parse(jsTicket1);
    if (jo1["access_token"] != null)
    {
    access_token = jo1["access_token"].ToString();
    }
    string subscribe_msg = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + access_token + "&openid=" + openid + "&lang=zh_CN";
    var result2 = client.GetAsync(subscribe_msg).Result;
    var jsTicket2 = result2.Content.ReadAsStringAsync().Result;
    JObject jo2 = JObject.Parse(jsTicket2);
    string subscribe = "";
    if (jo2["subscribe"] != null)
    {
    subscribe = jo2["subscribe"].ToString();
    }
    if (subscribe == "0")
    {
    return false;
    }
    return true;
    }

  • 相关阅读:
    AMD64 Instruction-Level Debugging With dbx
    Solaris 10上安装Oracle 11g
    Dave-oracle
    SSD 下的 MySQL IO 优化
    vmware 网络工作方式
    PLSQL Developer 配置Oralce11g连接 转
    LINUX下的21个特殊符号 转
    linux 内核调试相关资料
    mysql 源代码编绎
    Windows Performance Toolkit
  • 原文地址:https://www.cnblogs.com/zhtbk/p/5580650.html
Copyright © 2020-2023  润新知