search
HomeBackend DevelopmentPHP ProblemHow 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.

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"
}
*/
?>

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!

Statement
This article is reproduced at:博客园. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Atom editor mac version download

Atom editor mac version download

The most popular open source editor