You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace app\base\controller\wechat\api;
use app\base\model\wechat\WechatUser;
use app\BaseController;
use think\App;
class Test extends BaseController
{
/**
* 微信公众号 通过openid获取TOKEN一般用于测试openid或access_token过期后重新获取
* @date 2020-11-13
*/
public function getTokenByOpenid()
{
$openid = input('post.openid');
$wechat_user_model = new WechatUser();
$jwt_class = new \jwt\Jwt();
$wechat_user = $wechat_user_model->getOneData([
'openid' => $openid
]);
$info = [
'uid' => UID,
'openid' => $openid,
'wechat_user_id' => $wechat_user['id'],
'user_id' => $wechat_user['user_id'],
];
$res_token = $jwt_class->signToken($info);
$r_data = $info;
$r_data['access_token'] = $res_token['token'];
$r_data['access_token_expire_time'] = $res_token['exp'];
return sendSuccessMessage($r_data);
}
}