Micro letter login authentication

1, step

 

 

 

 

 

2, to achieve

  Preparation: Open the test account page, search [authorized] to set security callback domain name or ip

  

 

 

 

 Step 1: url used to obtain the assembly code (access via Developer Tools)

HTTPS: // open.weixin.qq.com/connect/oauth2/authorize?appid= own redirect_uri = HTTP & APPID: // own URL /login.php&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect

Step 2: Create login.php access_token according to code and get openid

< ?php
#1.获取code
$code = $_GET['code'];

# 2. Get openid and accessiontoken 
$ apiData = Array (
 'AppID' => 'wx56e3e3d75414b3d0',
'secret'=>'f8ec8178c6dda48d1cb25c07304eff44',
'code'=> $code,
'grant_type'=>'authorization_code'
);
$api = "https://api.weixin.qq.com/sns/oauth2/access_token?".http_build_query($apiData);
$data = json_decode(file_get_contents($api), true);

// echo $data['access_token'];
// echo '<hr/>';
// echo $data['openid'];

# 步骤3:根据openid和access_token获取用户信息
$apiData = array(
'access_token'=> $data['access_token'],
'openid'=> $data['openid'],
'lang'=>'zh_CN'
);
$api = "https://api.weixin.qq.com/sns/userinfo?".http_build_query($apiData);
$data = json_decode(file_get_contents($api), true);

echo '<pre>';
print_r($data);

Guess you like

Origin www.cnblogs.com/CGWTQ/p/12180066.html