linjinzhuang

获取微信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是否存在于我们的数据库(用户表),以此来判断该用户是否已参加过活动,进而实现业务逻辑

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-06-09
  • 2021-07-20
  • 2022-01-18
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
  • 2021-12-05
猜你喜欢
  • 2021-09-27
  • 2022-01-29
  • 2022-12-23
  • 2021-11-20
  • 2022-02-08
  • 2022-12-23
相关资源
相似解决方案