diff --git a/app/admin/controller/Store.php b/app/admin/controller/Store.php index 06e1d165..68b89be4 100644 --- a/app/admin/controller/Store.php +++ b/app/admin/controller/Store.php @@ -230,7 +230,7 @@ class Store extends Controller if ($channel->isEmpty()) { return $this->renderError('当前渠道不存在'); } - $user_name = $channel->code.$storeId; + $user_name = $channel->alias.$storeId; //当前账号是否创建 $merchant = Merchant::where('channel_id', $channel->id)->where('store_id', $storeId)->where('is_delete', 0)->find(); if ($merchant) { diff --git a/app/api/controller/Goods.php b/app/api/controller/Goods.php index b6b462ca..5de95d83 100644 --- a/app/api/controller/Goods.php +++ b/app/api/controller/Goods.php @@ -25,6 +25,8 @@ use think\db\exception\DbException; use think\response\Json; use app\common\enum\goods\GoodsDeliveryTime; use think\facade\Cache; +use EasyWeChat\Factory; + /** * 商品控制器 * Class Goods @@ -410,9 +412,25 @@ class Goods extends Controller } $store_id = GoodsModel::$storeId; $wxConfig = WxappSettingModel::getConfigBasic($store_id); + $config = [ + 'app_id' => $wxConfig['app_id'], + 'secret' => $wxConfig['app_secret'], + 'response_type' => 'array',// 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名 + 'log' => [ + 'level' => 'debug', + 'file' => app()->getRuntimePath().'wechat.log', + ], + ]; + $app = Factory::miniProgram($config); + $data = $app->short_link->getShortLink($page_url, "", false); + $url = ""; + if ($data['errcode'] == 0) { + $url = $data['link']; + } + // 请求api获取短连接 - $link_obj = new ShortLink($wxConfig['app_id'], $wxConfig['app_secret']); - $url = $link_obj->shortUrl($page_url, ""); + // $link_obj = new ShortLink($wxConfig['app_id'], $wxConfig['app_secret']); + // $url = $link_obj->shortUrl($page_url, ""); return $this->renderSuccess(['url' => $url]); } diff --git a/app/api/controller/Passport.php b/app/api/controller/Passport.php index 0e169d0b..914d2f40 100644 --- a/app/api/controller/Passport.php +++ b/app/api/controller/Passport.php @@ -140,9 +140,36 @@ class Passport extends Controller */ public function loginMpWxMobile(): Json { + $params = $this->postForm(); + $params['version'] = 1; // 微信小程序一键登录 $LoginService = new LoginService; - if (!$LoginService->loginMpWxMobile($this->postForm())) { + if (!$LoginService->loginMpWxMobile($params)) { + return $this->renderError($LoginService->getError()); + } + // 获取登录成功后的用户信息 + $userInfo = $LoginService->getUserInfo(); + return $this->renderSuccess([ + 'userId' => (int)$userInfo['user_id'], + 'token' => $LoginService->getToken((int)$userInfo['user_id']) + ], '登录成功'); + } + /** + * 快捷登录: 微信小程序授权手机号登录-新版,基于easywechat5.0 + * @return Json + * @throws BaseException + * @throws \think\Exception + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function auth(): Json + { + $params = $this->postForm(); + $params['version'] = 2; + // 微信小程序一键登录 + $LoginService = new LoginService; + if (!$LoginService->auth($params)) { return $this->renderError($LoginService->getError()); } // 获取登录成功后的用户信息 @@ -152,7 +179,6 @@ class Passport extends Controller 'token' => $LoginService->getToken((int)$userInfo['user_id']) ], '登录成功'); } - /** * 是否需要填写昵称头像 (微信小程序端) * @param string $code diff --git a/app/api/service/passport/Login.php b/app/api/service/passport/Login.php index 1b16ed51..8d3dc83a 100644 --- a/app/api/service/passport/Login.php +++ b/app/api/service/passport/Login.php @@ -25,6 +25,8 @@ use app\common\service\BaseService; use cores\exception\BaseException; use think\facade\Cache; use yiovo\captcha\facade\CaptchaApi; +use EasyWeChat\Factory; +use app\api\model\wxapp\Setting as WxappSettingModel; /** * 服务类:用户登录 @@ -201,6 +203,7 @@ class Login extends BaseService if (empty($form['partyData']['oauth'])) { $form['partyData']['oauth'] = 'MP-WEIXIN'; $form['partyData']['code'] = $form['code']; + $form['partyData']['version'] = $form['version']; } $loginData = [ 'mobile' => $plainData['purePhoneNumber'], @@ -215,7 +218,49 @@ class Login extends BaseService // 记录登录态 return $this->setSession(); } - + /** + * 快捷登录:微信小程序用户-5.0 + * @param array $form + * @return bool + * @throws BaseException + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @throws \think\Exception + */ + public function auth(array $form): bool + { + $wxSetting = WxappSettingModel::getConfigBasic(); + $config = [ + 'app_id' => $wxSetting['app_id'], + 'secret' => $wxSetting['app_secret'], + 'response_type' => 'array',// 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名 + 'log' => [ + 'level' => 'debug', + 'file' => app()->getRuntimePath().'wechat.log', + ], + ]; + $app = Factory::miniProgram($config); + $phoneData = $app->phone_number->getUserPhoneNumber($form['pcode']); + // 整理登录注册数据 + if (empty($form['partyData']['oauth'])) { + $form['partyData']['oauth'] = 'MP-WEIXIN'; + $form['partyData']['code'] = $form['ucode']; + $form['partyData']['version'] = $form['version']; + } + $loginData = [ + 'mobile' => $phoneData['phone_info']['purePhoneNumber'] ?? "", + 'isParty' => $form['isParty'], + 'partyData' => $form['partyData'], + 'refereeId' => $form['refereeId'] ?? null, + ]; + // 自动登录注册 + $this->register($loginData); + // 保存第三方用户信息 + $this->createUserOauth($this->getUserId(), $loginData['isParty'], $loginData['partyData']); + // 记录登录态 + return $this->setSession(); + } /** * 快捷登录:支付宝小程序用户 * @param array $form diff --git a/app/api/service/passport/Party.php b/app/api/service/passport/Party.php index 3bc4ec6d..596b5255 100644 --- a/app/api/service/passport/Party.php +++ b/app/api/service/passport/Party.php @@ -19,6 +19,8 @@ use app\common\service\BaseService; use app\common\enum\Client as ClientEnum; use cores\exception\BaseException; use think\Exception; +use app\api\model\wxapp\Setting as WxappSettingModel; +use EasyWeChat\Factory; /** * 第三方用户注册登录服务 @@ -159,7 +161,23 @@ class Party extends BaseService private function getOauthInfo(array $partyData): ?array { if ($partyData['oauth'] === ClientEnum::MP_WEIXIN) { - $wxSession = static::getMpWxSession($partyData['code']); + if ($partyData['version'] == 1) { + $wxSession = static::getMpWxSession($partyData['code']); + } else { + $wxSetting = WxappSettingModel::getConfigBasic(); + $config = [ + 'app_id' => $wxSetting['app_id'], + 'secret' => $wxSetting['app_secret'], + 'response_type' => 'array',// 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名 + 'log' => [ + 'level' => 'debug', + 'file' => app()->getRuntimePath().'wechat.log', + ], + ]; + $app = Factory::miniProgram($config); + $wxSession = $app->auth->session($partyData['code']); + } + return ['oauth_id' => $wxSession['openid'], 'unionid' => $wxSession['unionid'] ?? null]; } if ($partyData['oauth'] === ClientEnum::WXOFFICIAL) { diff --git a/app/common/model/Goods.php b/app/common/model/Goods.php index 31232b54..1469fe78 100644 --- a/app/common/model/Goods.php +++ b/app/common/model/Goods.php @@ -496,6 +496,11 @@ class Goods extends BaseModel $filter[] = ['is_new', '=', intval($param['is_new'])]; } + //gj + if (isset($param['merchantId']) && $param['merchantId']) { + $filter[] = ['goods.merchant_id', '=', $param['merchantId']]; + } + if (!empty($param['paihang'])) { $filter[] = ['paihang', '>', 0]; $query->order('paihang asc'); @@ -574,9 +579,9 @@ class Goods extends BaseModel if (isset($param['is_has_detail']) && $param['is_has_detail'] !== '') { $filter[] = ['goods.is_has_detail', '=', $params['is_has_detail']]; } - if (isset($param['merchantId']) && $param['merchantId'] !== '') { - $filter[] = ['goods.merchant_id', '=', $params['merchantId']]; - } + // if (isset($param['merchant_id']) && $param['merchant_id'] !== '') { + // $filter[] = ['goods.merchant_id', '=', $params['merchant_id']]; + // } if (isset($param['is_jd_remove']) && $param['is_jd_remove'] !== '') { $filter[] = ['goods.is_jd_remove', '=', $params['is_jd_remove']]; } diff --git a/app/common/service/qrcode/BaseQRcode.php b/app/common/service/qrcode/BaseQRcode.php index 11841bed..ddc0e0ac 100644 --- a/app/common/service/qrcode/BaseQRcode.php +++ b/app/common/service/qrcode/BaseQRcode.php @@ -19,6 +19,7 @@ use app\common\model\h5\Setting as H5SettingModel; use app\common\model\wxapp\Setting as WxappSettingModel; use app\common\service\BaseService; use cores\exception\BaseException; +use EasyWeChat\Factory; /** * 二维码服务基类 @@ -78,14 +79,35 @@ class BaseQRcode extends BaseService if (file_exists($savePath)) { return $savePath; } + $pathInfo = pathinfo($savePath); // 小程序配置信息 $wxConfig = WxappSettingModel::getConfigBasic($storeId); + $config = [ + 'app_id' => $wxConfig['app_id'], + 'secret' => $wxConfig['app_secret'], + 'response_type' => 'array',// 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名 + 'log' => [ + 'level' => 'debug', + 'file' => app()->getRuntimePath().'wechat.log', + ], + ]; + $app = Factory::miniProgram($config); + $response = $app->app_code->getUnlimit($scene, [ + 'page' => $page, + 'width' => 430, + ]); + if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) { + $filename = $response->saveAs($pathInfo['dirname'], $pathInfo['basename']); + } + return $savePath; + // var_dump($content); + // exit(); // 请求api获取小程序码 - $Qrcode = new WechatQrcode($wxConfig['app_id'], $wxConfig['app_secret']); - $content = $Qrcode->getQrcode($scene, $page); + // $Qrcode = new WechatQrcode($wxConfig['app_id'], $wxConfig['app_secret']); + // $content = $Qrcode->getQrcode($scene, $page); // 保存到文件 - file_put_contents($savePath, $content); - return $savePath; + // file_put_contents($savePath, $content); + // return $savePath; } /**