Browse Source

fix:评论

super-yimizi 6 days ago
parent
commit
b1125d0cfa

+ 2 - 2
application/admin/view/shop/goods/add_sku.html

@@ -984,7 +984,7 @@
     
     <!-- 单规格表单 - 使用Favisible动态显示 -->
     <div id="single-spec-form" data-favisible="spec_type=0">
-        <div class="form-group">
+        <!-- <div class="form-group">
             <label class="control-label col-xs-12 col-sm-2">商品图片:</label>
             <div class="col-xs-12 col-sm-10">
                 <div class="input-group">
@@ -996,7 +996,7 @@
                 </div>
                 <ul class="row list-inline faupload-preview" id="p-single-image"></ul>
             </div>
-        </div>
+        </div> -->
         <div class="form-group">
             <label class="control-label col-xs-12 col-sm-2">销售价:</label>
             <div class="col-xs-12 col-sm-10">

+ 26 - 0
application/api/controller/third/Apple.php

@@ -0,0 +1,26 @@
+<?php
+
+namespace addons\shopro\controller\third;
+
+use addons\shopro\controller\Common;
+use addons\shopro\service\third\apple\Apple as AppleService;
+
+class Apple extends Common
+{
+    protected $noNeedLogin = ['login'];
+
+    // 苹果登陆(仅对接App登录)
+    public function login()
+    {
+        $payload = $this->request->post('payload/a');
+
+        $apple = new AppleService();
+        $result = $apple->login($payload);
+
+        if ($result) {
+            $this->success('登陆成功');
+        }
+
+        $this->error('登陆失败');
+    }
+}

+ 195 - 0
application/api/controller/third/Wechat.php

@@ -0,0 +1,195 @@
+<?php
+
+namespace app\api\controller\third;
+
+use think\Db;
+use think\exception\HttpResponseException;
+use app\api\controller\Base;
+use app\common\Service\Third\Wechat\Wechat as WechatService;
+
+class Wechat extends Base
+{
+    protected $noNeedLogin = ['login', 'getSessionId', 'oauthLogin', 'jssdk', 'wxacode', 'subscribeTemplate'];
+    protected $noNeedRight = ['*'];
+    protected $payload = [];
+    protected $wechat;
+    protected $platform;
+
+    public function _initialize()
+    {
+        parent::_initialize();
+
+        $this->platform = $this->request->param('platform', '');
+
+        if ($this->platform === '') {
+            $this->error('参数错误');
+        }
+
+        $payloadString = htmlspecialchars_decode($this->request->param('payload', ''));
+
+        $this->payload = json_decode(urldecode($payloadString), true) ?? [];
+
+        $this->wechat = new WechatService($this->platform, $this->payload);
+    }
+
+    // 微信登陆(小程序+公众号+开放平台)
+    public function login()
+    {
+        $result = Db::transaction(function () {
+            return $this->wechat->login();
+        });
+
+        if ($result) {
+            $this->success('登陆成功');
+        }
+        $this->error('登陆失败');
+    }
+
+    // 获取小程序sessionId+自动登录
+    public function getSessionId()
+    {
+        $result = $this->wechat->getSessionId();
+        $this->success('', $result);
+    }
+
+    // 获取网页授权地址
+    public function oauthLogin()
+    {
+        $result = $this->wechat->oauthLogin();
+        if (isset($result['login_url'])) {
+            $this->success('', $result);
+        }
+
+        if (isset($result['redirect_url'])) {
+            return redirect($result['redirect_url']);
+        }
+    }
+
+    // 绑定用户手机号
+    public function bindUserPhoneNumber()
+    {
+        $result = Db::transaction(function () {
+            $user = auth_user();
+            $mobile = $this->wechat->getUserPhoneNumber();
+
+            $this->svalidate(['mobile' => $mobile], '.bindWechatMiniProgramMobile');
+
+            $user->mobile = $mobile;
+            $verification = $user->verification;
+            $verification->mobile = 1;
+            $user->verification = $verification;
+
+            return $user->save();
+        });
+        if ($result) {
+
+            $this->success('绑定成功');
+        }
+        $this->error('操作失败');
+    }
+
+    // 绑定微信账号
+    public function bind()
+    {
+        $result = Db::transaction(function () {
+            $user = auth_user();
+            return $this->wechat->bind($user);
+        });
+
+        if ($result) {
+            $this->success('绑定成功');
+        }
+        $this->error('绑定失败');
+    }
+
+    // 解绑微信账号
+    public function unbind()
+    {
+        $result = Db::transaction(function () {
+            return $this->wechat->unbind();
+        });
+
+        if ($result) {
+            $this->success('解绑成功');
+        }
+        $this->error('解绑失败');
+    }
+
+    // 微信网页jssdk
+    public function jssdk()
+    {
+        $apis = [
+            'checkJsApi',
+            'updateTimelineShareData',
+            'updateAppMessageShareData',
+            'getLocation', //获取位置
+            'openLocation', //打开位置
+            'scanQRCode', //扫一扫接口
+            'chooseWXPay', //微信支付
+            'chooseImage', //拍照或从手机相册中选图接口
+            'previewImage', //预览图片接口       'uploadImage', //上传图片
+            'openAddress',   // 获取微信地址
+            'requestMerchantTransfer', // 微信商家转账
+        ];
+        // $openTagList = [
+        //     'wx-open-subscribe'
+        // ];
+        try {
+            $data = $this->wechat->jssdk($apis);
+        } catch (HttpResponseException $e) {
+            $data = $e->getResponse()->getData();
+            $message = $data ? ($data['msg'] ?? '') : $e->getMessage();
+            $this->error($message);
+        } catch (\Exception $e) {
+            $this->error($e->getMessage());
+        }
+
+        $this->success('jssdkApi', $data);
+    }
+
+
+    /**
+     * 微信小程序码接口
+     */
+    public function wxacode()
+    {
+        $mp = $this->wechat->getApp();
+        $path = $this->payload['path'];
+        list($page, $scene) = explode('?', $path);
+
+        $content = $mp->app_code->getUnlimit($scene, [
+            'page' => substr($page, 1),
+            'is_hyaline' => true,
+            // 'env_version' => 'develop'
+            'env_version' => 'release'
+        ]);
+
+        if ($content instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
+            return response($content->getBody(), 200, ['Content-Length' => strlen($content->getBodyContents())])->contentType('image/png');
+        } else {
+            // 小程序码获取失败
+            $msg = $content['errcode'] ?? '-';
+            $msg .= $content['errmsg'] ?? '';
+
+            $this->error($msg);
+        }
+    }
+
+    /**
+     * 微信小程序订阅模板消息
+     */
+    public function subscribeTemplate()
+    {
+        $templates = [];
+        // 获取订阅消息模板
+        $notificationConfig = NotificationConfig::where('channel', 'WechatMiniProgram')->enable()->select();
+
+        foreach ($notificationConfig as $k => $config) {
+            if ($config['content'] && isset($config['content']['template_id']) && $config['content']['template_id']) {
+                $templates[$config['event']] = $config['content']['template_id'];
+            }
+        }
+
+        $this->success('获取成功', $templates);
+    }
+}

+ 18 - 0
application/common.php

@@ -5,6 +5,7 @@
 use think\exception\HttpResponseException;
 use think\Response;
 use app\common\Service\ShopConfigService;
+use app\common\exception\BusinessException;
 
 if (!function_exists('shop_config')) {
     /**
@@ -18,6 +19,23 @@ if (!function_exists('shop_config')) {
     }
 }
 
+/**
+ * 获取前端用户
+ */
+if (!function_exists('auth_user')) {
+    function auth_user($throwException = false)
+    {
+        if (\app\common\library\Auth::instance()->isLogin()) {
+            return \app\common\library\Auth::instance()->getUser();
+        }
+        if ($throwException) {
+            throw new BusinessException('请登录后操作');
+        }
+        return null;
+    }
+}
+
+
 if (!function_exists('format_log_error')) {
     /**
      * 格式化记录日志,重要地方使用

+ 109 - 0
application/common/Service/Third/Apple/Apple.php

@@ -0,0 +1,109 @@
+<?php
+
+namespace app\common\Service\Third\Apple;
+
+use app\common\library\Auth;
+use app\common\service\user\UserAuth;
+use app\common\model\ThirdOauth;
+
+class Apple
+{
+
+    public function __construct()
+    {
+    }
+    /**
+     * AppleId登陆
+     *
+     * @return array
+     */
+    public function login($payload)
+    {
+        $identityToken = $payload['identityToken'];
+        $openId = $payload['openId'];
+        $appleSignInPayload = \AppleSignIn\ASDecoder::getAppleSignInPayload($identityToken);
+        $isValid = $appleSignInPayload->verifyUser($openId);
+        if (!$isValid) return false;
+
+        $nickname = '';
+        if (!empty($payload['fullName'])) {
+            $hasFamilyName = !empty($payload['fullName']['familyName']);
+            $nickname = ($hasFamilyName ? $payload['fullName']['familyName'] : '') . ($hasFamilyName ? ' ' : '') . $payload['fullName']['giveName'];
+        }
+        $appleUser = [
+            'openid' => $openId,
+            'nickname' => $nickname,
+            'avatar' => ''
+
+        ];
+
+
+        $oauthInfo = $this->createOrUpdateOauthInfo($appleUser);
+
+        if (!$oauthInfo->user_id) {
+            $this->registerOrBindUser($oauthInfo);
+        }
+
+        $auth = Auth::instance();
+        $ret = $auth->direct($oauthInfo->user_id);
+
+        if ($ret) {
+            $oauthInfo->login_num += 1;
+            set_token_in_header($auth->getToken());
+            return true;
+        } else {
+            $oauthInfo->user_id = 0;
+            $oauthInfo->save();
+            return false;
+        }
+    }
+
+    /**
+     * 创建/更新用户认证信息
+     *
+     * @return think\Model
+     */
+    private function createOrUpdateOauthInfo($appleUser)
+    {
+        $oauthInfo = ThirdOauth::where([
+            'openid' => $appleUser['openid'],
+            'provider' => 'apple',
+            'platform' => 'App'
+        ])->find();
+        if (!$oauthInfo) {   // 创建新的third_oauth条目
+            $appleUser['provider'] = 'apple';
+            $appleUser['platform'] = 'App';
+            ThirdOauth::create($appleUser);
+            $oauthInfo = ThirdOauth::where([
+                'openid' => $appleUser['openid'],
+                'provider' => 'apple',
+                'platform' => 'App'
+            ])->find();
+        }
+        if ($oauthInfo) {  // 更新授权信息
+            $oauthInfo->save($appleUser);
+        }
+        return $oauthInfo;
+    }
+
+    /**
+     * 注册/绑定用户
+     *
+     * @return think\Model
+     */
+    private function registerOrBindUser($oauthInfo, $user_id = 0)
+    {
+        if ($oauthInfo->user_id) {
+            error_stop('该账号已绑定其他用户');
+        }
+        if ($user_id === 0) {   // 注册新用户
+            $user = (new UserAuth())->register([
+                'nickname' => $oauthInfo->nickname,
+                'avatar' => $oauthInfo->avatar,
+            ]);
+            $user_id = $user->id;
+        }
+        $oauthInfo->user_id = $user_id;
+        return $oauthInfo->save();
+    }
+}

+ 132 - 0
application/common/Service/Third/Wechat/MiniProgram.php

@@ -0,0 +1,132 @@
+<?php
+
+namespace app\common\Service\Third\Wechat;
+
+use app\common\facade\Wechat;
+use fast\Random;
+use app\common\library\Auth;
+use app\common\model\ThirdOauth;
+use app\common\exception\BusinessException;
+
+class MiniProgram
+{
+    public $wechat;
+    protected $request;
+    protected $payload;
+
+    public function __construct($payload = [])
+    {
+        $this->payload = $payload;
+        $this->wechat = Wechat::miniProgram();
+    }
+
+    // 小程序登录
+    public function login()
+    {
+        // https://developers.weixin.qq.com/community/develop/doc/00022c683e8a80b29bed2142b56c01
+        if (empty($this->payload['sessionId'])) {
+            throw new BusinessException('未获取到登陆态, 请重试');
+        }
+
+        $sessionData = cache($this->payload['sessionId']);
+
+        if (empty($sessionData)) {
+            throw new BusinessException('登陆态已过期, 请重试');
+        }
+
+        $wechatUser = [
+            'openid' => $sessionData['openid'],
+            'unionid' => $sessionData['unionid'] ?? '',
+            'mobile' => '',
+            'avatar' => '',
+            'nickname' => '',
+        ];
+        return $wechatUser;
+    }
+
+    public function bind()
+    {
+        if (empty($this->payload['sessionId'])) {
+            throw new BusinessException('未获取到登陆态, 请重试');
+        }
+
+        $sessionData = cache($this->payload['sessionId']);
+
+        if (empty($sessionData)) {
+            throw new BusinessException('登陆态已过期, 请重试');
+        }
+
+        $wechatUser = [
+            'openid' => $sessionData['openid'],
+            'unionid' => $sessionData['unionid'] ?? '',
+            'avatar' => '',
+            'nickname' => '',
+        ];
+        return $wechatUser;
+    }
+
+    // 解密微信小程序手机号
+    public function getUserPhoneNumber()
+    {
+        if (empty($this->payload['sessionId'])) {
+            throw new BusinessException('未获取到登陆态, 请重试');
+        }
+
+        $sessionData = cache($this->payload['sessionId']);
+
+        if (empty($sessionData)) {
+            throw new BusinessException('登陆态已过期, 请重试');
+        }
+
+        $phoneInfo = $this->wechat->encryptor->decryptData($sessionData['session_key'], $this->payload['iv'], $this->payload['encryptedData']);
+
+        if (empty($phoneInfo['purePhoneNumber'])) {
+            throw new BusinessException('获取失败,请重试');
+        }
+
+        if ($phoneInfo['countryCode'] !== '86') {
+            throw new BusinessException('仅支持大陆地区手机号');
+        }
+        return $phoneInfo['purePhoneNumber'];
+    }
+
+    /**
+     * 获取session_id, 缓存 session_key, openid (unionid), 自动登录
+     *
+     * @return string
+     */
+    public function getSessionId()
+    {
+        if (empty($this->payload['code'])) {
+            throw new BusinessException('缺少code参数');
+        }
+        
+        $decryptData = $this->wechat->auth->session($this->payload['code']);
+
+        if(!empty($decryptData['errmsg'])) {
+            throw new BusinessException($decryptData['errmsg']);
+        }
+
+        if (empty($decryptData['session_key'])) {
+            throw new BusinessException('未获取到登陆态, 请重试');
+        }
+        
+        $auto_login = $this->payload['auto_login'] ?? false;
+
+        // 自动登录流程
+        if($auto_login) {
+            $oauthInfo = ThirdOauth::getByOpenid($decryptData['openid']);
+            if($oauthInfo && $oauthInfo->user_id) {
+                $auth = Auth::instance();
+                $ret = $auth->direct($oauthInfo->user_id);
+                if ($ret) {
+                    //set_token_in_header($auth->getToken());
+                }
+            }
+        }
+     
+        $session_id = Random::uuid();
+        cache($session_id, $decryptData, 60 * 60 * 24 * 7);   // session_key缓存保留一周
+        return ['session_id' => $session_id, 'auto_login' => $auto_login];
+    }
+}

+ 77 - 0
application/common/Service/Third/Wechat/OfficialAccount.php

@@ -0,0 +1,77 @@
+<?php
+
+namespace app\common\Service\Third\Wechat;
+
+use app\common\facade\Wechat;
+use app\common\exception\BusinessException;
+class OfficialAccount
+{
+    public $wechat;
+    protected $request;
+    protected $payload;
+
+    public function __construct($payload)
+    {
+        $this->payload = $payload;
+        $this->request = request();
+        $this->wechat = Wechat::officialAccount();
+    }
+
+    public function login()
+    {
+        $code = $this->request->get('code');
+        if (empty($code)) {
+            throw new BusinessException('缺少code参数');
+        }
+        $decryptData = $this->wechat->oauth->user()->getOriginal();
+        
+        $wechatUser = [
+            'openid' => $decryptData['openid'],
+            'unionid' => $decryptData['unionid'] ?? '',
+            'avatar' => $decryptData['headimgurl'],
+            'nickname' => $decryptData['nickname'],
+        ];
+        return $wechatUser;
+    }
+
+    public function bind()
+    {
+        return $this->login();
+    }
+
+    /**
+     * 获取网页登录地址redirect+返回code
+     *
+     * @return string
+     */
+    public function oauthLogin()
+    {
+        // 返回前端
+        if (!empty($this->request->param('code'))) {
+            if($this->payload['event'] === 'bind') {
+                $query['bind_code'] = $this->request->param('code');
+            }else {
+                $query['login_code'] = $this->request->param('code');
+            }
+            
+            return [
+                'redirect_url' => $this->payload['page'] . '?' .  http_build_query($query)
+            ];
+        } else {
+            $query = [
+                'platform' => 'officialAccount',
+                'payload' => urlencode(json_encode($this->payload))
+            ];
+            $loginUrl = $this->request->domain() . '/api/shop/third.wechat/oauthLogin?' . http_build_query($query);
+            return [
+                'login_url' => $this->wechat->oauth->scopes(['snsapi_userinfo'])->redirect($loginUrl)->getTargetUrl()
+            ];
+        }
+    }
+
+    public function jssdk($APIs)
+    {
+        $this->wechat->jssdk->setUrl($this->payload['url']);
+        return $this->wechat->jssdk->buildConfig($APIs, false, false, false);
+    }
+}

+ 62 - 0
application/common/Service/Third/Wechat/OpenPlatform.php

@@ -0,0 +1,62 @@
+<?php
+
+namespace app\common\Service\Third\Wechat;
+
+use fast\Http;
+use app\common\facade\Wechat;
+use app\common\exception\BusinessException;
+
+class OpenPlatform
+{
+    public $wechat;
+    protected $request;
+    protected $payload;
+
+    public function __construct($payload)
+    {
+        $this->payload = $payload;
+        $this->request = request();
+        $this->wechat = Wechat::openPlatform();
+    }
+
+    public function login()
+    {
+        $payload = $this->payload;
+        if (empty($payload['code'])) {
+                        ('登陆失败');
+        }
+        $config = shop_config('shop.platform.App');
+
+        // 获取accessToken & openid
+        $res = Http::get('https://api.weixin.qq.com/sns/oauth2/access_token', [
+            'appid' => $config['app_id'],
+            'secret' => $config['secret'],
+            'code' => $payload['code'],
+            'grant_type' => 'authorization_code'
+        ]);
+        $decryptedData = json_decode($res, true);
+        if (isset($decryptedData['errmsg'])) {
+            throw new BusinessException($decryptedData['errmsg']);
+        }
+
+        // 获取userInfo
+        $res = Http::get('https://api.weixin.qq.com/sns/userinfo', ['access_token' => $decryptedData['access_token'], 'openid' => $decryptedData['openid']]);
+        $userInfo = is_string($res) ? json_decode($res, true) : $res;
+        if (isset($userInfo['errmsg'])) {
+            throw new BusinessException($userInfo['errmsg']);
+        }
+
+        $wechatUser = [
+            'openid' => $userInfo['openid'],
+            'unionid' => $userInfo['unionid'] ?? '',
+            'avatar' => $userInfo['headimgurl'],
+            'nickname' => $userInfo['nickname'],
+        ];
+        return $wechatUser;
+    }
+
+    public function bind()
+    {
+        return $this->login();
+    }
+}

+ 205 - 0
application/common/Service/Third/Wechat/Wechat.php

@@ -0,0 +1,205 @@
+<?php
+
+namespace app\common\Service\Third\Wechat;
+
+use app\common\library\Auth;
+use app\common\model\ThirdOauth;
+use app\common\model\User as UserModel;
+use app\common\exception\BusinessException;
+
+class Wechat
+{
+
+    // 平台
+    protected $platform;
+    // 转发服务
+    protected $service;
+
+    public function __construct($platform, $payload = [])
+    {
+        $this->platform = $platform;
+        $this->service = $this->setPlatformService($payload);
+    }
+
+    public function getApp()
+    {
+        return $this->service->wechat;
+    }
+
+    /**
+     * 微信登陆
+     *
+     * @return array
+     */
+    public function login()
+    {
+        $wechatUser = $this->service->login();
+
+        $oauthInfo = $this->createOrUpdateOauthInfo($wechatUser);
+
+        $this->registerOrBindUser($oauthInfo, 0, ['mobile' => $wechatUser['mobile'] ?? '']);
+
+        $oauthInfo->save();
+
+        $auth = Auth::instance();
+        $ret = $auth->direct($oauthInfo->user_id);
+
+        if ($ret) {
+            $oauthInfo->login_num += 1;
+            return true;
+        } else {
+            $oauthInfo->user_id = 0;
+            $oauthInfo->save();
+            return false;
+        }
+    }
+
+    /**
+     * 微信绑定
+     *
+     * @return array
+     */
+    public function bind(Object $user)
+    {
+        $wechatUser = $this->service->bind();
+        $oauthInfo = $this->createOrUpdateOauthInfo($wechatUser);
+        if ($this->registerOrBindUser($oauthInfo, $user->id)) {
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * 微信解绑
+     *
+     * @return array
+     */
+    public function unbind()
+    {
+        $user = Auth::instance()->getUser();
+        if (!$user->verification->mobile) {
+            throw new BusinessException('请先绑定手机号后再进行操作');
+        }
+        $oauthInfo = ThirdOauth::where([
+            'user_id' => $user->id,
+            'platform' => $this->platform,
+            'provider' => 'wechat'
+        ])->find();
+
+        if ($oauthInfo) {
+            $oauthInfo->delete();
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * 创建/更新用户认证信息
+     *
+     * @return think\Model
+     */
+    private function createOrUpdateOauthInfo($wechatUser, $extend = [])
+    {
+        $oauthInfo = ThirdOauth::getByOpenid($wechatUser['openid']);
+
+        if (!$oauthInfo) {   // 创建新的third_oauth条目
+            $wechatUser['user_id'] = 0;
+            if (!empty($wechatUser['unionid'])) {     // unionid账号合并策略
+                $unionOauthInfo = ThirdOauth::getByUnionid($wechatUser['unionid']);
+                if ($unionOauthInfo) {
+                    $wechatUser['user_id'] = $unionOauthInfo->user_id;
+                }
+            }
+
+            $wechatUser['provider'] = 'wechat';
+            $wechatUser['platform'] = $this->platform;
+            $wechatUser = array_merge($wechatUser, $extend);
+            $thirdOauth = new ThirdOauth($wechatUser);
+            $thirdOauth->allowField(true)->save();
+            $oauthInfo = ThirdOauth::getByOpenid($wechatUser['openid']);
+        } else {  // 更新授权信息
+            if ($this->platform === 'miniProgram') {
+                unset($wechatUser['avatar']);
+                unset($wechatUser['nickname']);
+            }
+            $oauthInfo->allowField(true)->save($wechatUser);
+        }
+
+        return $oauthInfo;
+    }
+
+    /**
+     * 注册/绑定用户
+     *
+     * @return think\Model
+     */
+    private function registerOrBindUser($oauthInfo, $user_id = 0, $extend = [])
+    {
+
+        // 检查用户存在
+        if ($oauthInfo->user_id) {
+            $user = UserModel::get($oauthInfo->user_id);
+            if ($user && $user_id > 0) {
+                throw new BusinessException('该微信账号已绑定其他用户');
+            }
+            // 用户被删除,则重置第三方信息所绑定的用户id
+            if (!$user) {
+                $oauthInfo->user_id = 0;
+            }
+        }
+
+        // 绑定用户
+        if ($oauthInfo->user_id === 0 && $user_id > 0) {
+            $user = UserModel::get($user_id);
+            if ($user) {
+                $oauthInfo->user_id = $user_id;
+                return $oauthInfo->save();
+            } else {
+                throw new BusinessException('该用户暂不可绑定微信账号');
+            }
+            return false;
+        }
+
+        // 注册新用户
+        if ($oauthInfo->user_id === 0 && $user_id === 0) {
+            $auth = Auth::instance()->register($oauthInfo->nickname ?? '', '', '', $extend['mobile'] ?? '');
+            $user = Auth::instance()->getUser();
+            $oauthInfo->user_id = $user->id;
+            return $oauthInfo->save();
+        }
+    }
+
+    /**
+     * 设置平台服务类
+     *
+     * @return class
+     */
+    private function setPlatformService($payload)
+    {
+        switch ($this->platform) {
+            case 'officialAccount':
+                $service = new OfficialAccount($payload);
+                break;
+            case 'miniProgram':
+                $service = new MiniProgram($payload);
+                break;
+            case 'openPlatform':
+                $service = new OpenPlatform($payload);
+                break;
+        }
+        if (!isset($service)) throw new BusinessException('平台参数有误');
+        return $service;
+    }
+
+    /**
+     * 方法转发到驱动提供者
+     *
+     * @param string $funcname
+     * @param array $arguments
+     * @return void
+     */
+    public function __call($funcname, $arguments)
+    {
+        return $this->service->{$funcname}(...$arguments);
+    }
+}

+ 30 - 0
application/common/model/ThirdOauth.php

@@ -0,0 +1,30 @@
+<?php
+
+namespace app\common\model;
+
+use think\Model;
+
+class ThirdOauth extends Model
+{
+
+
+    // 表名
+    protected $name = 'shop_third_oauth';
+
+    // 自动写入时间戳字段
+    protected $autoWriteTimestamp = 'int';
+
+    // 定义时间戳字段名
+    protected $createTime = 'createtime';
+    protected $updateTime = 'updatetime';
+    protected $deleteTime = false;
+
+    // 追加属性
+    protected $append = [
+    ];
+
+    public function user()
+    {
+        return $this->belongsTo("User", 'user_id', 'id')->setEagerlyType(0);
+    }
+}