Home > Article > Backend Development > How does the mini program obtain openid and session_key?
Do you know openid and session_key? Today I will take you to learn how to use PHP to obtain the openid and session_key of the mini program. Friends in need can refer to it.
<?php //获取openid function getopenid(){//获取用户ID //code为前端通过 wx.login() 方式获取 $code = $_GET["code"]; //小程序微信官方后台 appid 值 $appid='wx68d7c348c17f010c'; //同样通过小程序后台获取的 APPSecret 值 $secret='2e7840670256a9337f4d910e935f3e4b'; $c= file_get_contents("https://api.weixin.qq.com/sns/jscode2session?appid=".$appid."&secret=".$secret."&js_code=".$code."&grant_type=authorization_code"); echo json_encode($c); } //返回内容 例 /* { session_key: "v5M+ikxl7Ms1Jya+MjqXIg==", openid: "o_SM351Q-ZIA5URgTISkPvx2cSWg" } */ ?>
Recommended learning: php video tutorial
The above is the detailed content of How does the mini program obtain openid and session_key?. For more information, please follow other related articles on the PHP Chinese website!