不管用户是否已经关注,授权获取用户的基本信息
发布日期:2021-05-13 20:53:28 浏览次数:20 分类:精选文章

本文共 5490 字,大约阅读时间需要 18 分钟。

���������������������������������������������

  • ������������������������������������������������������
  • ������������������������������������������������������������������������������������������������

  • ������������������������������������������������������������������
  • ���������������������������������������������������������������"������"���������������"������������������"���"������������"������������������������������������������������������������������

    a. ���������������.Drawable������������

    ���������������������������������������������������������������������������������������������������������������������wx.xxx.com���������_DRAWABLE���������������������������������������������������������������������������������������������������������������������

    b. ������������code���������

    ������������������������������������������������������code���������������������������������������������������redirect_uri���������������������������������������������������������������������������������������������������������������������������������������������������������

    c. ������������������������������

    ���������������������������������������������������������������������������������������������������������������������������ID���������������������

    1. ������������������code���������������
    2. ������������������������������������������������code������������������������������������������������������������URL������������������������������������������

      a. ������wxid������

      ������URL���������������������������������������������wxid���������������������������������������������������������

      b. ������state������

      ������������CSRF������������������state������������������������������������������������������

      c. ������������������

      ���������������wxid���state������������������������������������������������URL���������������������������������������������������������

      URL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URL&response_type=code&scope=SCOPE&state=STATE"

      ���������APPID���������ID���REDIRECT_URL���������������������������������SCORE������������������������snsapi_userinfo���������������������URL������������������������������

      1. ���������������������������������������
      2. ���������������������������������������code������������������REDIRECT_URL������������������������������������������code������������API������access_token���openid���

        a. ���������������code������

        ������������������������code���state���������������������������������������������������CSRF���������������

        b. ������������access_token���������

        ���������������������API���������code���app_id���app_secret������������������������������������������������OPENID���

        c. ������������������������

        ������������������������������������������������������������������������������������������������������������������������������������������������

        1. PHP������������������
        2. ������������������������������������������PHP���������

          function wxauthorize() { global $.getConfig;

          // ������code���state������
          $code = isset($_GET['code']) ? $_GET['code'] : '';
          $state = isset($_GET['state']) ? $_GET['state'] : '';
          $validate_State = $getConfig('auth_validate_state');
          if ($validate_State && !$validate_State->isStateValid($state)) {
          echo "���������������";
          exit();
          }
          // ������������������������
          $data = M('userbindingwxconfig')->where('id='.$getConfig['wx_id'])->select();
          if (empty($data)) {
          echo "���������������������";
          exit();
          }
          $appid = $data[0]['appId'];
          $appsecret = $data[0]['appSecret'];
          // ������access_token���openid
          $token_url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$appid."&secret=".$appsecret."&code=".$code."&grant_type=authorization_code";
          $token_data = file_get_contents($token_url);
          if ($token_data === false) {
          echo "������token������";
          exit();
          }
          $token_obj = (array) json_decode($token_data, true);
          $access_token = $token_obj['access_token'] ?? '';
          $openid = $token_obj['openid'] ?? '';
          if (empty($access_token) || empty($openid)) {
          echo "���������������������";
          exit();
          }
          // ������������������������
          $userinfo_url = "https://api.weixin.qq.com/sns/userinfo?access_token=".$access_token."&openid=".$openid."&lang=zh_CN";
          $userinfo = file_get_contents($userinfo_url);
          if ($userinfo === false) {
          echo "������������������������";
          exit();
          }
          $user_data = (array) json_decode($userinfo, true);
          return $user_data;

          }

          ������������������������������������������������������������������������������������

          1. ���������������������������
          2. ���������������������������������������������������������������������������

            a. IISRewriteRule������

            ���������������������URL���������������������������IIS������������������������Web���������������������������������������������

            b. ���������������������

            ���������APPID���APPSECRET��������� secretion leak���������������state���������������������������CSRF���������

            c. ������������������

            ������������������������������������������������������������������������������������������������������������URL������������

            d. ������������������

            ��� Fehler������������������������������������error handling���������������������������������������������������������������������

            ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

    上一篇:LeetCode 872 叶子相似的树[DFS 二叉树] HERODING的LeetCode之路
    下一篇:关注回复和自定义回复(tp3.2)

    发表评论

    最新留言

    关注你微信了!
    [***.104.42.241]2025年05月03日 07时05分32秒