啥也不說--,直接上貨,喜歡的朋友可以點個贊;
public function text(){
$code= I('get.code');//用戶的登錄憑證code(使用wx.login({})可獲取到)這個是前端傳過來
$appid='小程序的appid';
$secret='密鑰就是secret';
$url="https://api.weixin.qq.com/sns/jscode2session?appid=$appid&secret=$secret&js_code=$code&grant_type=authorization_code";
$weixin=file_get_contents($url);
$jsondecode=json_decode($weixin);
$array=get_object_vars($jsondecode);
echo json_encode($array);
}