yyhhblog

/**
* 获取code
* @return code code作为换取access_token的票据,每次用户授权带上的code将不一样,code只能使用一次,5分钟未被使用自动过期
*/
public function actionIndex(){
$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$this->appid."&secret=".$this->secret."&code=".$_GET[\'code\']."&grant_type=authorization_code";
$token = file_get_contents($url);
$token = json_decode($token,true);
$token["access_token"];
$user_url = "https://api.weixin.qq.com/sns/userinfo?access_token=".$token[\'access_token\']."&openid=".$token["openid"]."&lang=zh_CN";
$userinfo = file_get_contents($user_url);
$arr = json_decode($userinfo,true);
$openid = $arr[\'openid\'];

$unionid = $arr[\'unionid\'];/*该字段必须在微信开发平台(https://open.weixin.qq.com/)进行关联*/

}

分类:

技术点:

相关文章:

  • 2021-11-27
  • 2022-01-14
  • 2022-12-23
  • 2021-12-12
  • 2022-12-23
  • 2022-01-23
  • 2021-04-14
猜你喜欢
  • 2022-02-09
  • 2021-12-04
  • 2021-11-27
  • 2021-12-03
  • 2021-07-15
  • 2022-01-09
  • 2022-02-07
相关资源
相似解决方案