diff --git a/app/controller/Wechat.php b/app/controller/Wechat.php index 56f9b8b..e583cd3 100644 --- a/app/controller/Wechat.php +++ b/app/controller/Wechat.php @@ -58,7 +58,7 @@ class Wechat $user = AppUser::where('openid', $user->getId())->find(); - if (!$user) { + if (! $user) { $user = AppUser::create([ 'nickname' => $user->getNickname(), 'avatar' => $user->getAvatar(), @@ -80,6 +80,13 @@ class Wechat */ public function payment() { + $userId = $GLOBALS['data']['userid']; + if (empty($userId)) { + return show("未登录!", NEED_LOGIN); + } + + $user = AppUser::find($userId); + $notifyUrl = Route::buildUrl('wechat/paid') ->suffix(false) ->domain(true); @@ -91,7 +98,7 @@ class Wechat 'total_fee' => 100, 'notify_url' => $notifyUrl, 'trade_type' => 'JSAPI', - 'openid' => '$openid', + 'openid' => $user->openid, ]); dump($unify); // $prepayId = $unify->prepay_id;