|
@@ -47,6 +47,20 @@ class WechatOfficialController extends HttpBaseController
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public function index3()
|
|
|
+ {
|
|
|
+ $this->app->template_message->send([
|
|
|
+ 'touser' => 'oML8X6YkbviDESdya_RCfgdmUtSQ',
|
|
|
+ 'template_id' => 'demGYbEZInVgvwO1ClJNuz2Hc-0FYWZp_duv7HSgdmw',
|
|
|
+ 'url' => 'https://easywechat.com',
|
|
|
+ 'data' => [
|
|
|
+ 'thing2' => '黄先生(1002)',
|
|
|
+ 'thing3' => '湖南友投CMIDERP',
|
|
|
+ 'time6' => '2024-02-21 9:58:23'
|
|
|
+ ]
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
public function index2()
|
|
|
{
|
|
|
$this->app->server->push(function ($message) {
|
|
@@ -89,26 +103,27 @@ class WechatOfficialController extends HttpBaseController
|
|
|
// 保存用户信息
|
|
|
$isSuccess = $this->saveUser($openid, $eventKey);
|
|
|
if ($isSuccess) {
|
|
|
- $msg = "您好!欢迎使用 优速办公!";
|
|
|
+ $msg = "您好!欢迎使用 办公软件!";
|
|
|
} else {
|
|
|
$msg = "对不起!扫描失败,请重试!";
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
case 'unsubscribe': // 取消关注
|
|
|
- $this->loginOut($openid, $eventKey);
|
|
|
+ //$this->loginOut($openid, $eventKey);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
return $msg;
|
|
|
|
|
|
} else {
|
|
|
- return "您好!欢迎使用 优速办公!";
|
|
|
+ return "您好!欢迎使用 办公软件!";
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- $response = $this->app->server->serve();
|
|
|
- $response->send();
|
|
|
+ $this->app->server->serve();
|
|
|
+ // $response = $this->app->server->serve();
|
|
|
+ // $response->send();
|
|
|
exit();
|
|
|
}
|
|
|
|
|
@@ -132,38 +147,29 @@ class WechatOfficialController extends HttpBaseController
|
|
|
$unionid = $userInfo['unionid'] ?? '';
|
|
|
$wxInfo = $userInfo;
|
|
|
|
|
|
- $isExistUser = DB::table('user_wechat_official_account')->select('id')->where('openid', $openid)->first();
|
|
|
- if ($isExistUser) {
|
|
|
- // 更新头像
|
|
|
- $isSuccess = DB::transaction(function () use ($openid, $isExistUser, $unionid, $nickname, $avatar, $wxInfo) {
|
|
|
- DB::table('user_wechat_official_account')->where('id', $isExistUser->id)->update([
|
|
|
- 'openid' => $openid,
|
|
|
- 'unionid' => $unionid,
|
|
|
- 'nick' => $nickname,
|
|
|
- 'wx_avatar' => $avatar,
|
|
|
- 'wx_info' => json_encode($wxInfo),
|
|
|
- ]);
|
|
|
-
|
|
|
- DB::table('user')->where('id', $isExistUser->id)->update([
|
|
|
- 'unionid' => $unionid,
|
|
|
- 'username' => $nickname,
|
|
|
- 'avatar' => $avatar,
|
|
|
- ]);
|
|
|
-
|
|
|
- return true;
|
|
|
- });
|
|
|
+ $isExistUser = DB::table('user_wechat_official_account')->select('id','mid')->where('openid', $openid)->first();
|
|
|
+ $productInfo = DB::table('product')->where('mid', $productMid)->where('is_delete', 0)->first();
|
|
|
|
|
|
+ $productTitle = '办公软件';
|
|
|
+ if ($productInfo) {
|
|
|
+ $productTitle = $productInfo -> title;
|
|
|
+ }
|
|
|
+ if ($isExistUser) {
|
|
|
+ $isSuccess = true;
|
|
|
$userId = $isExistUser->id; // 用户id
|
|
|
+ $nickname = $isExistUser->mid; //用户的mid
|
|
|
} else {
|
|
|
// 插入数据
|
|
|
$isSuccess = DB::transaction(function () use ($openid, $nickname, $avatar, $unionid, $wxInfo) {
|
|
|
+ $mid = Str::random(12);
|
|
|
+ $nickname = $mid;
|
|
|
$userData = [
|
|
|
'username' => $nickname,
|
|
|
'avatar' => $avatar,
|
|
|
'roles' => json_encode([1]),
|
|
|
'unionid' => $unionid,
|
|
|
'status' => 1,
|
|
|
- 'mid' => Str::random(12),
|
|
|
+ 'mid' => $mid,
|
|
|
'created_at' => time(),
|
|
|
'updated_at' => time(),
|
|
|
];
|
|
@@ -176,7 +182,7 @@ class WechatOfficialController extends HttpBaseController
|
|
|
'nick' => $nickname,
|
|
|
'wx_avatar' => $avatar,
|
|
|
'wx_info' => json_encode($wxInfo),
|
|
|
- 'mid' => Str::random(12),
|
|
|
+ 'mid' => $mid,
|
|
|
'created_at' => time(),
|
|
|
'updated_at' => time(),
|
|
|
];
|
|
@@ -189,22 +195,22 @@ class WechatOfficialController extends HttpBaseController
|
|
|
}
|
|
|
|
|
|
if ($isSuccess) {
|
|
|
+ // 发送登录成功消息
|
|
|
+ $this->app->template_message->send([
|
|
|
+ 'touser' => $openid,
|
|
|
+ 'template_id' => 'demGYbEZInVgvwO1ClJNuz2Hc-0FYWZp_duv7HSgdmw',
|
|
|
+ 'url' => 'https://www.qasimblog.com',
|
|
|
+ 'data' => [
|
|
|
+ 'thing2' => $nickname,
|
|
|
+ 'thing3' => $productTitle,
|
|
|
+ 'time6' => date('Y-m-d H:i:s')
|
|
|
+ ]
|
|
|
+ ]);
|
|
|
// 保存生成token需要的信息
|
|
|
$loginToken = new LoginTokenService($this->siteInfo['token_table']);
|
|
|
$token = $loginToken->createOnlyOneToken($userId, $productMid);
|
|
|
Cache::put('TOKEN_' . $sceneStr, $token, 5 * 60); // 有效期5分钟
|
|
|
- Log::info('33333333333333333333 === ' . 'TOKEN_' . $sceneStr . ' ==== ' . $token);
|
|
|
-
|
|
|
- // 如果用户直接点击手机登录链接,而没有扫描,则处理一下当前的扫描状态
|
|
|
- if (!Cache::get("SCAN_" . $sceneStr)) {
|
|
|
- Cache::put("SCAN_" . $sceneStr, true, 2 * 60); // 有效期2分钟
|
|
|
- }
|
|
|
-
|
|
|
- // 网页跳转,带一个随机参数,然后再通过该参数来换取session
|
|
|
- $key = md5(microtime() . $sceneStr);
|
|
|
- Cache::put($key, $token, 2 * 60); // 有效期3分钟
|
|
|
-
|
|
|
- return redirect('/mobile/#/?key=' . $key);
|
|
|
+ return true;
|
|
|
} else {
|
|
|
abort(500, '登录授权失败,请稍后再试!');
|
|
|
}
|