# Log in
# wechat service number
Wechat service number to get user information is very simple
- Introduce namespace sunphp\account\SunAccount
- Use the built-in login() method
use sunphp\account\SunAccount;
/* 前端默认入口示例 */
class Wx {
/* 微信公众号登录 */
public function login(){
$account=SunAccount::create();
$userinfo=$account->login();
dump($userinfo);
}
}
# wechat mini program
# Get openid
- The small program front end calls the wx.login() method to get the code
- Introduce namespace use sunphp\account\SunAccount
- The back-end obtains openid and session_key through the session() method
use sunphp\account\SunAccount;
/* 微信小程序常见接口示例 */
class WxXcx {
/* 获取用户的openid */
public function getOpenid(){
$code="小程序前端获取的code";
$account=SunAccount::create();
$data=$account->session($code);
//获取到的数据格式如下
// $data=[
// 'openid'=>"获取到的用户openid",
// 'session_key'=>"获取到的session值",
// ];
}
# Decrypt data
- The small program front-end obtains iv, encryptedData and other data
- Introduce namespace use sunphp\account\SunAccount
- The back end decrypts data through the decryptData() method
use sunphp\account\SunAccount;
/* 微信小程序常见接口示例 */
class WxXcx {
/* 解密用户信息 */
public function getUserinfo(){
$session_key="之前获取的session_key";
$iv="iv数据";
$encryptedData="encryptedData数据";
$account=SunAccount::create();
$data=$account->decryptData($session_key, $iv, $encryptedData);
}