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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6
Visual web development tools

Dreamweaver Mac version
Visual web development tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Atom editor mac version download
The most popular open source editor
