new_naweigete/crmeb/services/easywechat/oauth2/wechat/WechatOauth2Provider.php
2025-03-12 10:47:34 +08:00

52 lines
2.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace crmeb\services\easywechat\oauth2\wechat;
use crmeb\services\SystemConfigService;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
use think\facade\Request;
/**
* 微信网页授权
* Class WechatOauthProvider
* @package crmeb\services\easywechat\oauth\wechat
* @method oauth(string $code = '') code授权获取acces_token openid
* @method getUserInfo($openId, $lang = 'zh_CN') openid 获取用户信息
* @method setRequest(Request $request) 设置request对象
*/
class WechatOauth2Provider implements ServiceProviderInterface
{
/**
*
* @param Container $pimple
*/
public function register(Container $pimple)
{
$request = app('request');
$wechat = SystemConfigService::more(['wechat_appid', 'wechat_app_appid', 'wechat_app_appsecret', 'wechat_appsecret']);
if ($request->isApp()) {
$appId = isset($wechat['wechat_app_appid']) ? trim($wechat['wechat_app_appid']) : '';
$appsecret = isset($wechat['wechat_app_appsecret']) ? trim($wechat['wechat_app_appsecret']) : '';
} else {
$appId = isset($wechat['wechat_appid']) ? trim($wechat['wechat_appid']) : '';
$appsecret = isset($wechat['wechat_appsecret']) ? trim($wechat['wechat_appsecret']) : '';
}
$pimple['oauth2'] = function ($pimple) use ($appId, $appsecret) {
return new WechatOauth($pimple['access_token'], $appId, $appsecret);
};
}
}