This repository has been archived on 2024-07-11. You can view files and clone it, but cannot push or open issues or pull requests.
yoshop/source/application/common/library/wechat/WxUser.php

38 lines
1.0 KiB
PHP
Raw Normal View History

2020-04-25 22:20:29 +08:00
<?php
namespace app\common\library\wechat;
/**
* 微信小程序用户管理类
* Class WxUser
* @package app\common\library\wechat
*/
class WxUser extends WxBase
{
/**
* 获取session_key
* @param $code
* @return array|mixed
*/
public function sessionKey($code)
{
/**
* code 换取 session_key
* ​这是一个 HTTPS 接口,开发者服务器使用登录凭证 code 获取 session_key openid。
* 其中 session_key 是对用户数据进行加密签名的密钥。为了自身应用安全session_key 不应该在网络上传输。
*/
$url = 'https://api.weixin.qq.com/sns/jscode2session';
$result = json_decode(curl($url, [
'appid' => $this->appId,
'secret' => $this->appSecret,
'grant_type' => 'authorization_code',
'js_code' => $code
]), true);
if (isset($result['errcode'])) {
$this->error = $result['errmsg'];
return false;
}
return $result;
}
}