zoukankan      html  css  js  c++  java
  • 获取微信openID 的步骤

    获取微信openid的步骤:
    1、进入--》判断openID是否为空:
    空-->$url=urlencode("http://xxx/xxx.php");//回调链接
    $redirect="https://open.weixin.qq.com/connect/oauth2/authorize?appid=".APPID.
    "&redirect_uri={$url}&response_type=code&scope=snsapi_base&state=survey";
    echo "<script> location='".$redirect."';</script>";
    以上过程会自动跳转至回调链接,同时带上两个参数:
    http://xxx/xxx.php?code=0110c18ef6825s9asbbs6123a84d42fK&state=survey

    跳转后:用获取到的code再换取openID

    if($_GET['state']=='survey'){
    $code=$_GET['code'];
    $uinfo=file_get_contents("https://api.weixin.qq.com/sns/oauth2/access_token?appid=".APPID."&secret=".SECRET."&code={$code}&grant_type=authorization_code");
    $uinfo=(array)json_decode($uinfo);
    $openid=$uinfo['openid'];
    $_SESSION['openid']=$openid;

    }

    此时判断openID是否为空:
    不为空-->首先判断该openID是否存在于我们的数据库(用户表),以此来判断该用户是否已参加过活动,进而实现业务逻辑

  • 相关阅读:
    超链接与图像
    24
    2018-02-24
    2018-02-23
    2018-02-05(jQuery)
    2018-01-29(jQuery)
    2018-01-29(Bootstrap)
    2018-01-29(HTML+CSS)
    451. 根据字符出现频率排序
    550.键盘行
  • 原文地址:https://www.cnblogs.com/linjinzhuang/p/4691669.html
Copyright © 2011-2022 走看看