Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -2,9 +2,11 @@
|
||||
|
||||
namespace app\controller;
|
||||
|
||||
use app\model\AppUser;
|
||||
use EasyWeChat\Factory;
|
||||
use EasyWeChat\OfficialAccount\Application;
|
||||
use think\facade\Config;
|
||||
use think\facade\Db;
|
||||
use think\facade\Request;
|
||||
use think\facade\Route;
|
||||
use think\facade\View;
|
||||
@@ -39,7 +41,7 @@ class Wechat
|
||||
->domain(true);
|
||||
$this->initWechat();
|
||||
|
||||
return show(SUCCESS_MESSAGE,SUCCESS_CODE,$this->app->oauth->scopes(['snsapi_userinfo'])->redirect($redirect));
|
||||
return show(SUCCESS_MESSAGE, SUCCESS_CODE, $this->app->oauth->scopes(['snsapi_userinfo'])->redirect($redirect));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,16 +56,20 @@ class Wechat
|
||||
$user = $this->app->oauth->user();
|
||||
$callback = Request::get('callback');
|
||||
|
||||
$token = '怎样获得一个 token';
|
||||
return redirect($callback.'?token='.$token);
|
||||
$user = AppUser::where('openid', $user->getId())->find();
|
||||
|
||||
// $user 可以用的方法:
|
||||
// $user->getId(); // 对应微信的 OPENID
|
||||
// $user->getNickname(); // 对应微信的 nickname
|
||||
// $user->getName(); // 对应微信的 nickname
|
||||
// $user->getAvatar(); // 头像网址
|
||||
// $user->getOriginal(); // 原始API返回的结果
|
||||
// $user->getToken(); // access_token, 比如用于地址共享时使用
|
||||
if (! $user) {
|
||||
$user = AppUser::create([
|
||||
'nickname' => $user->getNickname(),
|
||||
'avatar' => $user->getAvatar(),
|
||||
'identity' => 1,
|
||||
'openid' => $user->getId(),
|
||||
]);
|
||||
}
|
||||
$tokenData = ['userid' => $user->id, 'loginTime' => time(), 'rankStr' => strRand(5)];
|
||||
$token = authcode(json_encode($tokenData), 'ENCODE');
|
||||
|
||||
return redirect($callback.'?token='.$token);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,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);
|
||||
@@ -85,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;
|
||||
|
||||
Reference in New Issue
Block a user