Home > Backend Development > PHP Problem > How does the mini program obtain openid and session_key?

How does the mini program obtain openid and session_key?

醉折花枝作酒筹
Release: 2023-03-11 15:38:01
forward
2476 people have browsed it

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.

How does the mini program obtain openid and session_key?

<?php
//获取openid
function getopenid(){//获取用户ID
    //code为前端通过 wx.login() 方式获取
    $code = $_GET["code"];
    //小程序微信官方后台 appid 值
    $appid=&#39;wx68d7c348c17f010c&#39;;
    //同样通过小程序后台获取的 APPSecret 值
    $secret=&#39;2e7840670256a9337f4d910e935f3e4b&#39;;

    $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"
}
*/
?>
Copy after login

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!

Related labels:
php
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template